Frameworks & coding agents

ElevenRouter speaks the OpenAI and Anthropic wire formats, so almost every framework works by changing a base URL. Recipes below, plus environment-variable setups for coding agents and the MCP server.

View as Markdown

OpenAI SDKs (any language)

import OpenAI from 'openai';
const client = new OpenAI({ baseURL: 'https://elevenrouter.com/api/v1', apiKey: process.env.ELEVENROUTER_API_KEY });
// Use any catalog model id. ElevenRouter extensions (models, provider, transforms) pass through as extra body fields.

Anthropic SDKs

import anthropic
client = anthropic.Anthropic(base_url="https://elevenrouter.com/api/v1", api_key=os.environ["ELEVENROUTER_API_KEY"])
msg = client.messages.create(model="openai/gpt-5.6-terra", max_tokens=300, messages=[{"role": "user", "content": "Hi"}])

POST /messages accepts the Anthropic format for every model in the catalog — including non-Anthropic ones — and translates tools, system prompts and streaming events.

Vercel AI SDK

import { createOpenAI } from '@ai-sdk/openai';
import { streamText } from 'ai';

const elevenrouter = createOpenAI({ baseURL: 'https://elevenrouter.com/api/v1', apiKey: process.env.ELEVENROUTER_API_KEY, name: 'elevenrouter' });

const result = streamText({
  model: elevenrouter.chat('anthropic/claude-sonnet-5'),
  prompt: 'Write a product description for a mechanical keyboard.',
  providerOptions: { openai: { models: ['openai/gpt-5.6-terra'] } }, // fallback, forwarded as an extra field
});

LangChain / LangGraph

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="anthropic/claude-sonnet-5",
    base_url="https://elevenrouter.com/api/v1",
    api_key=os.environ["ELEVENROUTER_API_KEY"],
    default_headers={"X-Title": "my-agent", "X-ER-Metadata": "enabled"},
    model_kwargs={"models": ["openai/gpt-5.6-terra"]},
)

LiteLLM

import litellm
response = litellm.completion(
    model="openai/anthropic/claude-sonnet-5",   # "openai/" selects the OpenAI-compatible provider
    api_base="https://elevenrouter.com/api/v1",
    api_key=os.environ["ELEVENROUTER_API_KEY"],
    messages=[{"role": "user", "content": "Hello"}],
)

PydanticAI

from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider

model = OpenAIChatModel("openai/gpt-5.6-terra", provider=OpenAIProvider(base_url="https://elevenrouter.com/api/v1", api_key=os.environ["ELEVENROUTER_API_KEY"]))
agent = Agent(model, instructions="Be concise.")

Coding agents

Most agents read the OpenAI or Anthropic environment variables. Point them at ElevenRouter and pick any catalog model; budgets, guardrails and logs apply exactly as for your own apps. Create a dedicated key per agent so spend is attributable.

# Claude Code (Anthropic format)
export ANTHROPIC_BASE_URL=https://elevenrouter.com/api/v1
export ANTHROPIC_AUTH_TOKEN=$ELEVENROUTER_API_KEY
export ANTHROPIC_MODEL=anthropic/claude-sonnet-5

# Codex CLI (OpenAI format)
export OPENAI_BASE_URL=https://elevenrouter.com/api/v1
export OPENAI_API_KEY=$ELEVENROUTER_API_KEY
codex --model openai/gpt-5.6-terra

# Cline / Roo Code: choose "OpenAI Compatible", base URL https://elevenrouter.com/api/v1, model id from the catalog.
# Cursor: use the dedicated Cursor service (Services → Cursor in the dashboard), not this base URL.
# See /docs/tools/cursor.

Cursor is special: its base-URL override sends a dialect of its own (Responses-style fields, flat and grammar tools) and needs neutral model names. ElevenRouter ships a dedicated Cursor service with its own endpoint, key and plans built for it.

MCP server

@elevenrouter/mcp gives agents tools to search the catalog by capability and price, look up official prices with cost estimates, check platform status, debug a request by generation id and summarise spend (management key). It speaks stdio JSON-RPC and needs nothing but Node.

# Claude Code
claude mcp add elevenrouter -e ELEVENROUTER_API_KEY=sk-er-v1-… -- npx -y @elevenrouter/mcp

# Cursor / Cline / Windsurf (mcpServers)
{
  "mcpServers": {
    "elevenrouter": { "command": "npx", "args": ["-y", "@elevenrouter/mcp"], "env": { "ELEVENROUTER_API_KEY": "sk-er-v1-…" } }
  }
}

Agents can also read this documentation directly: every page is available as Markdown (see llms.txt), and the OpenAPI document describes every endpoint.