POST /v1/chat/completions
Local clients should use a `b3iq_local_` API key with the local chat scope. B3IQ router-signed requests are also accepted on this endpoint when the router HMAC headers are configured. Router-signed streaming is supported: the receipt is recorded when the stream completes and `receipt_hash` is delivered in the final SSE chunk's `b3iq` metadata.

Authentication

Bearer Token (b3iq_local) API Key (header: X-B3IQ-API-Key) Bearer Token API Key (header: X-B3IQ-Router-Signature)

Request Body required

application/json
model string REQUIRED
messages object[] REQUIRED
Array of:
role string REQUIRED
Enum: system, user, assistant, tool
content string
May be omitted or empty on an assistant tool-call turn or a tool-role result message.
name string
Tool name on a tool-role message, or an optional participant name on a user/assistant message.
tool_calls object[]
Assistant tool-call array (OpenAI shape: `[{id, type, function: {name, arguments}}]`), forwarded verbatim.
Array of: object
tool_call_id string
Links a tool-role message back to the assistant tool call it answers.
max_tokens integer
temperature number
stream boolean
runtime_id string
Optional local runtime override.
session_id string
Optional local playground session ID; unavailable for router-signed requests.
tools object[]
OpenAI-compatible tool/function definitions, forwarded verbatim to the runtime so agentic clients can drive tool-calling.
Array of: object
tool_choice unknown
OpenAI-compatible tool_choice control (`"auto"`, `"none"`, or a specific tool-selector object), forwarded verbatim to the runtime.

Responses

200 Chat completion response, or SSE stream when `stream` is true and allowed.
application/json
id string REQUIRED
object string REQUIRED
Enum: chat.completion
created integer REQUIRED
model string REQUIRED
choices object[] REQUIRED
Array of:
index integer REQUIRED
message object REQUIRED
role string REQUIRED
Enum: system, user, assistant, tool
content string
May be omitted or empty on an assistant tool-call turn or a tool-role result message.
name string
Tool name on a tool-role message, or an optional participant name on a user/assistant message.
tool_calls object[]
Assistant tool-call array (OpenAI shape: `[{id, type, function: {name, arguments}}]`), forwarded verbatim.
Array of: object
tool_call_id string
Links a tool-role message back to the assistant tool call it answers.
finish_reason string REQUIRED
usage object REQUIRED
prompt_tokens integer REQUIRED
completion_tokens integer REQUIRED
total_tokens integer REQUIRED
b3iq object REQUIRED
runtime_id string REQUIRED
runtime_kind string REQUIRED
latency_ms integer REQUIRED
ttft_ms integer
session_id string
receipt_hash string
default B3IQ-native problem response.
curl -X POST 'http://127.0.0.1:8831/v1/chat/completions' \  -H 'Authorization: Bearer YOUR_API_TOKEN' \  -H 'Content-Type: application/json' \  -d '{  "model": "string",  "messages": [    {      "role": "system",      "content": "string",      "name": "string",      "tool_calls": [        {}      ],      "tool_call_id": "string"    }  ],  "max_tokens": 1,  "temperature": 0,  "stream": false,  "runtime_id": "string",  "session_id": "string",  "tools": [    {}  ],  "tool_choice": null}'
const response = await fetch('http://127.0.0.1:8831/v1/chat/completions', {  method: 'POST',  headers: {      "Authorization": "Bearer YOUR_API_TOKEN",      "Content-Type": "application/json"  },  body: JSON.stringify({    "model": "string",    "messages": [      {        "role": "system",        "content": "string",        "name": "string",        "tool_calls": [          {}        ],        "tool_call_id": "string"      }    ],    "max_tokens": 1,    "temperature": 0,    "stream": false,    "runtime_id": "string",    "session_id": "string",    "tools": [      {}    ],    "tool_choice": null  })});const data = await response.json();console.log(data);
import requestsheaders = {    'Authorization': 'Bearer YOUR_API_TOKEN'}response = requests.post('http://127.0.0.1:8831/v1/chat/completions', headers=headers, json={  "model": "string",  "messages": [    {      "role": "system",      "content": "string",      "name": "string",      "tool_calls": [        {}      ],      "tool_call_id": "string"    }  ],  "max_tokens": 1,  "temperature": 0,  "stream": false,  "runtime_id": "string",  "session_id": "string",  "tools": [    {}  ],  "tool_choice": null})print(response.json())
200 Response
{  "id": "<string>",  "object": "chat.completion",  "created": 123,  "model": "<string>",  "choices": [    {      "index": 123,      "message": {        "role": "system",        "content": "<string>",        "name": "<string>",        "tool_calls": [          "<object>"        ],        "tool_call_id": "<string>"      },      "finish_reason": "<string>"    }  ],  "usage": {    "prompt_tokens": 123,    "completion_tokens": 123,    "total_tokens": 123  },  "b3iq": {    "runtime_id": "<string>",    "runtime_kind": "<string>",    "latency_ms": 123,    "ttft_ms": 123,    "session_id": "<string>",    "receipt_hash": "<string>"  }}
Ask a question... ⌘I