API
POST /chat

POST /v1/chat

Initiate chat response.

Request Body

  • bot_uid: (string, optional) - Bot unique identifier.
  • bot_slug: (string, optional) - Bot unique human-readable identifier.
  • prompt: (string, optional) - Prompt for the chat.
  • messages: (array[ChatMessage], optional) - Array of chat messages.
  • stream: (boolean, required) - Whether to stream the response.
  • user_id: (string, optional) - Unique identifier representing end-user. Which can help to monitor and detect abuse.

Notes:

  • Either bot_uid or bot_slug should be present.
  • Either prompt or messages should be present.

ChatMessage

  • role: (string, required) - The role of the author of this message. One of: system, user, or assistant.
  • content: (string, required) - Message text.

Example:

{
    "bot_uid": "edf826b8-1b75-4f57-bd26-641c897f9c1e",
    "stream": true,
    "prompt": "Explain how to pay taxes."
}
{
    "bot_slug": "taxson",
    "stream": true,
    "messages": [
        {"role": "system", "content": "User live in Texas, US."},
        {"role": "user", "content": "Explain how to pay taxes."}
    ]
}

Responses

  • Status Code: 200

    • Description: JSON response in case parameter stream is false.
    • Schema: Response body (application/json)
  • Status Code: 200

    • Description: Streaming response in case parameter stream is true.
    • Schema: Response body (text/event-stream)
  • Status Code: 422

Response body

Bot response.

  • content: (string, required) - bot answer text.

Example:

  1. Non-stream:
    {
        "content": "To pay taxes in Texas, gather your financial documents..."
    }
  2. Stream:
    {"content":""}
    {"content":"To"}
    {"content":" pay"}
    {"content":" taxes"}
    {"content":","}
    {"content":" gather"}
    {"content":" necessary"}
    {"content":" documents"}
    // ...
    [DONE]

HTTPValidationError

ValidationError

  • loc: (array, required) - Location of the error cause.
  • msg: (string, required) - Error Message
  • type: (string, required) - Error Type

Examples:

  1. Missing stream parameter
    {
        "detail": [
            {
                "loc": [
                    "body",
                    "stream"
                ],
                "msg": "field required",
                "type": "value_error.missing"
            }
        ]
    }
  2. stream parameter has a wrong type
    {
        "detail": [
            {
                "loc": [
                    "body",
                    "stream"
                ],
                "msg": "none is not an allowed value",
                "type": "type_error.none.not_allowed"
            }
        ]
    }
  3. Missing both prompt and messages
    {
       "detail": [
           {
               "loc": [
                   "body",
                   "__root__"
               ],
               "msg": "Either \"prompt\" or \"messages\" is required",
               "type": "value_error"
           }
       ]
    }