Authentication

All API requests require authentication via an API key.

Bearer Token

For the /v1/chat/completions, /v1/models, /v1/embeddings, /v1beta/models/{model}:generateContent, and /v1beta/models/{model}:streamGenerateContent endpoints, authenticate using the Authorization: Bearer header.

Authorization: Bearer rh_your_api_key_here

Anthropic-style Auth

For the /v1/messages endpoint, authenticate using the x-api-key header. The standard Bearer token also works on this endpoint.

x-api-key: rh_your_api_key_here

Google-style Auth

For the /v1beta/models/{model}:generateContent and :streamGenerateContent endpoints, you can also authenticate using the x-goog-api-key header. The standard Bearer token also works on these endpoints.

x-goog-api-key: rh_your_api_key_here

Required Headers

Each endpoint requires specific headers for authentication and content negotiation.

Endpoint Required Headers
POST /v1/chat/completions Authorization, Content-Type: application/json
POST /v1/messages x-api-key, anthropic-version: 2023-06-01, Content-Type: application/json
GET /v1/models Authorization
POST /v1/embeddings Authorization, Content-Type: application/json
POST /v1beta/models/{model}:generateContent Authorization or x-goog-api-key, Content-Type: application/json
POST /v1beta/models/{model}:streamGenerateContent Authorization or x-goog-api-key, Content-Type: application/json

SDK Configuration

Configure your preferred SDK or HTTP client to authenticate with RouterHub.

curl https://api.routerhub.ai/v1/chat/completions \
  -H "Authorization: Bearer $ROUTERHUB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "anthropic/claude-sonnet-4", "messages": [{"role": "user", "content": "Hi"}]}'
from openai import OpenAI

client = OpenAI(
    base_url="https://api.routerhub.ai/v1",
    api_key="YOUR_API_KEY",
)
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.routerhub.ai",
    api_key="YOUR_API_KEY",
)
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    base_url="https://api.routerhub.ai/v1",
    api_key="YOUR_API_KEY",
    model="anthropic/claude-sonnet-4",
)

Rate Limiting

RouterHub enforces cascading rate limits at three levels: api_key, project, and organization.

Rate limits are applied per API key, with optional overrides at the project and organization level.

Error Responses

Authentication and rate limiting errors are returned in standard OpenAI error format.

401 Unauthorized

{
  "error": {
    "message": "Invalid API key",
    "type": "invalid_request_error",
    "code": "invalid_api_key"
  }
}

429 Rate Limited

{
  "error": {
    "message": "Rate limit exceeded",
    "type": "rate_limit_error",
    "code": "rate_limit_exceeded"
  }
}

503 Service Unavailable

{
  "error": {
    "message": "Auth service temporarily unavailable",
    "type": "server_error",
    "code": "service_unavailable"
  }
}