OpenAI-Compatible AI API Documentation

Integrate multiple AI models through one gateway using familiar SDKs, one Base URL, and one API Key.

Open tutorial

API Reference

After your first successful request, use this section to review provider-specific request parameters and response formats.

30 Model API endpoints
POSTOpenAIOpenAI/chat/completions

Create Chat Completion

Creates a model response from conversation history with streaming, tools, and usage accounting.

Authentication

Send your CostRouter API Key as Authorization: Bearer sk-xxxx.

Authorization: Bearer sk-xxxx
Content Type
application/json
Model Examples
gpt-4o, gpt-4.1, gpt-5, o3, o4-mini

Request Example

{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "stream": false
}

Response Example

{
  "id": "chatcmpl_xxx",
  "object": "chat.completion",
  "created": 0,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello!"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 8,
    "completion_tokens": 3,
    "total_tokens": 11
  }
}

curl Example

curl -X POST 'https://costrouter.ai/v1/chat/completions' \
  -H 'Authorization: Bearer sk-xxxx'
  -H 'Content-Type: application/json'
  -d '{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "stream": false
}'
Parameters
NameTypeRequiredDescription
modelstringYesModel ID. CostRouter uses it to identify compatible, available routes for the request.
messagesarray<object>YesConversation message array, usually with system, user, assistant, or tool roles.
temperaturenumberNoSampling temperature. Higher values make output more random.
top_pnumberNoNucleus sampling parameter, usually adjusted instead of temperature.
streambooleanNoWhether to return a streaming response.
max_tokensintegerNoMaximum number of output tokens.
toolsarray<object>NoTool or function definitions. Support depends on the selected model.
response_formatobjectNoStructured response format. Support depends on the selected model.
Response Example
NameTypeRequiredDescription
idstringNoResponse, task, or resource ID.
objectstringNoResponse object type.
createdintegerNoCreation timestamp.
modelstringNo-
choicesarray<object>NoCandidate model outputs.
usageobjectNoToken usage statistics.

Common errors and fixes

Most first-request failures involve authentication, model IDs, account balance or spend limits, or invalid request parameters.

401

Authentication failed

Check that Authorization uses Bearer followed by your CostRouter API Key.

403

Access or balance issue

Check key status, account balance, model access, and billing settings.

429

Rate limited

Reduce concurrency, retry with backoff, or review account limits.

5xx

Provider or routing failure

Retry later, then inspect Usage Logs for the request status and selected model route.

Copyright 2026 CostRouter. All rights reserved.

CostRouter is prohibited for users located in mainland China. If use from mainland China is discovered, CostRouter may suspend or terminate the account, and any paid fees or remaining balance will not be refunded.

Contact us

Choose the channel that best matches your request.

Contact us
OpenAI-Compatible API Documentation | CostRouter