Sign In
API Docs

API Reference

Call model services with request formats compatible with each model provider's official API.

30
Model API endpoints
8
Categories
API Key
Authentication

API Reference

Use this section after your first request works, or when you need provider-specific endpoint details.

30 Model API endpoints
POSTOpenAIOpenAI/chat/completions

Create Chat Completion

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

Authentication

Use your API-Key with 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. The CostRouter selects an available channel by model name and forwards 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 upstream model.
response_formatobjectNoStructured response format. Support depends on the upstream model.
Response Example
NameTypeRequiredDescription
idstringNoResponse, task, or resource ID.
objectstringNoResponse object type.
createdintegerNoCreation timestamp.
modelstringNo-
choicesarray<object>NoCandidate model outputs.
usageobjectNoToken usage statistics.

Core concepts

These are the pieces new users usually need to understand before debugging an integration.

API-Key: your CostRouter key authenticates requests to every supported model.
Base URL: replace the provider URL with the CostRouter relay URL.
Model name: keep the requested model in the payload; CostRouter selects an available channel.
Usage and billing: costs appear in Usage Logs and Billing after requests complete.

Choosing a model

Use these defaults when you are not sure which endpoint to start with.

General chat: start with gpt-4o-mini or another low-cost chat model.
Reasoning or coding: choose a stronger model only after you confirm the basic request works.
Images, audio, and video: use the matching endpoint category in API Reference.
Price checks: open Models before production traffic to compare groups and rates.

Common errors and fixes

Most first-run failures are caused by authentication, model names, quota, or request shape.

401

Authentication failed

Check that Authorization uses Bearer plus your CostRouter API-Key.

403

No access or balance

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

429

Rate limited

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

5xx

Upstream or routing failure

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

Contact us

Choose the channel that best matches your request.

Contact us
API Docs - CostRouter