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
orbot_slug
should be present. - Either
prompt
ormessages
should be present.
ChatMessage
role
: (string, required) - The role of the author of this message. One of:system
,user
, orassistant
.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
isfalse
. - Schema: Response body (application/json)
- Description: JSON response in case parameter
-
Status Code: 200
- Description: Streaming response in case parameter
stream
istrue
. - Schema: Response body (text/event-stream)
- Description: Streaming response in case parameter
-
Status Code: 422
- Description: Validation Error.
- Schema: HTTPValidationError (application/json)
Response body
Bot response.
content
: (string, required) - bot answer text.
Example:
- Non-stream:
{ "content": "To pay taxes in Texas, gather your financial documents..." }
- Stream:
{"content":""} {"content":"To"} {"content":" pay"} {"content":" taxes"} {"content":","} {"content":" gather"} {"content":" necessary"} {"content":" documents"} // ... [DONE]
HTTPValidationError
detail
: (array[ValidationError], required)
ValidationError
loc
: (array, required) - Location of the error cause.msg
: (string, required) - Error Messagetype
: (string, required) - Error Type
Examples:
- Missing
stream
parameter{ "detail": [ { "loc": [ "body", "stream" ], "msg": "field required", "type": "value_error.missing" } ] }
stream
parameter has a wrong type{ "detail": [ { "loc": [ "body", "stream" ], "msg": "none is not an allowed value", "type": "type_error.none.not_allowed" } ] }
- Missing both
prompt
andmessages
{ "detail": [ { "loc": [ "body", "__root__" ], "msg": "Either \"prompt\" or \"messages\" is required", "type": "value_error" } ] }