Skip to main content
POST
Create a chat completion
The endpoint is OpenAI-compatible — point any OpenAI SDK at 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.
The endpoint is stateless by default — pass the full history on every call, exactly like OpenAI. To skip resending history, take the 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, send end_user with each completion — a stable id of whoever the request is for:
That identity is what makes per-user scoping work. Sources configured with an identity header, a pinned parameter, or row-level database scope resolve to this value, so each of your users only ever reaches their own rows — enforced by your own API or database rules, not by prompt instructions. Usage, memory and the audit trail are attributed to it too. Omit it and those sources are simply not available for the request, rather than running unscoped. A request with no 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:
Every response also carries an 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:
The agent still queries your sources server-side — the request simply blocks until the full answer is ready, so expect response times of several seconds for tool-heavy questions. 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 OpenAI tool_calls delta:
Tool execution happens server-side inside CoreBase — you don’t need to handle the call. The next text deltas after the tool call carry the model’s interpretation of the result.

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 the messages 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:
A conversation belongs to the API token that started it — another token (or another organization) gets a 404. A continued conversation always stays in the project it started in; project_id is ignored on continuation.

Authorizations

Authorization
string
header
required

A cb_live_ API token, created in the panel under API Tokens.

Body

application/json

An OpenAI-compatible chat completion request. model is accepted but ignored — the model used is your organization's default LLM key.

messages
DeveloperMessage · object[]
required

The conversation so far, oldest first.

Required array length: 1 - 200 elements
model
string | null

Accepted for OpenAI compatibility but ignored.

stream
boolean
default:true

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).

source_ids
string[] | null

Restrict the request to these data source ids (from the sources endpoint). Omit to use every source in the project.

project_id
string | null

Run the completion inside this project (workspace). Omit to use the organization's default project. List ids with the projects endpoint.

end_user
string | null

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.

Maximum string length: 200
conversation_id
string | null

Continue 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.