Board Run API Endpoint Protocol

Describes how to use the Board Run API Endpoint. This API endpoint is different from the invoke BSE endpoint in that it follows the "Run" mode semantics.

Endpoint

POST {API_URL}

When using Board Server, it will be the URL of the board, with the json extension replaced by api/run. For example a board at this location:

http://mycoolboardserver.example.com/boards/@pluto/chat-agent.bgl.json

Will have the API endpoint at:

http://mycoolboardserver.example.com/boards/@pluto/chat-agent.bgl.api/run

Authentication

Authentication is performed using an API key.

Request

Headers

Body

The request body should be a JSON object with the following structure:

{
  "$key": "YOUR_API_KEY",
  "$next": "OPTIONAL_RESUMPTION_STATE",
  ...inputs
}

Example input for initiating request:

{
  "$key": "YOUR_API_KEY",
  "context": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Hello, my name is Pluto! When talking with me, please start by addressing me by name"
        }
      ]
    }
  ]
}

Example input for continuing request:

{
  "$key": "YOUR_API_KEY",
  "$next": "RESUME_FROM_THIS_STATE",
  "text": {
    "role": "user",
    "parts": [{ "text": "What is Breadboard?" }]
  }
}

You can also initiate request with no inputs. In this case, the response will contain the input type response and supply the schema:

{
  "$key": "YOUR_API_KEY"
}

Response

The response is a Server-Sent Events (SSE) stream. Each event in the stream is a serialized JSON object prefixed by data: and separated by \n\n.

Event Format

Each event is an array with two elements: [type, data]

The type can be one of the following:

  1. "input"
  2. "output"
  3. "error"

Event Types

  1. Input Event
["input", {
  "schema": { ... },
  "next": "RESUMPTION_STATE"
}]
  1. Output Event
["output", {
  "output": [ ... ]
}]
  1. Error Event
["error", "ERROR_MESSAGE"]

Error Handling

Resuming Interactions

To continue an interaction:

  1. Extract the next value from the most recent input event.
  2. Include this value as $next in your next request body.

Examples

Initiating a conversation

Request:

POST {API_URL} HTTP/1.1
Content-Type: application/json

{
  "$key": "YOUR_API_KEY",
  "context": [
    {
      "role": "user",
      "parts": [{ "text": "Hello, my name is Dimitri! When talking with me, please start by addressing me by name" }]
    }
  ]
}

Continuing a conversation

Request:

POST {API_URL} HTTP/1.1
Content-Type: application/json

{
  "$key": "YOUR_API_KEY",
  "$next": "PREVIOUS_NEXT_VALUE",
  "text": {
    "role": "user",
    "parts": [{ "text": "What is Breadboard?" }]
  }
}

Notes