Skip to main content

Endpoint

Creates a completion for the chat conversation using the specified model.

Request

Headers

string
required
Must be application/json
string
required
The AI provider to use (e.g., openai, anthropic, google)
string
required
Your API key for the specified provider
string
Optional JSON config for routing, fallbacks, and guardrails

Body Parameters

string
required
The model to use for completion (e.g., gpt-4o-mini, claude-3-5-sonnet-20241022)
array
required
Array of message objects with role and content
number
default:1
Sampling temperature between 0 and 2. Higher values make output more random.
integer
Maximum number of tokens to generate
number
default:1
Nucleus sampling parameter. Alternative to temperature.
boolean
default:false
Whether to stream the response
string | array
Up to 4 sequences where the API will stop generating
number
default:0
Penalty for token presence (-2.0 to 2.0)
number
default:0
Penalty for token frequency (-2.0 to 2.0)
integer
default:1
Number of completions to generate
string
Unique identifier for the end-user
array
List of tools the model can call
string | object
Controls which tool the model should use
object
Format of the response (e.g., {"type": "json_object"})
integer
Seed for deterministic sampling

Response

string
Unique identifier for the completion
string
Object type, always chat.completion
integer
Unix timestamp of creation
string
The model used for completion
array
Array of completion choices
integer
Choice index
object
The generated message
string
Role of the message author (always assistant)
string
The message content
array
Tool calls made by the model
string
Reason for completion: stop, length, tool_calls, or content_filter
object
Token usage information
integer
Number of tokens in the prompt
integer
Number of tokens in the completion
integer
Total tokens used

Examples

Basic Request

Response

Using Python SDK

Using JavaScript SDK

With Function Calling

With JSON Mode