API reference

Base URL: https://elevenrouter.com/api/v1. All responses are JSON; streaming responses are Server-Sent Events.

View as Markdown

POST /chat/completions

OpenAI-compatible chat completion. Requires Authorization: Bearer sk-er-v1-….

modelstring, required
Canonical slug (anthropic/claude-sonnet-5) or accepted alias. Append :nitro to prefer throughput or :floor to prefer price (see Routing).
messagesarray, required
system, developer, user, assistant and tool messages. Content may be a string or an array of text / image_url / file parts. Text parts and messages accept cache_control: { type: "ephemeral", ttl?: "5m" | "1h" } to place prompt-cache breakpoints (Anthropic semantics; passed through where supported).
streamboolean
Stream Server-Sent Events. The final chunk carries `usage` (and `cost` when requested) before data: [DONE].
max_tokens / max_completion_tokensinteger
Cap on output tokens. Defaults to a model-specific value when the provider requires one.
temperature, top_p, top_k, stop, seed, frequency_penalty, presence_penalty, repetition_penalty, min_psampling
Forwarded when the model supports the parameter; silently dropped otherwise.
tools, tool_choice, parallel_tool_callstools
OpenAI function-calling schema. Translated for Anthropic-native providers.
response_formatobject
text, json_object or json_schema (models advertising structured_outputs).
reasoningobject
{ effort: minimal|low|medium|high|xhigh, max_tokens, exclude }. Mapped to reasoning_effort or extended thinking per vendor.
modelsstring[]
ElevenRouter extension: ordered fallback models tried when the primary has no available endpoint.
providerobject
ElevenRouter extension: { order, only, ignore, allow_fallbacks, sort }. See Routing.
usage.includeboolean
ElevenRouter extension: adds `cost` (USD) to the usage object.

Response headers: x-er-generation-id, x-er-provider (the model's vendor, e.g. Anthropic), x-er-model, x-ratelimit-limit, x-ratelimit-remaining, x-request-id.

Request headers understood on every inference endpoint: X-ER-Session-Id (or body session_id) groups requests into a conversation for per-session cost; X-ER-User-Id (or the OpenAI user field) tags your end user; X-ER-Metadata: enabled adds the route receipt below.

Route receipt (X-ER-Metadata)

Send X-ER-Metadata: enabled and every response carries an elevenrouter_metadata object: how the request was routed and what it cost, to the cent. On streams it rides on the final usage chunk (Responses: on the response.completed object; Messages: on message_delta). On errors where routing already happened (502, 503) it is placed under error.metadata.elevenrouter_metadata. Attempts name the model's vendor and a classified reason; there is nothing to parse and nothing vendor-specific.

"elevenrouter_metadata": {
  "generation_id": "gen-Qm3bHk9ZP2xT7Y1L",
  "requested_model": "anthropic/claude-sonnet-5:nitro",
  "model": "anthropic/claude-sonnet-5",
  "vendor": "Anthropic",
  "routing": {
    "strategy": "expiry_first", "sort": "throughput",
    "eligible_endpoints": 3, "attempt": 2, "attempts": 2, "fallback_model": false,
    "fallbacks": [{ "vendor": "Anthropic", "outcome": "retryable_error", "reason": "rate_limited", "duration_ms": 118 }]
  },
  "timing_ms": { "routing": 9, "fallback": 118, "ttft": 640, "generation": 1210, "total": 1977 },
  "cost": {
    "currency": "USD", "prompt": 0.000063, "cache_read": 0.0000036, "cache_write": 0,
    "completion": 0.00057, "reasoning": 0, "request_fee": 0, "platform_fee": 0,
    "total": 0.0006366, "insured": false, "byok": false
  },
  "pricing": { "prompt_per_million": 3, "completion_per_million": 15, "cache_read_per_million": 0.3,
               "cache_write_per_million": 3.75, "reasoning_per_million": null, "request_fee": 0 }
}
routing.eligible_endpointsinteger
Endpoints that could serve the model for your request after credential, health and preference filtering.
routing.attempt / attemptsinteger
Which attempt produced the response (1-based) and how many were made. attempt is null when every attempt failed.
routing.fallbacks[].reasonstring
Classified failure of an earlier attempt: rate_limited, overloaded, upstream_error, timeout, network, model_access_denied, quota_exhausted, auth_invalid.
routing.fallback_modelboolean
True when a model from your models array served the request instead of the primary one.
cost.*number (USD)
Split by token class at the official rates in pricing; total is what your balance was charged (0 when insured).
timing_ms.*integer
routing = before the first upstream call; fallback = time lost to failed attempts; ttft = time to first token; generation = ttft → last token.

POST /messages

Anthropic Messages-compatible endpoint. Point the Anthropic SDK at https://elevenrouter.com/api/v1 with your ElevenRouter key as x-api-key (or Authorization: Bearer) and use any model in the catalog, not only Claude. Requests are normalised internally and routed exactly like chat completions; responses, streaming events (message_start message_stop) and errors use Anthropic's shapes. Supports system (string or blocks with cache_control), text / image / document blocks, tools, tool_choice, thinking, stop_sequences, metadata.user_id and the ElevenRouter models / provider extensions.

curl https://elevenrouter.com/api/v1/messages \
  -H "x-api-key: $ELEVENROUTER_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "openai/gpt-5.6-luna",
    "max_tokens": 256,
    "messages": [{ "role": "user", "content": "Hello" }]
  }'

