Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.trellis.sh/llms.txt

Use this file to discover all available pages before exploring further.

Send a natural language message and receive a streamed response via Server-Sent Events (SSE).
For a complete guide on handling responses, see the Chat Overview.Prefer real-time bidirectional communication? Use the WebSocket endpoint instead.
chat_id is now required. Call Create Chat first to obtain one — sending without chat_id returns 400 MISSING_CHAT_ID, and an unknown ID returns 404 CHAT_NOT_FOUND.
Authorization
string
required
Bearer token obtained from the authenticate endpoint.
Accept
string
Set to text/event-stream to receive SSE responses.
message
string
required
The natural language message to send.
chat_id
string
required
ID of an existing chat. Obtain one from Create Chat. Omitting this field returns 400 MISSING_CHAT_ID; passing an ID that doesn’t belong to the caller returns 404 CHAT_NOT_FOUND.
integration_id
string
ID of the database integration to query. Required for database queries.
title
string
Custom title for new chats. If omitted, a title is generated automatically.
model
string
AI model to use for this message. If omitted, the default model is used. See List Models for available values.
upload_ids
string[]
List of upload IDs to attach to this message. Upload files first via Upload Files, then reference their IDs here. Requires chat_id to be set.
saved_query_id
string
ID of a saved query to execute deterministically. When provided, the saved query’s SQL is run directly instead of passing the message through the AI agent. Use List Saved Queries to retrieve query IDs.
parameters
object
Key-value pairs supplying runtime values for {{param_name}} placeholders in the saved query’s SQL. Required when the saved query has a non-empty parameters array. Only applicable when saved_query_id is set.
{ "year": "2025", "limit": "10" }
When saved_query_id is provided, the AI agent is bypassed and the saved query’s SQL is executed directly against the connected database. The message field is still required but is used only for display in the chat history. Any {{param_name}} placeholders in the SQL must have corresponding entries in parameters — missing values will return a 400 error.

Response

The response is a stream of Server-Sent Events. See Chat Overview for details on handling the stream.

Event types

EventDataDescription
chat_metadata{"id": "chat_...", "user_message_id": "msg_..."}Chat ID and persisted user message ID. Emitted at the start of every response.
processing{"status": "starting" | "thinking" | "analyzing" | "processing"}AI processing status. starting is emitted within ~100ms of request receipt.
visualizationFull chart or table payloadA chart or table was generated. See Visualizations.
text_delta{"content": "..."}An incremental chunk of the final assistant text, streamed as the model generates it. Multiple frames arrive per turn. Concatenate content values in order to build the response.
message{"content": "...", "id": "msg_..."}The final response. Always carries the authoritative full content plus the persisted message id. Safe to overwrite any streaming buffer with content on receipt.
error{"error": "...", "code": "...", "retryable": boolean, "debug_id": "...", "error_type": "..."}An error occurred. See WebSocket → Error codes for the stable code enum and retry semantics.
text_delta events let you render the response progressively — typical time-to-first-token is about 1 second vs. several seconds for the full answer. See Chat Overview → Streaming text deltas for the buffer-and-reconcile pattern.
curl -X POST https://api.trellis.sh/v1/chats \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -d '{
    "message": "Show me the top 5 projects by budget as a bar chart",
    "chat_id": "chat_abc123",
    "integration_id": "550e8400-e29b-41d4-a716-446655440000"
  }'
event: chat_metadata
data: {"id": "chat_abc123", "user_message_id": "msg_001"}

event: processing
data: {"status": "thinking"}

event: processing
data: {"status": "analyzing"}

event: text_delta
data: {"content": "There were 1,523 orders "}

event: text_delta
data: {"content": "placed last month (December 2024)."}

event: message
data: {"content": "There were 1,523 orders placed last month (December 2024).", "id": "msg_xyz789"}