Create a chat completion
Changed onSends a request for a model response for the given chat conversation. Supports both streaming and non-streaming modes.
Request
- Base URL: https://openrouter.ai/api/v1
- URL: https://openrouter.ai/api/v1/chat/completions
- Auth: HTTP bearer
Headers
Opt-in level for surfacing routing metadata on the response under openrouter_metadata.
Opt-in to surface routing metadata on the response under openrouter_metadata. Defaults to disabled. The legacy header X-OpenRouter-Experimental-Metadata is also accepted for backward compatibility.
Request body
Example request
{
"max_tokens": 150,
"messages": [
{
"content": "You are a helpful assistant.",
"role": "system"
},
{
"content": "What is the capital of France?",
"role": "user"
}
],
"model": "openai/gpt-4",
"temperature": 0.7
}Response
Successful chat completion response
Example response
{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "The capital of France is Paris.",
"role": "assistant"
}
}
],
"created": 1677652288,
"id": "chatcmpl-123",
"model": "openai/gpt-4",
"object": "chat.completion",
"system_fingerprint": "fp_44709d6fcb",
"usage": {
"completion_tokens": 15,
"prompt_tokens": 10,
"total_tokens": 25
}
}Changes
- info
added
armordiscriminator mapping keys to the/request property - info
added to the
/request propertyoneOflist - info
added the optional property
/to the response with the status (media type: text/event-stream) - info
added the optional property
to the response with the status (media type: application/json)
- info
- breaking
added the new required request property
//////// - breaking
added the new required request property
//////// - breaking
the
///////request property type changed fromstringtoobject - info
the
///////request property's minLength was decreased from1to0 - info
removed the pattern
^[^\n\r]*$from the request property/////// - info
added the optional property
to the response with the status (media type: application/json) - info
added the optional property
/to the response with the status (media type: text/event-stream)
- breaking