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:

Send a Chat Completions request
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)
JSON payload JSON
{
  "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.

Stream a Chat Completions request
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[].function shape and return message.tool_calls; see Tool calling.
  • Images use image_url content parts inside a user message; see Images and vision.

Search Keiro docs

Start typing to search pages and sections.

Start typing to search pages and sections.

Documentation

Console