Chat Completions API
Endpoint
POST /v1/chat/completions
Request Body
{
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
],
"temperature": 0.7,
"max_tokens": 1000
}
Response
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "The capital of France is Paris."},
"finish_reason": "stop"
}
],
"usage": {"prompt_tokens": 20, "completion_tokens": 8, "total_tokens": 28}
}
Streaming
Set stream: true for server-sent events.