Create chat completion
POST/chat/completions
Creates a model response for the given conversation. Set stream: true to receive the response as a stream of server-sent events. The last chunk before data: [DONE] carries the usage object on every stream, whether or not stream_options.include_usage is set. An error after the stream has started (the API commits a stream that the model has not answered within 2 seconds, and keeps it alive with : ping comment lines) arrives as a final data: event whose JSON has an error member, the usual error object, followed by data: [DONE]; see the streaming guide.
Request
Responses
- 200
- 400
- 401
- 404
- 413
- 429
- 500
- 503
A chat completion. When stream is true the body is a text/event-stream of ChatCompletionChunk objects terminated by data: [DONE].
The request is malformed or a parameter is invalid. More images than the model reads, counted over the whole conversation (from 1 to 8 depending on the model: references.max in GET /v1/models), are refused with code: too_many_images and param: messages. Two function tools with the same name in tools (compared exactly, letter case included) are refused with param pointing at the second one, such as tools[1].function.name.
Missing or invalid API key.
The requested model does not exist or is not available to this key.
The request body is larger than the gateway accepts (4 MB).
Rate limit exceeded, or the service is temporarily at capacity for this model. Wait for the number of seconds in the Retry-After header before retrying.
Response Headers
Seconds to wait before retrying.
Unexpected server error: the model service returned an unexpected response (upstream_error), the request got no answer within 600 seconds (timeout), or an error in the gateway. Retry with backoff.
The model service is temporarily unavailable. Retry later and check the status page at https://status.serenityedge.ai.