External Chat API Quickstart
Create a chat-scoped API key and send your first streamed or non-streamed turn through /api/v1/ext
External Chat API Quickstart
Overview
The External Chat API lets your own applications talk to a workspace assistant over HTTP. It uses a personal API key with the chat scope, optionally paired with an API client key, and returns either a single JSON response or a Server-Sent Events stream. Use it for embedded assistants, back-office tools and integrations that should not impersonate a browser session.
Prerequisites
- A chat-scoped personal API key (
ss_pat_…), created in User Settings → Apps & API Access (/user-settings/apps-and-api-access). - The numeric workspace ID you want to call.
GET /api/v1/ext/melists the workspaces the key can use. - If your organization requires it, an API client key (
ss_cli_…) created under Organization → Settings → API Clients (/org/<slug>/settings/api-clients).
Step-by-step
-
Create a key and copy it once. Chat-scoped keys cannot be used outside
/api/v1/ext. -
Probe the key and see your workspaces:
curl -s https://mcintelligentplus.magiccreative.ai/api/v1/ext/me \ -H "Authorization: Bearer ss_pat_your_key_here" -
Send a non-streamed turn to get a single JSON answer:
curl -s https://mcintelligentplus.magiccreative.ai/api/v1/ext/chat \ -H "Authorization: Bearer ss_pat_your_key_here" \ -H "Content-Type: application/json" \ -d '{"workspace_id": 9, "message": "Summarise the travel policy", "stream": false}' -
Switch to streaming for chat UIs by setting
"stream": true(the default). The response istext/event-streamwith one event perdata:line. -
Keep
conversation_idfrom the response and send it on later turns to continue the thread. Omit it to start a new conversation. -
Send
external_user_refto correlate turns with a user in your system, andclient_request_idto make retries idempotent for 10 minutes. -
When the client key is required, add
X-MCip-Client-Key: ss_cli_…to every request.
The request body is capped at 64 KB and message at 32,000 characters. The public schema is served at /api/v1/ext/openapi.json.
Example
curl -N https://mcintelligentplus.magiccreative.ai/api/v1/ext/chat \
-H "Authorization: Bearer ss_pat_your_key_here" \
-H "X-MCip-Client-Key: ss_cli_your_client_key" \
-H "Content-Type: application/json" \
-d '{
"workspace_id": 9,
"message": "List the hotel limits in the travel policy with citations",
"conversation_id": null,
"stream": true,
"external_user_ref": "employee-1042",
"client_request_id": "turn-0001"
}'Expected result
GET /api/v1/ext/mereturns the user, the API client, the key prefix and expiry, and the usable workspaces.- A successful turn returns
answer,citations,rejected_actions,usage.credits_microsanderror(null on success) in non-streamed mode, or the equivalent events when streaming. - Subsequent turns with the same
conversation_idretain context.
Limits and troubleshooting
| Status | Error code | Meaning |
|---|---|---|
| 400 | PROMPT_REFUSED | Guardrails refused the prompt |
| 401 | API_KEY_MISSING, API_KEY_INVALID, API_KEY_EXPIRED, CLIENT_KEY_MISSING | Fix the headers or create a new key |
| 403 | API_KEY_SCOPE, API_CLIENT_DISABLED, IP_DENIED, INSUFFICIENT_SCOPE | The key or client is not allowed for this call |
| 404 | CONVERSATION_NOT_FOUND | The conversation does not exist or is not visible to this key |
| 409 | CONVERSATION_BUSY, CONVERSATION_AWAITING_APPROVAL | Retry after the given delay, or continue the approval flow |
| 413 | REQUEST_TOO_LARGE | Over 64 KB per request or 32,000 characters per message |
| 429 | RATE_LIMITED, CLIENT_RATE_LIMITED | Respect the Retry-After header |
- Personal keys expire (90 days by default, 365 maximum unless the deployment caps them).
- A chat-scoped key is confined to
/api/v1/ext; use the MCP server or the web app for knowledge-base administration. - Cookie or JWT session tokens are rejected; always send a Bearer API key.