Skip to content

Chat completions

POST /v1/chat/completions takes a conversation and returns the assistant’s next message. The request and response shapes are OpenAI’s; this page covers what siema_ai does with each field.

from openai import OpenAI
import os
client = OpenAI(base_url="https://api.siema-ai.pl/v1", api_key=os.environ["SIEMA_API_KEY"])
r = client.chat.completions.create(
model="speakleash/bielik-11b-v3.0-instruct",
messages=[
{"role": "system", "content": "Jesteś asystentem działu obsługi klienta sklepu z elektroniką."},
{"role": "user", "content": "Klient pyta, czy może zwrócić otwarte słuchawki po 10 dniach. Odpowiedz uprzejmie."},
],
max_tokens=300,
temperature=0.3,
)
print(r.choices[0].message.content)
print(r.usage) # prompt_tokens, completion_tokens, total_tokens

Set your HTTP client’s own timeout to 180 seconds or more — the gateway’s own budget for a cold start (see Streaming). A shorter client timeout can abandon the request before the model has answered; you’re still charged the estimated input tokens for it, and if your SDK retries on timeout (twice by default), that cost repeats on every retry.

Field What siema_ai does
model Required. A model id from GET /v1/models, such as qwen/qwen3.8-27b. An id that doesn’t exist returns 404 model_not_found. A model that exists but doesn’t have the chat capability (an embeddings model, for example) returns 400 invalid_request with param: "model".
messages Required, a non-empty array. Roles system, user, assistant, tool. content is a string, an array of content parts, or null — an assistant message that carries only tool_calls has null content.
stream false returns one JSON object; true returns server-sent events. See Streaming.
stream_options.include_usage When true, the final stream chunk carries usage. The gateway always fetches usage from the model server for billing; this flag only controls whether you see it.
max_tokens, max_completion_tokens Either name works and both mean the same thing: an upper bound on generated tokens, an integer of at least 1 (anything else is 400 invalid_request). A value above the model’s max_output_tokens is clamped silently to that ceiling. Omit the field, or send JSON null, and the model’s ceiling is used. This null-is-absent handling is specific to these two fields: a null model or messages is 400 invalid_request, and every other field’s null is forwarded as sent. Whichever name you send, the value forwarded upstream is always max_tokens.
n Up to 8; above that is 400 invalid_request with param: "n". The model server may return more than one choice; the output tokens of every choice returned are billed, not just the first.
best_of Not supported. Sending it at all, with any value, is 400 invalid_request with param: "best_of".
temperature, top_p, stop, user Forwarded to the model unchanged.
Anything else Forwarded unchanged: tools, tool_choice, response_format, seed, logprobs, presence_penalty, frequency_penalty, and so on. If the model server rejects a field, you get its error back, typically as 400 invalid_request.
Value Meaning
stop The model finished or hit one of your stop sequences.
length Generation hit max_tokens. If you asked for more than max_output_tokens, this is the clamped ceiling, not your number. Ask for a shorter answer or continue the conversation.
tool_calls The model wants to call a tool; see message.tool_calls.
content_filter The model server stopped generation. Rare with open models.

tools and tool_choice pass straight through to the model server unchanged. Both qwen/qwen3.5-397b-a17b and qwen/qwen3.8-27b have the tools capability and return OpenAI-shaped tool_calls (tool messages with role tool go back in the conversation as usual). Even so, we do not promise tool calling for every prompt or schema — test it with your own tools before relying on it in production. If the model server doesn’t support the fields you send, you get its error back as 400 invalid_request.

response_format is forwarded unchanged. On the two Qwen models, {"type": "json_schema", "json_schema": {...}} (with "strict": true if you like) returns content that parses as JSON and follows your schema in our testing, and {"type": "json_object"} returns a JSON object. The gateway does not validate the reply: validate it yourself, as with any model. With reasoning on, the thinking uses part of max_tokens, so a schema-shaped answer can be cut off (finish_reason: "length") if the budget is too small.

Some models, such as qwen/qwen3.5-397b-a17b and qwen/qwen3.8-27b, think before they answer. That is the model’s own behaviour: siema_ai sets no default for it, and reasoning_effort is forwarded like any other field, so you choose per request. Send reasoning_effort: "none" to switch reasoning off; that is verified on the upstreams we have tested. How the other values change the amount of reasoning depends on the upstream, and some ignore them. When a model reasons, its reply carries the thinking in message.reasoning (delta.reasoning when streaming), separate from content; those tokens are billed as completion tokens, and they count against max_tokens: a reply that spends its whole budget thinking ends with finish_reason: "length" and may have an empty content. Raise max_tokens (up to the model’s max_output_tokens), or send reasoning_effort: "none" when you need the full length for the answer.

Image content parts are forwarded to the model server unmodified and unvalidated by the gateway. Only a model whose capabilities include vision understands an image_url part — and no model has vision today (check GET /v1/models before you build against this). Send images the same way once a vision-capable model is available:

r = client.chat.completions.create(
model="<a future model id with vision in its capabilities>",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "Co jest na tym paragonie? Wypisz pozycje i sumę."},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,/9j/4AAQ..."}},
],
}],
)

Send an image part to a model without vision and the model server that receives it can’t understand the part; it rejects the request and the gateway surfaces that as 400 invalid_request. Image bytes are forwarded to the model server and, like all prompt content, are never stored.

  • A short system message in Polish (Odpowiadaj po polsku.) is a simple way to keep the reply language consistent across the chat models.
  • Bielik handles formal register well; say formalnie or bezpośrednio when it matters.
  • For structured output, use response_format (see Structured output) and validate the result, as with any model.

Cost in micro-PLN is ceil(prompt_tokens × input_price / 1 000 000) + ceil(completion_tokens × output_price / 1 000 000), each term rounded up separately, at the price in force when the request started. For example, on speakleash/bielik-11b-v3.0-instruct’s current placeholder prices, 2 000 prompt tokens and 500 completion tokens cost 3 000 + 1 500 = 4 500 micro-PLN.

The usage object in the response is what you’re billed for when the model server reports it, and its cost_micro_pln field is what this request costs (see Reading cost and balance). When it doesn’t — for instance a stream that breaks before reaching a final usage chunk — siema_ai estimates the tokens instead and marks the request estimated in the console; see Streaming. See Billing for the full picture.