APIRail API documentation
APIRail serves OpenAI-compatible, Anthropic-compatible and native Gemini endpoints behind one API key. This page covers what you need to send a first request and to run your existing tools against APIRail.
Quickstart
- Sign in with Google and open Dashboard → API keys.
- Create a key. The full key, starting with
ar-live-, is shown once; store it somewhere safe. - Top up at least $20 under Dashboard → Billing.
- Send a request:
curl https://api.apirail.dev/v1/chat/completions \
-H "Authorization: Bearer ar-live-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}'Authentication
Send your key in any of these headers. All three work on every endpoint.
Authorization: Bearer ar-live-… | OpenAI style |
x-api-key: ar-live-… | Anthropic style |
x-goog-api-key: ar-live-… | Gemini style |
Gemini routes also accept the key as a ?key= query parameter. A missing, wrong or disabled key returns 401 invalid_api_key.
Base URLs
Use the base URL that matches the SDK or tool you are configuring.
| API | Base URL |
|---|---|
| OpenAI-compatible | https://api.apirail.dev/v1 |
| Anthropic-compatible | https://api.apirail.dev |
| Gemini native | https://api.apirail.dev/v1beta |
Chat Completions
POST /v1/chat/completions accepts the OpenAI Chat Completions request body. Every text model in the catalog can be called here, including Claude and Gemini models.
curl https://api.apirail.dev/v1/chat/completions \
-H "Authorization: Bearer ar-live-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.2-sol",
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}'Responses
POST /v1/responses accepts the OpenAI Responses request body and is available for GPT text models.
curl https://api.apirail.dev/v1/responses \
-H "Authorization: Bearer ar-live-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-6.2-sol",
"input": "Say hello in one sentence."
}'Anthropic Messages
POST /v1/messages accepts the Anthropic Messages request body, and POST /v1/messages/count_tokens counts tokens without generating. Available for Claude models and GPT text models.
curl https://api.apirail.dev/v1/messages \
-H "x-api-key: ar-live-YOUR_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Say hello in one sentence."}]
}'Gemini
POST /v1beta/models/{model}:generateContent and :streamGenerateContent accept native Gemini request bodies for Gemini models.
curl "https://api.apirail.dev/v1beta/models/gemini-3.8-flash:generateContent" \
-H "x-goog-api-key: ar-live-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"contents": [{"parts": [{"text": "Say hello in one sentence."}]}]}'Images
POST /v1/images/generations generates images with GPT Image models. Each generated image is billed at the per-image price on the pricing page. Video generation is not available.
curl https://api.apirail.dev/v1/images/generations \
-H "Authorization: Bearer ar-live-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A lighthouse on a rocky coast at dusk, watercolor",
"size": "1024x1024",
"n": 1
}'Streaming
Set "stream": true, or call :streamGenerateContent?alt=sse for Gemini, to receive server-sent events.
Chat Completions streams include token usage in the last chunk, so that final chunk can have an empty choices array. Check for it before reading choices[0].
While a long request waits for its first token, APIRail sends SSE comment lines (: keep-alive) to keep the connection open. Standard SSE clients ignore them.
: keep-alive
data: {"choices":[{"index":0,"delta":{"content":"Hello"}}]}
data: {"choices":[{"index":0,"delta":{"content":" there."}}]}
data: {"choices":[],"usage":{"prompt_tokens":14,"completion_tokens":3}}
data: [DONE]Claude Code
Set two environment variables and start Claude Code as usual. Requests then go to APIRail and are billed to that key.
export ANTHROPIC_BASE_URL=https://api.apirail.dev
export ANTHROPIC_AUTH_TOKEN=ar-live-YOUR_KEY
claude --model claude-sonnet-5-5Codex CLI
Codex CLI uses the Responses API, so any GPT text model works.
export OPENAI_BASE_URL=https://api.apirail.dev/v1
export OPENAI_API_KEY=ar-live-YOUR_KEY
codex --model gpt-6.2-solCursor and Cline
Use the OpenAI-compatible base URL and enter the model ID exactly as it appears in the catalog.
# Cursor: Settings → Models → API Keys
OpenAI API Key: ar-live-YOUR_KEY
Override OpenAI Base URL: https://api.apirail.dev/v1
Custom model: claude-sonnet-5-5
# Cline: API Provider → OpenAI Compatible
Base URL: https://api.apirail.dev/v1
API Key: ar-live-YOUR_KEY
Model ID: claude-sonnet-5-5Errors
Errors use the format of the API you called: an OpenAI error object, an Anthropic error event or a Gemini error.
| Status | Code | Meaning |
|---|---|---|
| 401 | invalid_api_key | The key is missing, wrong or disabled. |
| 402 | insufficient_quota | Your balance is too low for this request. Top up to continue. |
| 403 | model_not_allowed | The key's allowed-models list does not include this model. |
| 404 | model_not_found | The model ID does not exist in the catalog. |
| 429 | monthly_limit_exceeded | The key has reached its monthly spending limit. |
| 429 | rate_limited | The model is busy. Retry after a short wait. |
| 502 | provider error | The model provider returned an error. You are not charged. |
| 503 | model_unavailable | The model is temporarily unavailable. Try again later. |
Billing and limits
Text requests are billed per token at 30% of list price, with cached input at the cached rate; images are billed per image. The cost is rounded up to the nearest micro-dollar and recorded in Dashboard → Usage.
A request is refused with 402 when your balance is too low, and with 429 monthly_limit_exceeded when the key's monthly limit is reached. Each account can have up to 20 keys.
List models
GET /v1/models returns the model IDs your key can use in OpenAI list format; GET /v1beta/models returns the Gemini models in Gemini format.
curl https://api.apirail.dev/v1/models \
-H "Authorization: Bearer ar-live-YOUR_KEY"