Usage is reported as input_tokens, output_tokens, cache_read_input_tokens and cache_creation_input_tokens; cost is added when the request includes usage.include. Errors come back as { "type": "error", "error": { "type", "message" } }.

POST /responses

OpenAI Responses API dialect. Accepts input as a string or an item list (messages, function_call, function_call_output), instructions, max_output_tokens, function tools, tool_choice, reasoning.effort, text.format (JSON schema) and text.verbosity. Streaming emits response.created, response.output_text.delta, response.function_call_arguments.delta and finishes with response.completed (or response.incomplete when truncated). Server-side conversation state (previous_response_id) and hosted tools are not supported; send the full conversation each time.

{
  "id": "resp_Qm3bHk9ZP2xT7Y1L", "object": "response", "status": "completed",
  "model": "openai/gpt-5.6-luna", "provider": "OpenAI",
  "output": [{ "id": "msg_…", "type": "message", "role": "assistant", "status": "completed",
               "content": [{ "type": "output_text", "text": "Hello!", "annotations": [] }] }],
  "output_text": "Hello!",
  "usage": { "input_tokens": 8, "output_tokens": 2, "total_tokens": 10,
             "input_tokens_details": { "cached_tokens": 0 }, "output_tokens_details": { "reasoning_tokens": 0 } }
}

POST /completions

Legacy text completions. prompt (string or string[]) becomes a single user message; the reply is returned as choices[].text with object: "text_completion". Streams end with data: [DONE].

POST /embeddings

OpenAI-compatible embeddings. input is a string, an array of strings, or token arrays; dimensions and encoding_format are forwarded. Embedding models appear in GET /models with modality text->embedding and are billed on input tokens only at the official rate. Fallback models, provider preferences and usage.include work as for chat.

curl https://elevenrouter.com/api/v1/embeddings \
  -H "Authorization: Bearer $ELEVENROUTER_API_KEY" \
  -H "content-type: application/json" \
  -d '{ "model": "openai/text-embedding-3-small", "input": ["hello", "world"], "usage": { "include": true } }'

GET /models

Public. Lists active models with official per-token pricing (decimal strings, USD per token), context length, supported parameters and the number of live endpoints.

{
  "object": "list",
  "data": [{
    "id": "anthropic/claude-haiku-4.5",
    "name": "Anthropic: Claude Haiku 4.5",
    "context_length": 200000,
    "pricing": { "prompt": "0.000001", "completion": "0.000005", "input_cache_read": "0.0000001", "input_cache_write": "0.00000125", "request": "0", "image": "0" },
    "top_provider": { "context_length": 200000, "max_completion_tokens": 64000, "is_moderated": false },
    "supported_parameters": ["max_tokens", "temperature", "tools", "reasoning", "..."],
    "endpoints_available": 1
  }]
}

GET /auth/key

Information about the calling key: label, spend limit, usage, remaining limit and rate limit.

GET /credits

Total credits purchased or granted and total usage for the organization that owns the key.

GET /generation?id=gen-…

Metadata for one request: model, provider, status, finish reason, prompt / completion / cached / reasoning tokens, total cost, latency and generation time.

{
  "data": {
    "id": "gen-Qm3bHk9ZP2xT7Y1L", "model": "anthropic/claude-sonnet-5", "provider_name": "Anthropic",
    "status": "succeeded", "streamed": true, "finish_reason": "stop",
    "tokens_prompt": 21, "tokens_completion": 38, "native_tokens_cached": 0, "native_tokens_reasoning": 0,
    "total_cost": 0.000422, "latency": 812, "generation_time": 1460, "created_at": "2026-09-14T18:42:11.204Z"
  }
}