Chat Completions
Use the OpenAI-compatible Chat Completions endpoint for message-based text generation.
Basic request
A non-streaming response contains generated content under:
Token usage, when reported by the model, is returned in the usage object.
Python
Node.js / TypeScript
Message roles
The API schema supports these roles:
Common request fields
Do not send optional fields unless your selected model supports them.
Multimodal input
The message content schema supports typed content parts such as text, image URLs, input audio, files, and video URLs. Availability depends on the model.
Example image input:
Tool calling
When a compatible model returns tool_calls, execute the requested function in your application and append a tool message with the matching tool_call_id. Tool support and exact behavior are model-dependent.
Streaming
Set stream to true and read text from each chunk's choices[0].delta.content. See Streaming for complete examples.
Errors
400— invalid request fields or unsupported values401— missing or invalid API key429— rate limit, quota, or capacity restriction- Model errors — incorrect model ID or endpoint mismatch
