AI Agent Integration
Hand a coding agent the base URL, key and model ids it needs to wire AnyRouter into a project.
Paste the brief below into a coding agent (Claude Code, Cursor, Codex, Aider, Hermes) to add AnyRouter to an existing codebase. The change is a new base URL, key and model id.
| Setting | Value |
|---|---|
| Base URL | https://anyrouter.dev/api/v1 |
| Key | ANYROUTER_API_KEY (prefix sk-ar-, from the dashboard) |
| Default model | z-ai/glm-4.7-flash |
| Cheap / fast | openai/gpt-5.4-nano, anthropic/claude-haiku-4-5 |
| High quality | anthropic/claude-sonnet-4-6, openai/gpt-5.4 |
| Endpoints | POST /chat/completions, POST /messages (Anthropic-native), POST /responses |
Steps
-
Paste this prompt into your agent:
Integrate AnyRouter as the LLM provider for this project. API: OpenAI-compatible Base: https://anyrouter.dev/api/v1 Key: process.env.ANYROUTER_API_KEY (prefix sk-ar-) Model: process.env.ANYROUTER_MODEL (fallback z-ai/glm-4.7-flash) Rules: 1. Reuse the existing LLM client; if none, add one small module that exports a configured OpenAI client. 2. Never hardcode the key. 3. Keep request/response shapes compatible with the current feature. 4. Only swap the LLM source; keep existing UI and behavior. 5. Keep `anthropic/*` calls on /messages, or move them to /chat/completions. 6. Add a smoke test: one short prompt that prints the response. -
The client it adds looks like this (Python:
OpenAI(base_url=..., api_key=os.environ["ANYROUTER_API_KEY"])):typescriptimport OpenAI from "openai" export const anyrouter = new OpenAI({ baseURL: "https://anyrouter.dev/api/v1", apiKey: process.env.ANYROUTER_API_KEY, }) export const MODEL = process.env.ANYROUTER_MODEL ?? "z-ai/glm-4.7-flash" -
Verify. A reply of
anyrouter-okmeans it works:bashcurl https://anyrouter.dev/api/v1/chat/completions \ -H "Authorization: Bearer $ANYROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"z-ai/glm-4.7-flash","messages":[{"role":"user","content":"Reply with: anyrouter-ok"}],"max_tokens":20}'
Done when calls hit the base URL above, the key comes from the env var, model ids use provider/model, and streaming still streams.
Optional
Attribute usage to your app with headers X-AnyRouter-Title, X-AnyRouter-Source and X-AnyRouter-Version (OpenAI client: defaultHeaders).
Set routing preferences with a provider block in the request body:
{ "provider": { "sort": "latency", "max_price": { "prompt": "2.00", "completion": "8.00" }, "allow_fallbacks": true } }AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer