Create a chat completion
Runs an OpenAI-compatible chat completion over your connected data.
Send a messages array; the agent may query your sources server-side. With
stream: true (default) the answer streams back as Server-Sent Events
(standard chat.completion.chunk objects, terminated by data: [DONE]);
with stream: false the full answer is returned as a single
chat.completion object — use that from tools that can’t consume SSE
(n8n, Zapier, plain HTTP calls). The model field is accepted for OpenAI
compatibility but ignored — the model used is your organization’s default
LLM key. Scope a request to specific sources with source_ids. Requires
the mcp_query permission.
https://api.corebasehq.com/api/v1 and it just works. By default responses stream as text/event-stream using the standard chat.completion.chunk payload, terminated by data: [DONE]; set stream: false to get one complete chat.completion JSON object instead (for workflow tools like n8n or Zapier, and plain HTTP calls).
POST /api/v1/chat/completions is the canonical path. The older POST /api/v1/chat is kept as an alias for backward compatibility and behaves identically.conversation_id from a previous response and send only the new message —
see Multi-turn.Acting on behalf of your users
If your product has users, sendend_user with each completion — a stable id of
whoever the request is for:
end_user is for a source that isn’t
about a particular person.
Streaming response
Content-Type: text/event-stream. Each frame is a standard OpenAI chat.completion.chunk:
X-Conversation-Id header — keep it to continue the conversation later without resending history.
Non-streaming (stream: false)
One complete chat.completion object, Content-Type: application/json:
conversation_id is a CoreBase extension; OpenAI clients ignore it.
Using the OpenAI SDK
Because the wire format matches OpenAI, you can use any OpenAI client:Tool calls
When the model invokes one of your connected data sources, the call streams as a standard OpenAItool_calls delta:
Errors
Multi-turn
Two ways to continue a conversation — pick one per conversation, don’t mix them.Resend the history (OpenAI-style)
Append assistant replies to themessages array on subsequent calls. The model uses the full conversation as context.
Continue by conversation_id
Every response returns a conversation_id (as a body field on non-streaming responses, and as the X-Conversation-Id header on both). Pass it back with only the new message — the server keeps the history, so requests stay small and prompt size doesn’t grow with every turn:
404. A continued conversation always stays in the project it started in; project_id is ignored on continuation.Authorizations
A cb_live_ API token, created in the panel under API Tokens.
Body
An OpenAI-compatible chat completion request. model is accepted but
ignored — the model used is your organization's default LLM key.
The conversation so far, oldest first.
1 - 200 elementsAccepted for OpenAI compatibility but ignored.
True (default) streams Server-Sent Events; false returns one complete chat.completion JSON object — for callers that can't consume SSE (workflow tools like n8n or Zapier, plain HTTP).
Restrict the request to these data source ids (from the sources endpoint). Omit to use every source in the project.
Run the completion inside this project (workspace). Omit to use the organization's default project. List ids with the projects endpoint.
Run this completion on behalf of one of your users. Sources scoped to an end user (identity headers, pinned parameters, row-level database scope) resolve to this value, and usage, memory and the audit trail are attributed to it. Omit for a request that isn't about a particular person — scoped sources are then unavailable rather than unscoped.
200Continue a server-stored conversation instead of resending the history. Take the value from a previous response (the conversation_id field / X-Conversation-Id header) and send ONLY the new message(s) in messages — the server prepends the stored history. Omit for a new conversation (fully stateless, backward compatible). Ids are only valid for the token identity that created them.
Response
A Server-Sent Event stream of OpenAI chat.completion.chunk objects, terminated by data: [DONE].
The response is of type string.