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.

SettingValue
Base URLhttps://anyrouter.dev/api/v1
KeyANYROUTER_API_KEY (prefix sk-ar-, from the dashboard)
Default modelz-ai/glm-4.7-flash
Cheap / fastopenai/gpt-5.4-nano, anthropic/claude-haiku-4-5
High qualityanthropic/claude-sonnet-4-6, openai/gpt-5.4
EndpointsPOST /chat/completions, POST /messages (Anthropic-native), POST /responses

Steps

  1. 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.
  2. The client it adds looks like this (Python: OpenAI(base_url=..., api_key=os.environ["ANYROUTER_API_KEY"])):

    typescript
    import 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"
  3. Verify. A reply of anyrouter-ok means it works:

    bash
    curl 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:

json
{ "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