Create chat completion
Generate a chat completion for the given messages, following the OpenAI Chat Completions API wire format.
Set stream: true to receive a Server-Sent Events stream. Each event carries a chat.completion.chunk object. When stream_options.include_usage is true, the final chunk before [DONE] includes a usage field with token counts.
Please provide header value as 'Bearer ' and don't forget to add 'Bearer' HTTP Authorization Scheme before the token.
Request body for POST /v1/chat/completions (OpenAI Chat Completions API).
ID of the model to use.
openai/gpt-oss-120bThe format the model must output. Which formats a model supports is model-specific.
Sampling temperature between 0 and 2.
Nucleus sampling probability mass, greater than 0 and at most 1. A value outside that range, including exactly 0, is rejected with a 400.
Number of chat completion choices to generate. When omitted, the model chooses.
If true, stream partial results as Server-Sent Events.
falseUp to 4 sequences at which generation stops.
Maximum number of tokens to generate. For a reasoning model, the reasoning counts
toward this limit and comes before the answer. If the limit is reached while the
model is still reasoning, the response has finish_reason length, an empty
content, and the reasoning so far in reasoning. A lower reasoning_effort
leaves more of the limit for the answer.
Maximum number of tokens to generate, including any reasoning, as for max_tokens.
OpenAI's replacement for the deprecated max_tokens. Avoid setting both in one
request: which of the two applies is model-specific. The accepted range is
model-specific.
Penalize tokens that have appeared so far in the text.
Penalize tokens based on their frequency in the text.
Whether to return log probabilities of the output tokens.
Number of most-likely tokens to return at each position, when logprobs is true.
Opaque identifier for your end user.
How much reasoning to do before answering, for reasoning-capable models. Accepted values are model-specific. A value the model does not accept is rejected with a 400.
highControls which tool, if any, the model calls. none means no tool call, auto lets
the model decide, and required forces a tool call. A named tool object forces a
specific function.
Which values a model honors is model-specific. A model may answer with a normal
message instead of the tool call that required or a named function asks for. The
value is not checked, so how any other value is answered is also model-specific.
Seed for deterministic sampling. Repeated requests with the same seed and parameters return the same completion on a best-effort basis. Support is model-specific.
Whether the model may emit more than one tool call in a single turn. Whether it is honored is model-specific.
Successful operation. Returns ChatCompletionResponse for non-streaming requests,
or a text/event-stream of chat.completion.chunk objects when stream: true.
Bad Request
The request sent to the API was malformed.
Unauthorized
The request is missing authorization information or the authorization information provided are expired.
Forbidden
The user issuing the request does not have the needed permissions.
Not Found
The requested model or endpoint does not exist. A model that exists but lacks the capability the request needs is rejected with a 400 instead.
Payload Too Large
The request exceeds a size limit. The request body is limited to 16 MiB, an inline
base64 data URI to 12 MiB decoded, and an uploaded image or mask to 10 MiB. On
/v1/chat/completions, /v1/embeddings, and /v1/rerank, a message, query, or
document is limited to 2048 content parts. Count limits, such as the number of
documents, are stated with each field. Pass large media as a remote HTTP or HTTPS URL
instead of inline base64: a URL does not count against the size limits, though it
still counts as a content part.
Unprocessable Entity
The request was well-formed but contains semantic errors.
Too Many Requests
Your contract's rate limit is exhausted. Wait the number of seconds in Retry-After
before retrying, rather than a delay of your own. The OpenAI SDKs do this
automatically. Limits are contract-specific.
Internal Server Error
The request could not be completed because of an internal error. The request was
not necessarily rejected, so a retry is safe for idempotent calls. If it persists,
quote the value of the X-Request-Id response header when contacting support.
Bad Gateway
The model could not be reached, or stopped before it finished answering. No partial answer is returned in its place, and nothing is billed for it. Retrying is reasonable. An image or video URL in the request whose host cannot be reached, times out or answers with a server error is also answered this way.
Service Overloaded (503)
Too many large requests are already being handled at once. This applies only
to a request above a size threshold, or one sent with chunked transfer
encoding. An ordinary-sized request is never refused this way. Always retry
using the Retry-After header, not a fixed delay, to avoid a synchronized
retry storm. For sustained traffic in media, keep individual requests small:
pass large media in a JSON body as a remote HTTP or HTTPS URL rather than
inline base64, and keep a file upload small, for example by sending audio in
a compressed format such as MP3 or Opus. The message gives the advice that
fits how the request was sent.
Gateway Timeout
The model did not answer within the time allowed for it. The request may
have reached the model and may even have been served, so a retry is only safe for
idempotent calls. Retrying the same request unchanged tends to time out again: the
work itself is usually what was too slow, so prefer a smaller request (fewer or
smaller images, a shorter prompt, a lower n) or a model that can serve it.
Capacity Exhausted (529)
The service is temporarily overloaded. This is a non-standard status,
matching the convention used by other LLM providers for the same
condition: capacity is exhausted, not a client error (429) and not an
outage (503). error.code distinguishes a per-user throttle
(user_overloaded) from a system-wide capacity shortage
(server_overloaded). If you check only the status, treat both
alike. Always retry using the Retry-After header, not a
fixed delay, to avoid a synchronized retry storm.
POST /v1/chat/completions HTTP/1.1
Host: openai.inference.de-txl.ionos.com
Authorization: Bearer YOUR_SECRET_TOKEN
Content-Type: application/json
Accept: */*
Content-Length: 127
{
"model": "openai/gpt-oss-120b",
"messages": [
{
"role": "user",
"content": "Hello, how are you?"
}
],
"max_tokens": 256,
"temperature": 0.7
}{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "openai/gpt-oss-120b",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "I'm doing well, thank you!"
},
"finish_reason": "stop",
"logprobs": null
}
],
"usage": {
"prompt_tokens": 13,
"completion_tokens": 9,
"total_tokens": 22
}
}Last updated
Was this helpful?