Chat completions

POST /v1/chat/completions accepts an OpenAI-style JSON body and forwards it to the devshard gateway.

On this page

POST /v1/chat/completions

Auth is an obk- key. The body is forwarded. OpenBroker does not rewrite messages, max_tokens, temperature, or tools. If a model or host rejects a field, that error is returned as the upstream response.

Required fields you should set

  • model — a full id from GET /v1/models.
  • messages — the usual role / content list.
  • max_tokens — caps the completion. The gateway reserves balance for input length + max_tokens before the call, then settles what actually ran. A huge max_tokens reserves more than the reply will cost. See Pricing.
bash
curl https://api.openbroker.gonka.gg/v1/chat/completions \
  -H "Authorization: Bearer obk-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MiniMaxAI/MiniMax-M2.7",
    "messages": [
      { "role": "user", "content": "Explain devshards in one sentence." }
    ],
    "max_tokens": 100
  }'
python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.openbroker.gonka.gg/v1",
    api_key="obk-YOUR_API_KEY",
)

response = client.chat.completions.create(
    model="MiniMaxAI/MiniMax-M2.7",
    messages=[{"role": "user", "content": "Explain devshards in one sentence."}],
    max_tokens=100,
)

print(response.choices[0].message.content)
javascript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.openbroker.gonka.gg/v1",
  apiKey: "obk-YOUR_API_KEY",
});

const response = await client.chat.completions.create({
  model: "MiniMaxAI/MiniMax-M2.7",
  messages: [{ role: "user", content: "Explain devshards in one sentence." }],
  max_tokens: 100,
});

console.log(response.choices[0].message.content);

Response

A success is the OpenAI chat completion object: id, choices[].message.content, and usage when the gateway sends token counts.

Save id if you want to look the call up later. Also read the X-Request-Id response header. It is present when the gateway assigned a request id, including on some errors that never produced a JSON body. Pass either value to GET /v1/usage/{id}.

Streaming

Set "stream": true for server-sent events. That path has its own timeout behavior. Read Streaming before you put a 15 or 30 second client timeout on it.

Legacy completions

POST /v1/completions with a string prompt is accepted and translated into a one-message chat request. Batch prompts are rejected. See Legacy completions.