Create a chat completion

Create a model response from the conversation history. Supports streaming and non-streaming responses. Compatible with the OpenAI Chat Completions API.

POST /v1/chat/completions

Service root: https://getrouter.ai

Protocol: OpenAI Chat Completions

Authentication: Authorization: Bearer YOUR_API_KEY

Request body

The request body is required. Media type: application/json

Request fields

FieldTypeRequiredDescription
modelstringYesModel ID
messagesarray<object>YesList of conversation messages
temperaturenumberNoSampling temperature Default: 1; Range: 0–2
top_pnumberNoNucleus sampling parameter Default: 1; Range: 0–1
nintegerNoNumber of generations Default: 1; Range: 1–∞
streambooleanNoWhether to stream the response Default: false
stream_optionsobjectNo
stopstring or array<string>NoStop sequence
max_tokensintegerNoMaximum number of generated tokens
max_completion_tokensintegerNoMaximum number of completion tokens
presence_penaltynumberNoDefault: 0; Range: -2–2
frequency_penaltynumberNoDefault: 0; Range: -2–2
logit_biasobjectNo
userstringNo
toolsarray<object>No
tool_choicestring or objectNo
response_formatobjectNo
seedintegerNo
reasoning_effortstringNoReasoning effort (for models that support reasoning) Allowed values: low, medium, high
modalitiesarray<string>No
audioobjectNo

Example request

curl --request POST \
  --url https://getrouter.ai/v1/chat/completions \
  --header "Authorization: Bearer YOUR_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "MODEL_ID",
  "messages": [
    {
      "role": "system",
      "content": "Hello, introduce yourself."
    }
  ],
  "stream": false,
  "temperature": 1,
  "max_tokens": 1
}'

Responses

StatusDescription
200Response created successfully
400Invalid request parameters
429Rate limit exceeded

Success response fields

FieldTypeRequiredDescription
idstringNo
objectstringNo
createdintegerNo
modelstringNo
choicesarray<object>No
usageobjectNo
system_fingerprintstringNo

Example response

{
  "id": "string",
  "object": "object",
  "created": 1,
  "model": "MODEL_ID",
  "choices": [
    {
      "index": 1,
      "message": {
        "role": "system",
        "content": "Hello, introduce yourself.",
        "name": "string",
        "tool_calls": [
          {
            "id": null,
            "type": null,
            "function": null
          }
        ],
        "tool_call_id": "string",
        "reasoning_content": "string"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 1,
    "completion_tokens": 1,
    "total_tokens": 1,
    "prompt_tokens_details": {
      "cached_tokens": 1,
      "text_tokens": 1,
      "audio_tokens": 1,
      "image_tokens": 1
    },
    "completion_tokens_details": {
      "text_tokens": 1,
      "audio_tokens": 1,
      "reasoning_tokens": 1
    }
  },
  "system_fingerprint": "string"
}

For complete workflows and examples, read the Chat Completions API Guide.


This page is generated from the public Relay OpenAPI specification. Browse the complete specification in the API Explorer.