Basic request
Send a list ofmessages. Each message has a role (system, user, or assistant) and content.
Common parameters
Supported parameters vary by model. Unsupported fields are safely ignored
rather than rejected.
Multi-turn conversations
The API is stateless, so it doesn’t remember previous calls. To continue a conversation, send the full message history each time and append the model’s previous reply as anassistant message:
Image input
Vision-capable models accept images alongside text. Send the messagecontent as an array of parts: a text part and an image_url part, where the image is a URL or a base64 data: URI.
Streaming
Set"stream": true to receive the response incrementally as Server-Sent Events (SSE) instead of waiting for the full completion. This is ideal for chat UIs that render tokens as they arrive. Image requests can stream too; see Image generation.
data: line with a partial chunk; tokens arrive in choices[0].delta.content. The final chunk carries a usage object with cost, and the stream ends with a data: [DONE] sentinel:
Next steps
Tool calling
Let the model call your functions.
Reasoning
Use models that think before they answer.
Structured outputs
Force responses that match a JSON schema.