Hoveydai

Chat completions

The main endpoint and its parameters.

Reading time: 1 min

Request

POST /v1/chat/completions with a JSON body. It is the OpenAI shape; unknown fields are ignored.

ParameterTypeDescription
modelstring, requiredA model id from /v1/models, or auto.
messageslist, requiredMessages with the role system, developer, user or assistant.
max_tokens / max_completion_tokensintegerCap on the answer length.
temperaturenumber, 0 to 2How creative the answer is.
streambooleanSend the answer in chunks.
stream_options.include_usagebooleanIn 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.