Chat Completions
Use POST /v1/chat/completions when your application already sends ordered message arrays and reads choices[0].message.
On this page 1 of 6
Request#
A minimal request includes a public model and at least one message:
from getpass import getpass
from openai import OpenAI
client = OpenAI(
base_url="https://api.keirolabs.ai/v1",
api_key=getpass("Keiro API key: "),
)
response = client.chat.completions.create(
model="eb1-preview",
messages=[
{"role": "system", "content": "Answer concisely."},
{"role": "user", "content": "Explain vector databases."},
],
)
print(response.choices[0].message.content)
{
"model": "eb1-preview",
"messages": [
{
"role": "user",
"content": "Explain token buckets in one sentence."
}
]
}
Use the system role or supported top-level system compatibility field for stable instructions. Keep application-specific context in explicit messages.
Response#
Read generated text from choices[0].message.content, the terminal reason from choices[0].finish_reason, and canonical token accounting from usage.
Treat the public response layout as the contract. Do not depend on private model selection, vendor metadata, or internal cost fields.
Supported controls#
The current Chat Completions surface supports the documented message input plus controls including stream, temperature, top_p, stop, max_tokens or max_completion_tokens, seed, tools, tool_choice, parallel_tool_calls, text response format, logprobs, user, metadata, and reasoning controls.
Strict validation rejects unknown fields. JSON mode and JSON Schema structured output are not currently supported.
Streaming#
Set stream to true to receive server-sent events. Text arrives in choices[0].delta.content; tool calls arrive in delta.tool_calls. Assemble fragments by choice and tool-call index, and wait for the terminal finish reason before executing a tool.
from getpass import getpass
from openai import OpenAI
client = OpenAI(
base_url="https://api.keirolabs.ai/v1",
api_key=getpass("Keiro API key: "),
)
stream = client.chat.completions.create(
model="eb1-preview",
messages=[{"role": "user", "content": "Count to three."}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
Streams are governed by documented idle and wall-clock time entitlements, not a flat timeout. reasoning_effort selects the run's entitlement row — see Streaming, and the same page for terminal and error handling.
Tools and images#
- Function tools use the Chat Completions nested
tools[].functionshape and returnmessage.tool_calls; see Tool calling. - Images use
image_urlcontent parts inside a user message; see Images and vision.