Use router in the apps you already know
Connect coding tools, agents and chat apps with a base URL, an API key and a model ID. Use Chat Completions, stateless Responses or Anthropic-compatible Messages.
SDKs and frameworks#
Router accepts familiar API shapes. Start with the compatible base URL for your client and an active key from your workspace.
https://your-router-domain/v1The Messages base URL is the site origin without /v1. Find current model identifiers in the catalog.
curl 'https://your-router-domain/v1/chat/completions' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "deepseek-v4-flash",
"messages": [
{
"role": "user",
"content": "Hello!"
}
],
"max_tokens": 128
}'OpenAI Node#
JavaScript SDK · Chat CompletionsUse the OpenAI JavaScript SDK with your router endpoint.
- Install openai in your own server-side application.
- Set ROUTER_API_KEY to the full key saved at creation.
- Set baseURL to the /v1 URL and choose an exact catalog model ID.
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.ROUTER_API_KEY,
baseURL: "https://your-router-domain/v1",
});
const response = await client.chat.completions.create({
model: "deepseek-v4-flash",
messages: [{ role: 'user', content: 'Hello' }],
max_tokens: 128,
});
console.log(response.choices[0].message.content);OpenAI Python#
Python SDK · Chat CompletionsUse the OpenAI Python SDK with a custom base_url.
- Install openai in your Python environment.
- Set ROUTER_API_KEY without committing it to source control.
- Pass the /v1 base_url and exact model ID to the client.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ['ROUTER_API_KEY'],
base_url="https://your-router-domain/v1",
)
response = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{'role': 'user', 'content': 'Hello'}],
max_tokens=128,
)
print(response.choices[0].message.content)Vercel AI SDK#
AI framework · Chat CompletionsUse the OpenAI-compatible provider and select its chat model explicitly.
- Install ai and @ai-sdk/openai-compatible in your application.
- Create a provider with name, baseURL and your server-side API key.
- Pass router.chatModel(modelId) to generateText.
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from 'ai';
const router = createOpenAICompatible({
name: 'router',
baseURL: "https://your-router-domain/v1",
apiKey: process.env.ROUTER_API_KEY,
});
const { text } = await generateText({
model: router.chatModel("deepseek-v4-flash"),
prompt: 'Hello',
maxOutputTokens: 128,
});
console.log(text);LangChain#
Agent framework · Chat CompletionsConfigure ChatOpenAI for the compatible Chat endpoint.
- Install @langchain/openai and @langchain/core in your application.
- Set configuration.baseURL and apiKey, and leave useResponsesApi false.
- Invoke the model with ordinary messages; run client-side tools in your application.
import { ChatOpenAI } from '@langchain/openai';
const model = new ChatOpenAI({
model: "deepseek-v4-flash",
apiKey: process.env.ROUTER_API_KEY,
configuration: { baseURL: "https://your-router-domain/v1" },
useResponsesApi: false,
maxTokens: 128,
});
const response = await model.invoke('Hello');
console.log(response.content);Codex#
Responses APIAdd router as a model provider and use the Responses wire format.
- Set ROUTER_API_KEY in your shell environment.
- Add the provider configuration to ~/.codex/config.toml.
- Use an exact model ID from the catalog, then start Codex.
model = "deepseek-v4-flash"
model_provider = "router"
[model_providers.router]
name = "router"
base_url = "https://your-router-domain/v1"
wire_api = "responses"
env_key = "ROUTER_API_KEY"Claude Code#
Anthropic MessagesPoint Claude Code at the Messages-compatible endpoint with environment variables.
- Create an API key in your workspace.
- Set the base URL, API key and exact model identifier.
- Start Claude Code from the same shell.
export ANTHROPIC_BASE_URL="https://your-router-domain"
export ANTHROPIC_API_KEY="YOUR_API_KEY"
export ANTHROPIC_MODEL="deepseek-v4-flash"
claudeOpenClaw#
OpenAI-compatibleRegister router as a custom model provider for your agent.
- Add a router provider to your OpenClaw configuration.
- Set ROUTER_API_KEY in your environment.
- Select router/model-id as the agent model.
{
"models": {
"providers": {
"router": {
"baseUrl": "https://your-router-domain/v1",
"apiKey": "${ROUTER_API_KEY}",
"api": "openai-completions",
"models": [
{
"id": "deepseek-v4-flash",
"name": "deepseek-v4-flash"
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "router/deepseek-v4-flash"
}
}
}
}Hermes Agent#
OpenAI-compatibleUse a custom OpenAI-compatible endpoint in the Hermes model setup.
- Run the model configuration command.
- Choose a custom endpoint and enter your router base URL.
- Supply your API key and exact model ID.
hermes model
# Select a custom OpenAI-compatible endpoint
# Base URL: https://your-router-domain/v1
# API key: YOUR_API_KEY
# Model: deepseek-v4-flashOpenCode#
OpenAI-compatibleConfigure an OpenAI-compatible provider in opencode.json.
- Set ROUTER_API_KEY in your environment.
- Add the router provider and model entry to your configuration.
- Select the configured router model in OpenCode.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"router": {
"npm": "@ai-sdk/openai-compatible",
"name": "router",
"options": {
"baseURL": "https://your-router-domain/v1",
"apiKey": "{env:ROUTER_API_KEY}"
},
"models": {
"deepseek-v4-flash": {
"name": "deepseek-v4-flash"
}
}
}
},
"model": "router/deepseek-v4-flash"
}OpenWork#
OpenAI-compatibleConnect the workspace to router using a custom provider.
- Open the provider configuration in your workspace.
- Choose an OpenAI-compatible provider.
- Enter your router base URL, API key and catalog model ID.
Provider: OpenAI Compatible
Base URL: https://your-router-domain/v1
API key: YOUR_API_KEY
Model: deepseek-v4-flashOpen WebUI#
OpenAI-compatibleAdd router as an OpenAI-compatible connection in the admin panel.
- Open Admin Panel → Settings → Connections.
- Add a new OpenAI API connection.
- Save the base URL and key, then select a model in chat.
Admin Panel → Settings → Connections → OpenAI API
URL: https://your-router-domain/v1
API key: YOUR_API_KEY
Model: deepseek-v4-flashCline#
OpenAI-compatibleUse Cline’s OpenAI Compatible provider option.
- Open Cline settings and select OpenAI Compatible.
- Enter the base URL and API key.
- Set Model ID to the exact model you want to use.
API Provider: OpenAI Compatible
Base URL: https://your-router-domain/v1
API Key: YOUR_API_KEY
Model ID: deepseek-v4-flashContinue#
OpenAI-compatibleAdd router to your Continue YAML model configuration.
- Store ROUTER_API_KEY using Continue’s secret configuration.
- Add an OpenAI provider entry with apiBase set to router.
- Reload the configuration and choose your model.
name: router
version: 1.0.0
schema: v1
models:
- name: deepseek-v4-flash
provider: openai
model: deepseek-v4-flash
apiBase: https://your-router-domain/v1
apiKey: ${{ secrets.ROUTER_API_KEY }}Cursor#
OpenAI-compatibleKeep the editor and override the OpenAI base URL in model settings.
- Open Settings → Models and add your OpenAI API key.
- Enable Override OpenAI Base URL and enter the router URL.
- Add the exact catalog model ID and verify the connection.
OpenAI API key: YOUR_API_KEY
Override OpenAI Base URL: https://your-router-domain/v1
Model: deepseek-v4-flashAider#
OpenAI-compatibleSet the OpenAI-compatible environment variables and select your model.
- Export your router base URL and API key.
- Start Aider with openai/ followed by the exact model ID.
- Check the model’s context and output limits before large changes.
export OPENAI_API_BASE="https://your-router-domain/v1"
export OPENAI_API_KEY="YOUR_API_KEY"
aider --model openai/deepseek-v4-flashLibreChat#
OpenAI-compatibleAdd router as a custom endpoint in librechat.yaml.
- Set ROUTER_API_KEY in the server environment.
- Add the custom endpoint configuration.
- Restart LibreChat and select router from the model menu.
endpoints:
custom:
- name: router
apiKey: ${ROUTER_API_KEY}
baseURL: https://your-router-domain/v1
models:
default: ["deepseek-v4-flash"]
fetch: trueVerify the connection#
ReferenceStart with an authenticated catalog read before running inference.
- Replace YOUR_API_KEY with your saved full key and run the catalog request below. It does not call a model.
- A 401 means authentication failed; a 403 can indicate missing permission or an IP restriction. Use a key with inference permission.
- For an end-to-end check, run one small text example with an exact available model and wallet credit, then inspect Requests. That inference is billable.
curl 'https://your-router-domain/v1/models' \
-H 'Authorization: Bearer YOUR_API_KEY'Prompt cache and long-session savings#
ReferenceKeep a compatible route preference and inspect actual supplier cache usage.
- API keys default to passthrough. Advanced key settings choose on, off or passthrough; x-ci-prompt-cache overrides the key for one request. off keeps customer cache_control and disables only the routing preference.
- on adds automatic cache_control only when you supplied no marker. Non-Claude models remain unchanged. Claude needs a native Messages candidate: the current verified catalog has one for claude-opus-4.8 only. Automatic markers use the five-minute default. Supported Chat/Responses to Messages conversions preserve 5m markers but reject explicit 1h with unsupported_conversion until supplier alias pricing is verified. Native same-protocol 1h behavior remains unchanged, with its pricing dimension not independently verified; other Claude models can be unavailable.
- Set x-ci-prompt-cache-scope to session, user or org. Session uses the key and a printable ASCII x-ci-prompt-cache-session label (1–256 characters, nonblank; omit for the key alone); user uses the responsible actor; org shares within the workspace or personal account. Never use a secret as the label.
- x-ci-prompt-cache-affinity new/hit/stale/miss describes a five-minute route hint for a cacheable prefix, not a supplier cache hit. Price, health, protocol and ZDR rules still apply; a different-route fallback is miss.
- In Requests, hit means positive reported cache reads, zero means an explicit zero read, and unknown means the supplier did not report reads. Writes are independent. Exact-response cache hits use not_applicable; pending requests have no settled cache state.
curl 'https://your-router-domain/v1/messages' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'anthropic-version: 2023-06-01' \
-H 'x-ci-prompt-cache: on' \
-H 'x-ci-prompt-cache-scope: session' \
-H 'x-ci-prompt-cache-session: example-session' \
-H 'Content-Type: application/json' \
-d '{
"model": "claude-opus-4.8",
"max_tokens": 128,
"system": "Keep reusable instructions and context here.",
"messages": [
{
"role": "user",
"content": "Summarize our task."
}
]
}'