Chat completions
The main endpoint and its parameters.
Request
POST /v1/chat/completions with a JSON body. It is the OpenAI shape; unknown fields are ignored.
| Parameter | Type | Description |
|---|---|---|
model | string, required | A model id from /v1/models, or auto. |
messages | list, required | Messages with the role system, developer, user or assistant. |
max_tokens / max_completion_tokens | integer | Cap on the answer length. |
temperature | number, 0 to 2 | How creative the answer is. |
stream | boolean | Send the answer in chunks. |
stream_options.include_usage | boolean | In a stream, also send usage. |
A message's content can be plain text or a list of text and image_url parts. Only a model with supports_vision accepts an image.
resp = client.chat.completions.create( model="MODEL_ID", messages=[ {"role": "system", "content": "Answer briefly."}, {"role": "user", "content": "What is a token?"}, ], max_tokens=300, temperature=0.4,)print(resp.choices[0].message.content)print(resp.usage)
Response
Normally a chat.completion object with choices and usage comes back. Every response, errors included, carries an x-request-id header; send it if you write to support.
Request size
The request body is at most 40 MB; larger gets 413 with request_too_large. Input longer than the model allows is 422 with context_length_exceeded.
See the endpoint reference for every parameter and response.
Did this page not help? Tell us.