Skip to content

Chat API

Send messages to AI agents and manage conversations programmatically.


Send Chat Message

Send a message to an AI agent and receive a response.

Endpoint: POST /chat/{slug}

Parameters

Parameter Type Location Required Description
slug string path Yes The unique identifier (slug) of your AI agent

Request Body

{
  "message": "Your message text here",
  "stream": false,
  "conversationId": "optional-conversation-id"
}
Field Type Required Description
message string Yes The message to send to the AI agent
stream boolean No Enable streaming responses (default: false)
async boolean or number No true enqueues the request for background processing and returns a Request ID immediately via the X-Request-Id response header (default: false). A number of seconds waits that long for the answer first. See Asynchronous Mode and Wait time
conversationId string No Continue an existing conversation (null for new conversation)
language_model string or number No The language model to answer with: the model's id, or the name configured on the agent. See Choosing the language model

Response

Synchronous success (200): the current schema documents a text response, with x-conversation-id and x-conversation-name headers. Do not parse this as a JSON data.response envelope.

Hello, how can I help you?

Use the returned conversation ID when continuing the conversation. Check the actual response content type and the selected streaming mode when implementing a client.

Examples

Basic Chat

curl -X POST "https://PLATFORM-URL-PLACEHOLDER/v1/api/chat/support-agent" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "What are your business hours?",
    "stream": false
  }'

Continue Conversation

curl -X POST "https://PLATFORM-URL-PLACEHOLDER/v1/api/chat/support-agent" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Can you elaborate on that?",
    "stream": false,
    "conversationId": "conv_abc123"
  }'

Streaming Response

curl -X POST "https://PLATFORM-URL-PLACEHOLDER/v1/api/chat/support-agent" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Tell me a long story",
    "stream": true
  }'

Error Responses

400 - Bad Request:

{
  "data": null,
  "error": {
    "name": "ValidationError",
    "message": "Message field is required",
    "details": {}
  }
}

401 - Unauthorized. Sent with no API key, an expired key, or, on an agent that requires a chat session, a message with neither an API key nor a platform-issued chat session (the session is what the embedded chat window, the sidebar and the signed-out agent page use):

{
  "data": null,
  "error": {
    "name": "UnauthorizedError",
    "message": "Invalid or missing API token",
    "details": {}
  }
}

404 - Not Found:

{
  "data": null,
  "error": {
    "name": "NotFoundError",
    "message": "Agent with slug 'support-agent' not found",
    "details": {}
  }
}

Finding Your Agent Slug

The agent slug is the unique identifier for your agent. You can find it in the platform:

  1. Navigate to My Agents
  2. Click on your agent
  3. The slug is shown in the agent settings or URL

Copy the actual slug from the agent URL; do not derive it from the display name.


Conversation Management

New Conversation

To start a new conversation, omit the conversationId field or set it to null:

{
  "message": "Hello",
  "conversationId": null
}

Continue Conversation

To continue an existing conversation, include the conversation ID from the previous response’s x-conversation-id header:

{
  "message": "Follow-up question",
  "conversationId": "conv_abc123"
}

Choosing the Language Model

A chat request can name the language model it wants with language_model, by the model entry's id or by the exact name configured on the agent (case and spaces included). The choice applies to that request and is remembered on the conversation, the same way a model picked in the chat window is, so later messages keep using it without sending the field again. Sending the agent's own default model clears the remembered choice. Search agents honour the field on every request, since they have no conversation.

curl -X POST "https://PLATFORM-URL-PLACEHOLDER/v1/api/chat/support-agent" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Summarise the last ticket",
    "language_model": "Claude Sonnet 5.5 High"
  }'

If the value is not one of the agent's available models, or a name matches more than one model, the request is rejected with 400 instead of falling back to the default:

{
  "data": null,
  "error": {
    "name": "ValidationError",
    "message": "language_model does not match exactly one of this agent's available chat models (by id or name)",
    "details": {}
  }
}

The field is ignored on agents that do not let users change the model, and on website widget agents; tag-based model selection keeps its priority.


Asynchronous Mode (Request ID)

