Skip to main content

Chat API Reference

This page documents the request and response schemas for the Chat API. For endpoint URLs and quickstart examples, see Getting Started.

Request Schema

Both the streaming (POST /chat/stream) and non-streaming (POST /chat/response) endpoints accept the same request body:

{
"agent_identifier": "string (required)",
"conversation": [ChatMessage],
"conversation_context": ConversationContext,
"bot_params": {}
}
FieldTypeRequiredDescription
agent_identifierstringYesThe identifier of the agent to invoke
conversationChatMessage[]YesThe conversation history
conversation_contextConversationContextNoTop-level context for the request
bot_paramsobjectNoRuntime parameters for the agent (see below)

ChatMessage

A single message in the conversation. The sender field is "user" for user messages and "bot" for agent messages:

{
"sender": "user" | "bot",
"content": "string",
"message_id": "string",
"content_parts": [ContentPart],
"evidences": [ChatMessageEvidence],
"function_call_request": FunctionCallRequest,
"function_call_response": FunctionCallResponse,
"function_specs": FunctionSpec,
"image_uri": "string"
}
FieldTypeRequiredDescription
sender"user" or "bot"YesMessage author — "bot" denotes the agent's response
contentstringYesThe text content of the message
message_idstringNoUnique message identifier (returned by server; used for feedback)
content_partsContentPart[]NoStructured message parts (context, text, tool calls, tables)
evidencesChatMessageEvidence[]NoCitation evidence linking answer spans to sources
function_call_requestobjectNoDeprecated. Legacy function call suggestion — use tool content parts instead
function_call_responseobjectNoDeprecated. Legacy function call result — use tool content parts instead
function_specsobjectNoDeprecated. Function specifications for legacy function call pattern
image_uristringNoDeprecated. Use content parts for media

ContentPart

Each content part has a type discriminator and one corresponding data field:

TypeData FieldDescription
"text"textA text segment of the agent's response
"context"contextA ConversationContext block (documents the agent found or context the client attached)
"tool"toolA tool call event with lifecycle status
"table"tableStructured tabular data
{
"type": "text" | "context" | "tool" | "table",
"text": "string",
"context": ConversationContext,
"tool": ContentPartTool,
"table": ContentPartTable
}

ContentPartTool

Represents a single tool call and its lifecycle. Agents stream these to communicate what they are doing:

FieldTypeRequiredDescription
tool_call_idstringYesUnique identifier for this tool invocation
namestringYesName of the tool being called
paramsobjectNoVisible parameters sent to the tool
responseobjectNoTool execution result (present when completed)
display_textstringNoHuman-readable description of what the tool is doing/did
status"running" / "completed" / "error"NoCurrent lifecycle state

See Content Parts for how to render these in a UI.

ContentPartTable

Structured tabular data returned by an agent:

FieldTypeDescription
format"row" or "columnar"How the data is organized
headersstring[]Column headers
rowsobject[]Row data (when format is "row") — each object maps header → value
columnsobjectColumn data (when format is "columnar") — maps header → value[]

Exactly one of rows or columns must be present.

Example (row format):

{
"type": "table",
"table": {
"format": "row",
"headers": ["Document", "Relevance"],
"rows": [
{"Document": "BERT paper", "Relevance": "High"},
{"Document": "GPT-2 paper", "Relevance": "Medium"}
]
}
}

ConversationContext

Context scoping the conversation to specific documents, tags, filters, or custom content. Can appear at the top level of the request or inside a content_parts entry with type: "context".

{
"document_context": {
"document_ids": ["string"],
"retrieval_unit": "document" | "chunk"
},
"custom_context": {
"items": [
{"document_id": "string", "content": "string or object"}
]
},
"tag_context": {
"tag_ids": ["string"]
},
"filter_context": {
"filters": {}
},
"user_document_context": {
"enabled": true
}
}

document_context and custom_context are mutually exclusive. All other fields can be combined freely.

See Passing Context for usage patterns and examples.

ChatMessageEvidence

A citation linking a span of the answer to a source document:

FieldTypeRequiredDescription
document_hit_urlstringYesURL path to fetch the source document/chunk
text_extractstringNoRelevant passage from the source (with <b> highlights)
anchor_textstringNoThe citation marker in the answer text (e.g., <sup>1</sup>)

See Handling Citations for rendering patterns.

Response Schema

Non-Streaming Response (ChatResponseItem)

{
"agent_identifier": "string",
"conversation": [ChatMessage],
"conversation_context": ConversationContext,
"function_specs": [FunctionSpec]
}

The response echoes back the full conversation with the agent's response appended as the last message.

Streaming Response (SSE)

The streaming endpoint returns Server-Sent Events. Each event has:

event: new_message
id: {message_id}:{event_index}
data: {ChatMessage as JSON}
retry: 15000

Each event contains the complete message so far — as tokens are generated, the content field grows incrementally. The final event contains the fully formed response including evidences and content_parts.

See Streaming for reconnection, cancellation, and protocol details.

bot_params

The bot_params field allows API clients to pass runtime parameters to the agent at request time. These parameters flow into the agent factory's dependency resolution — specifically, they fill agent constructor parameters that are not already set by the agent's static configuration.

How it works:

  1. The client sends bot_params: {"search_scope": "internal"} in the request.
  2. The handler sanitizes the dict (protected keys like tenant, request_headers, index_id are always stripped).
  3. The agent factory resolves each constructor parameter by checking the agent's static agent_configuration first, then falling back to handler_params (which includes the sanitized bot_params).
  4. If the agent class declares a parameter matching a key in bot_params, and the static configuration does not already set it, the runtime value is used.

Security model:

  • Static agent_configuration always takes precedence — bot_params cannot override values the agent developer has locked in configuration.
  • For dict-typed parameters, values are deep-merged with configuration taking precedence.
  • Protected system keys (tenant, request_headers, index_id) are always stripped regardless of what the client sends.

When to use:

Use bot_params when the agent developer has designed specific constructor parameters to be overridable at runtime. Common patterns include passing a user-selected scope, language preference, or feature flag. The exact parameters available depend on the specific agent's implementation.

Error Handling

HTTP Errors

Errors from the chat service return JSON with a detail field:

{"detail": "Error description"}
StatusMeaningCommon Causes
400Bad RequestUnknown agent_identifier, agent not streamable for the streaming endpoint, malformed request body, mutually exclusive fields both set
401UnauthorizedMissing or invalid API key / Bearer token (returned by the API gateway)
403ForbiddenValid credentials but insufficient permissions for this tenant
404Not Foundmessage_id not found or expired when reconnecting or cancelling a stream
422Validation ErrorRequest body fails schema validation
500Internal Server ErrorUnexpected server-side failure
note

401 responses come from the API gateway and use {"message": "Unauthorized"} rather than {"detail": "..."}.

Validation Errors (422)

Validation errors include per-field details in the standard FastAPI/Pydantic format:

{
"detail": [
{
"loc": ["body", "conversation", 0, "sender"],
"msg": "value is not a valid enumeration member",
"type": "value_error.enum"
}
]
}

Streaming Errors

If the agent encounters an error during an active SSE stream, an error event is sent with a plain-text data field (not JSON):

event: error
data: Internal streaming error

When you receive an error event, close the connection. If the error occurred mid-stream, you can attempt reconnection using the last received message_id and event_index.

Deprecated Fields

FieldReplacement
function_call_request / function_call_responsecontent_parts with type: "tool" — see Content Parts
function_specsTool specifications are now configured server-side
image_uriMedia should be handled via content parts