Create a chat completion
The OpenAI Chat Completions API: messages (text and, on models with `image_input`, images), tools and tool choice, `response_format` with JSON Schema, sampling parameters and streaming. With `stream: true` the response is server-sent events of `chat.completion.chunk` objects ending with `data: [DONE]`, exactly as OpenAI sends them; `stream_options.include_usage` adds a final usage chunk (and `"usage": null` on the others). A stream that fails after it started ends with an OpenAI error event (`data: {"error": {...}}`); one that fails before the first token is a plain HTTP error. The response head of a stream waits for the first generated token, so `Server-Timing` can carry `ttft`. Parameters this node does not take return `400 unsupported_parameter` naming the parameter. Besides the OpenAI parameters below, it takes the sampling extensions `top_k`, `min_p`, `repetition_penalty` and `logit_bias`, and `chat_template_kwargs.enable_thinking` (the model answers without a reasoning phase unless it is `true`; the reasoning then arrives in `reasoning_content`). `metadata`, `store` and `service_tier` are accepted and ignored. `null` means unset for every optional parameter. Image URLs are `https://` (fetched by the node through its egress guard, which refuses private, loopback and metadata addresses with `403 egress_denied`) or `data:image/{png,jpeg,webp,gif};base64,`. JSON Schemas (tool `parameters`, `response_format.json_schema.schema`) larger than 64 KiB or nested deeper than 32 levels are `400 unsupported_parameter`. Bills input and output tokens. Requests are admitted against your organization's per-minute limits on the model: one request, and the estimated prompt plus `max_completion_tokens` (or `max_tokens`, else 512 tokens), settled with the real counts when the request ends.
/v1/infer/chat/completions
Authentication
Request Body required
application/jsonmodel
string
REQUIRED
messages
object[]
REQUIRED
role
string
REQUIRED
system, developer, user, assistant, toolcontent
string | null | (object | object)[]
type
string
REQUIRED
texttext
string
REQUIRED
type
string
REQUIRED
image_urlimage_url
object
REQUIRED
name
string | null
tool_calls
object[] | null
id
string
REQUIRED
type
string
REQUIRED
functionfunction
object
REQUIRED
name
string
REQUIRED
arguments
string
REQUIRED
tool_call_id
string | null
refusal
string | null
reasoning_content
string | null
tools
object[] | null
type
string
REQUIRED
functionfunction
object
REQUIRED
name
string
REQUIRED
description
string
parameters
object
strict
boolean
tool_choice
string | null | object
type
string
REQUIRED
functionfunction
object
REQUIRED
name
string
REQUIRED
parallel_tool_calls
boolean | null
response_format
object | null | object | object
type
string
REQUIRED
texttype
string
REQUIRED
json_objecttype
string
REQUIRED
json_schemajson_schema
object
REQUIRED
name
string
REQUIRED
description
string
schema
object
strict
boolean
temperature
number | null
top_p
number | null
max_tokens
integer | null
max_completion_tokens
integer | null
stop
string | null | string[]
seed
integer | null
n
integer | null
presence_penalty
number | null
frequency_penalty
number | null
logprobs
boolean | null
top_logprobs
integer | null
user
string | null
stream
boolean | null
stream_options
object | null
include_usage
boolean | null
route
string | null
local, gateway, nulltop_k
integer | null
min_p
number | null
repetition_penalty
number | null
logit_bias
object | null
chat_template_kwargs
object | null
enable_thinking
boolean
metadata
object | null
store
boolean | null
service_tier
string | null
Responses
application/jsonid
string
REQUIRED
object
string
REQUIRED
chat.completioncreated
integer
REQUIRED
model
string
REQUIRED
choices
object[]
REQUIRED
index
integer
REQUIRED
message
object
REQUIRED
role
string
REQUIRED
assistantcontent
string | null
REQUIRED
tool_calls
object[]
id
string
REQUIRED
type
string
REQUIRED
functionfunction
object
REQUIRED
name
string
REQUIRED
arguments
string
REQUIRED
refusal
string | null
reasoning_content
string
finish_reason
string
REQUIRED
stop, length, tool_calls, content_filterlogprobs
object | null
usage
object
prompt_tokens
integer
REQUIRED
completion_tokens
integer
REQUIRED
total_tokens
integer
REQUIRED
system_fingerprint
string | null
b3os
object
route
string
local, gatewaynode
string
timing
object
ttft_ms
number
model_ms
number
total_ms
number
curl -X POST 'https://beta-api.b3os.org/v1/infer/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": [ { "id": "string", "type": "function", "function": { "name": "string", "arguments": "string" } } ], "tool_call_id": "string", "refusal": "string", "reasoning_content": "string" } ], "tools": [ { "type": "function", "function": { "name": "string", "description": "string", "parameters": {}, "strict": true } } ], "tool_choice": "none", "parallel_tool_calls": true, "response_format": { "type": "text" }, "temperature": 0, "top_p": 0, "max_tokens": 1, "max_completion_tokens": 1, "stop": "string", "seed": 0, "n": 1, "presence_penalty": -2, "frequency_penalty": -2, "logprobs": true, "top_logprobs": 0, "user": "string", "stream": false, "stream_options": { "include_usage": true }, "route": "local", "top_k": -1, "min_p": 0, "repetition_penalty": 0, "logit_bias": {}, "chat_template_kwargs": { "enable_thinking": true }, "metadata": {}, "store": true, "service_tier": "string"}'
const response = await fetch('https://beta-api.b3os.org/v1/infer/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": [ { "id": "string", "type": "function", "function": { "name": "string", "arguments": "string" } } ], "tool_call_id": "string", "refusal": "string", "reasoning_content": "string" } ], "tools": [ { "type": "function", "function": { "name": "string", "description": "string", "parameters": {}, "strict": true } } ], "tool_choice": "none", "parallel_tool_calls": true, "response_format": { "type": "text" }, "temperature": 0, "top_p": 0, "max_tokens": 1, "max_completion_tokens": 1, "stop": "string", "seed": 0, "n": 1, "presence_penalty": -2, "frequency_penalty": -2, "logprobs": true, "top_logprobs": 0, "user": "string", "stream": false, "stream_options": { "include_usage": true }, "route": "local", "top_k": -1, "min_p": 0, "repetition_penalty": 0, "logit_bias": {}, "chat_template_kwargs": { "enable_thinking": true }, "metadata": {}, "store": true, "service_tier": "string" })});const data = await response.json();console.log(data);
import requestsheaders = { 'Authorization': 'Bearer YOUR_API_TOKEN'}response = requests.post('https://beta-api.b3os.org/v1/infer/chat/completions', headers=headers, json={ "model": "string", "messages": [ { "role": "system", "content": "string", "name": "string", "tool_calls": [ { "id": "string", "type": "function", "function": { "name": "string", "arguments": "string" } } ], "tool_call_id": "string", "refusal": "string", "reasoning_content": "string" } ], "tools": [ { "type": "function", "function": { "name": "string", "description": "string", "parameters": {}, "strict": true } } ], "tool_choice": "none", "parallel_tool_calls": true, "response_format": { "type": "text" }, "temperature": 0, "top_p": 0, "max_tokens": 1, "max_completion_tokens": 1, "stop": "string", "seed": 0, "n": 1, "presence_penalty": -2, "frequency_penalty": -2, "logprobs": true, "top_logprobs": 0, "user": "string", "stream": false, "stream_options": { "include_usage": true }, "route": "local", "top_k": -1, "min_p": 0, "repetition_penalty": 0, "logit_bias": {}, "chat_template_kwargs": { "enable_thinking": true }, "metadata": {}, "store": true, "service_tier": "string"})print(response.json())
{ "id": "chatcmpl-01m5t5tmscqev5tf32q87tr1v5", "object": "chat.completion", "created": 1793001600, "model": "b3os/qwen3.5-9b", "choices": [ { "index": 0, "message": { "role": "assistant", "content": null, "tool_calls": [ { "id": "call_7f3a", "type": "function", "function": { "name": "get_weather", "arguments": "{\"city\":\"Eugene\"}" } } ] }, "finish_reason": "tool_calls", "logprobs": null } ], "usage": { "prompt_tokens": 61, "completion_tokens": 18, "total_tokens": 79 }, "b3os": { "route": "local", "node": "n1" }}
Try this endpoint
/v1/infer/chat/completions