API v2
Use the v2 REST API for agent management, streaming chat, conversations, feedback, sources, contacts, leads, and settings.
API v2 is a structured REST API for managing agents and building custom chat experiences. It adds agent management, streaming chat, conversation history, message feedback, contacts, leads, sources, settings, and training endpoints.
API access requires a Hobby plan or above with active billing.
Base URL
https://your-domain.com/api/v2
Authentication
Except for the health check, send your workspace API key as a bearer token:
Authorization: Bearer YOUR_API_KEY
Create and revoke API keys from Settings > API Keys.
Response Format
Most successful responses return either a resource object or a data envelope:
{
"data": []
}
List endpoints include cursor pagination:
{
"data": [],
"pagination": {
"cursor": null,
"hasMore": false,
"total": 0
}
}
Errors use a structured error object:
{
"error": {
"code": "VALIDATION_INVALID_BODY",
"message": "Invalid request body"
}
}
Every v2 response includes an x-request-id header. Include it when contacting support about an API request.
Conversation Scope
Read-only conversation endpoints default to source=api_v2. Set source=widget to return widget and Playground conversations; Playground rows are stored with the widget source. Set source=all to return API v2, widget, and Playground conversations. Results always remain limited to the authenticated account's agent. An invalid source value or more than one source query parameter returns 400 VALIDATION_INVALID_BODY. Chat continuation, retry, feedback, message listing, and per-user reads remain scoped to API v2 conversations.
Health
GET /api/v2/health
The health check does not require authentication.
Success: 200 OK
{
"status": "ok",
"timestamp": 1784332800
}
timestamp is the current Unix timestamp in seconds.
Chat
POST /api/v2/agents/{agentId}/chat
Request:
{
"message": "What plans do you offer?",
"conversationId": "optional-existing-conversation-id",
"userId": "optional-user-id",
"stream": true
}
| Field | Required | Notes |
|---|---|---|
message | Yes | 1 to 32,000 characters. |
conversationId | No | Continue an API v2 conversation. Unknown IDs return 404. |
userId | No | Stable end-user ID for grouping API conversations. Letters, numbers, ., _, and - are allowed. |
stream | No | Defaults to true. Set false for one JSON response. |
Streaming responses use Server-Sent Events. The stream includes message-start, text-start, text-delta, text-end, message-metadata, finish, and [DONE] events. A stream or completion-hook failure emits an error event with error.code set to CHAT_STREAMING_ERROR; this SSE-only protocol code is separate from the structured REST error catalog. message-metadata contains the assistant message ID when persistence succeeds, plus the conversation ID, user ID, finish reason, and usage. Its messageId is null when no assistant message was persisted. When the reply pauses on a client-side action, the stream also emits a tool-call event with { "id", "name", "arguments" }; submit the outcome to the tool-result endpoint to resume the conversation — the response to that request streams the continuation.
Non-streaming responses return:
{
"data": {
"id": "123",
"role": "assistant",
"parts": [{ "type": "text", "text": "..." }],
"pendingToolCall": null,
"metadata": {
"userMessageId": "122",
"conversationId": "abc123",
"userId": "user_123",
"finishReason": "stop",
"usage": { "credits": 1 }
}
}
}
The non-streaming data.id and metadata.userMessageId values are numeric message IDs serialized as strings, or null when the corresponding message was not persisted. metadata.userId is the supplied/stored user ID or null. pendingToolCall is null unless the reply paused on a client-side tool call, in which case it holds { "id", "name", "arguments" } for the tool-result endpoint.
Endpoint Summary
| Method | Endpoint | Description | Reference |
|---|---|---|---|
| GET | /api/v2/health | Check API health. | Health |
| GET | /api/v2/agents | List agents. | Agents and settings |
| POST | /api/v2/agents | Create an agent. | Agents and settings |
| GET | /api/v2/agents/{agentId} | Get an agent. | Agents and settings |
| PATCH | /api/v2/agents/{agentId} | Update agent name or URL. | Agents and settings |
| DELETE | /api/v2/agents/{agentId} | Delete an agent. | Agents and settings |
| POST | /api/v2/agents/{agentId}/chat | Send a chat message. | Chat |
| GET | /api/v2/agents/{agentId}/conversations | List conversations by source. | Conversations |
| GET | /api/v2/agents/{agentId}/conversations/export | Export conversations with messages. | Conversations |
| GET | /api/v2/agents/{agentId}/conversations/{conversationId} | Get one conversation by source. | Conversations |
| GET | /api/v2/agents/{agentId}/conversations/{conversationId}/messages | List messages in an API v2 conversation. | Conversations |
| POST | /api/v2/agents/{agentId}/conversations/{conversationId}/retry | Retry an API v2 assistant reply. | Conversations |
| POST | /api/v2/agents/{agentId}/conversations/{conversationId}/tool-result | Submit a client-side tool result. | Conversations |
| PATCH | /api/v2/agents/{agentId}/conversations/{conversationId}/messages/{messageId}/feedback | Set or clear assistant message feedback. | Conversations |
| GET | /api/v2/agents/{agentId}/users/{userId}/conversations | List API v2 conversations for an end user. | Conversations |
| GET | /api/v2/agents/{agentId}/sources | List training sources. | Sources and training |
| POST | /api/v2/agents/{agentId}/sources/text | Add a text source. | Sources and training |
| POST | /api/v2/agents/{agentId}/sources/qna | Add a Q&A source. | Sources and training |
| POST | /api/v2/agents/{agentId}/sources/url | Add or retrain one URL source. | Sources and training |
| POST | /api/v2/agents/{agentId}/sources/file/upload-url | Create signed URLs for direct file uploads. | Sources and training |
| POST | /api/v2/agents/{agentId}/sources/file | Register uploaded files and start processing. | Sources and training |
| DELETE | /api/v2/agents/{agentId}/sources/{documentId} | Delete a source. | Sources and training |
| GET | /api/v2/agents/{agentId}/contacts | List contacts. | Contacts |
| POST | /api/v2/agents/{agentId}/contacts | Create or update one contact by external ID. | Contacts |
| POST | /api/v2/agents/{agentId}/contacts/import | Bulk upsert contacts. | Contacts |
| GET | /api/v2/agents/{agentId}/leads | List captured leads. | Contacts and leads |
| GET/PATCH | /api/v2/agents/{agentId}/settings/ai | Read or update AI settings. | Agents and settings |
| GET/PATCH | /api/v2/agents/{agentId}/settings/design | Read or update design settings. | Agents and settings |
| GET/PATCH | /api/v2/agents/{agentId}/settings/security | Read or update security settings. | Agents and settings |
| GET/PATCH | /api/v2/agents/{agentId}/settings/notifications | Read or update notification settings. | Agents and settings |
| GET/PATCH | /api/v2/agents/{agentId}/settings/training | Read or update training settings. | Agents and settings |
| GET | /api/v2/agents/{agentId}/channels/instagram | Get the Instagram connection, automations, and conversation starters. | Instagram channel |
| GET/PATCH | /api/v2/agents/{agentId}/channels/instagram/automations/{key} | Read or update one Instagram automation. | Instagram channel |
| GET/PATCH | /api/v2/agents/{agentId}/channels/instagram/conversation-starters | Read or update Instagram conversation starters. | Instagram channel |
| GET | /api/v2/agents/{agentId}/train | Get training status. | Sources and training |
| POST | /api/v2/agents/{agentId}/train | Start retraining web sources. | Sources and training |
Feedback
Use feedback to mark API v2 assistant messages as positive, negative, or null. See Conversations, messages, and feedback for the request schema, response, and error behavior.
Pagination
Treat cursors as opaque tokens returned by the API. Replay the pagination.cursor value unchanged on the next request; do not construct or decode it.
| Query | Notes |
|---|---|
limit | Defaults to 20. It must be an integer from 1 to 100 unless an endpoint documents a lower maximum; conversation export has a maximum of 20. |
cursor | Opaque cursor returned from the previous page. Invalid cursors return 400 VALIDATION_INVALID_BODY. |
Contacts also accept search. Leads accept inclusive createdAfter and createdBefore ISO 8601 datetime filters. Sources accept sourceType with web_crawl, file_upload, text_snippet, or qna_entry.
Cursor formats are an internal implementation detail. Clients must treat every cursor as opaque and replay it unchanged without constructing or decoding it.
Common Errors
| Code | Meaning |
|---|---|
AUTH_INVALID_API_KEY | The bearer API key cannot be validated. |
SUBSCRIPTION_PLAN_REQUIRED | The workspace plan does not include API access. |
AGENT_NOT_FOUND | The agent does not exist or does not belong to the API key's account. |
VALIDATION_INVALID_BODY | A request body, path value, query parameter, limit, or cursor failed validation. |
See the complete API v2 error catalog for all 27 declared codes, HTTP statuses, triggers, and reserved codes.
Reference
- Error catalog
- Agents and settings
- Conversations, messages, retries, and feedback
- Sources and training
- Contacts and leads
- Instagram channel