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
}
FieldRequiredNotes
messageYes1 to 32,000 characters.
conversationIdNoContinue an API v2 conversation. Unknown IDs return 404.
userIdNoStable end-user ID for grouping API conversations. Letters, numbers, ., _, and - are allowed.
streamNoDefaults 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

MethodEndpointDescriptionReference
GET/api/v2/healthCheck API health.Health
GET/api/v2/agentsList agents.Agents and settings
POST/api/v2/agentsCreate 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}/chatSend a chat message.Chat
GET/api/v2/agents/{agentId}/conversationsList conversations by source.Conversations
GET/api/v2/agents/{agentId}/conversations/exportExport conversations with messages.Conversations
GET/api/v2/agents/{agentId}/conversations/{conversationId}Get one conversation by source.Conversations
GET/api/v2/agents/{agentId}/conversations/{conversationId}/messagesList messages in an API v2 conversation.Conversations
POST/api/v2/agents/{agentId}/conversations/{conversationId}/retryRetry an API v2 assistant reply.Conversations
POST/api/v2/agents/{agentId}/conversations/{conversationId}/tool-resultSubmit a client-side tool result.Conversations
PATCH/api/v2/agents/{agentId}/conversations/{conversationId}/messages/{messageId}/feedbackSet or clear assistant message feedback.Conversations
GET/api/v2/agents/{agentId}/users/{userId}/conversationsList API v2 conversations for an end user.Conversations
GET/api/v2/agents/{agentId}/sourcesList training sources.Sources and training
POST/api/v2/agents/{agentId}/sources/textAdd a text source.Sources and training
POST/api/v2/agents/{agentId}/sources/qnaAdd a Q&A source.Sources and training
POST/api/v2/agents/{agentId}/sources/urlAdd or retrain one URL source.Sources and training
POST/api/v2/agents/{agentId}/sources/file/upload-urlCreate signed URLs for direct file uploads.Sources and training
POST/api/v2/agents/{agentId}/sources/fileRegister 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}/contactsList contacts.Contacts
POST/api/v2/agents/{agentId}/contactsCreate or update one contact by external ID.Contacts
POST/api/v2/agents/{agentId}/contacts/importBulk upsert contacts.Contacts
GET/api/v2/agents/{agentId}/leadsList captured leads.Contacts and leads
GET/PATCH/api/v2/agents/{agentId}/settings/aiRead or update AI settings.Agents and settings
GET/PATCH/api/v2/agents/{agentId}/settings/designRead or update design settings.Agents and settings
GET/PATCH/api/v2/agents/{agentId}/settings/securityRead or update security settings.Agents and settings
GET/PATCH/api/v2/agents/{agentId}/settings/notificationsRead or update notification settings.Agents and settings
GET/PATCH/api/v2/agents/{agentId}/settings/trainingRead or update training settings.Agents and settings
GET/api/v2/agents/{agentId}/channels/instagramGet 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-startersRead or update Instagram conversation starters.Instagram channel
GET/api/v2/agents/{agentId}/trainGet training status.Sources and training
POST/api/v2/agents/{agentId}/trainStart 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.

QueryNotes
limitDefaults 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.
cursorOpaque 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

CodeMeaning
AUTH_INVALID_API_KEYThe bearer API key cannot be validated.
SUBSCRIPTION_PLAN_REQUIREDThe workspace plan does not include API access.
AGENT_NOT_FOUNDThe agent does not exist or does not belong to the API key's account.
VALIDATION_INVALID_BODYA 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

Next Steps