For long-running chat completions where the client cannot keep an HTTP connection open, the Chat API supports an asynchronous mode. Submit with async: true, receive a Request ID immediately, then poll a separate endpoint until the result is ready.

Submitting an Async Request

Set async: true in the request body:

curl -X POST "https://PLATFORM-URL-PLACEHOLDER/v1/api/chat/your-agent" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Generate a long report",
    "async": true
  }'

The server enqueues the chat for background processing and returns immediately. The Request ID is exposed via the X-Request-Id response header (not in the response body).

Polling for the Result

Once the chat has been enqueued, poll the status endpoint with the Request ID:

Endpoint: GET /v1/api/chat/request/{x-request-id}

curl "https://PLATFORM-URL-PLACEHOLDER/v1/api/chat/request/REQUEST_ID_FROM_HEADER" \
  -H "Authorization: Bearer YOUR_API_KEY"

The response uses top-level fields. The schema examples show processing, complete and a failure case. A completed response includes result.text:

{
  "requestId": "550e8400-e29b-41d4-a716-446655440000",
  "status": "complete",
  "conversationId": "example-conversation-id",
  "result": {"text": "Hello!"},
  "completedAt": 1740000060000
}

Poll with a finite interval and timeout. Stop on a terminal failure; a 404 can mean missing, expired or inaccessible to the current identity. Keep the same intended identity when submitting and polling.

Async Mode — Behaviour

Aspect Behaviour
Trigger async: true in POST /v1/api/chat/{slug} body
Request ID location X-Request-Id response header on the submission call
Poll endpoint GET /v1/api/chat/request/{x-request-id}
TTL Async requests persist for 30 minutes after creation; polling after expiry returns a clear not-found response
Access scope Only the user (or service account) who created the async request can read it back
Impersonation header Both endpoints honour an optional x-user-identifier header (workspace member email or Service Account UUID) under Workspace API Tokens; ignored for User API Tokens and JWT auth
Sync compatibility async: false or omitted preserves existing sync behaviour — same response shape, headers, and status codes as before

x-user-identifier

See API Keys — Acting on Behalf of an Identity for header semantics.


Wait Time for Long Answers

Server-to-server integrations that call the chat API without streaming can set async to a number of seconds instead of true. The API waits up to that long and returns the answer if it is ready. Otherwise it returns HTTP 202 with a ticket id, which the caller polls at GET /v1/api/chat/request/{id} or receives through its callback URL, instead of timing out.

curl -X POST "https://PLATFORM-URL-PLACEHOLDER/v1/api/chat/your-agent" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 7c9e6679-7425-40de-944b-e07fc1f90ae7" \
  -d '{
    "message": "Write the full quarterly summary",
    "stream": false,
    "async": 120
  }'
Aspect Behaviour
async as a number Seconds to wait. Inside that time the call returns the answer as a normal response
Not ready in time 202 with the ticket id; poll or use the callback URL
Idempotency-Key header Optional. A retry with the same key joins the original request instead of starting a second model run
Caller disconnects A caller that disconnects with neither an Idempotency-Key nor a callback URL has its run cancelled, so no answer is generated for nobody
Existing callers async as true or false behaves as before

Clearer provider errors

When the AI provider rejects a request, for example a retired model or an account without credit, the chat explains why instead of returning a generic error.


Streaming Responses

When stream: true is set, the response will be sent as Server-Sent Events (SSE):

curl -X POST "https://PLATFORM-URL-PLACEHOLDER/v1/api/chat/agent-slug" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello", "stream": true}' \
  --no-buffer

Process streamed content incrementally. Check the current endpoint contract and response headers before choosing a parser; do not assume the non-streaming JSON envelope or an undocumented chunk/sentinel format.


Best Practices

  1. Store Conversation IDs: Save conversationId values to maintain context across messages
  2. Handle Timeouts: For long answers without streaming, set async to a number of seconds and send an Idempotency-Key so retries do not start a second run
  3. Error Handling: Implement retry logic for transient errors (429, 500)
  4. Rate Limiting: Respect rate limits and implement exponential backoff
  5. Streaming: Use streaming for better UX with long responses