{"slug": "agentrouter-the-definitive-developer-guide", "title": "AgentRouter: The Definitive Developer Guide", "summary": "AgentRouter, a non-profit OpenAI-compatible API gateway, aggregates over 30 AI models including Claude, GPT, Gemini, and DeepSeek behind a single endpoint, offering new users $200 in free credits via referral. The platform aims to lower barriers to AI experimentation for developers by providing a unified API key, pay-per-token pricing, and no subscription lock-in.", "body_md": "TL;DR— AgentRouter is a non-profit, OpenAI-compatible API gateway that aggregates Claude, GPT, Gemini, DeepSeek, and 30+ other models behind a single endpoint. New users get$200 in free creditsvia referral — no credit card required. Ideal for developers who want model flexibility without juggling five subscriptions.\n\n👉 [Claim Your $200 Free Credits → agentrouter.org/register?aff=DWBb](https://agentrouter.org/register?aff=DWBb)\n\n[What Is AgentRouter?](#1-what-is-agentrouter)[Free Credits Deep Dive: The $200 Offer Explained](#2-free-credits-deep-dive-the-200-offer-explained)[Full Model Catalog & Pricing Tiers](#3-full-model-catalog--pricing-tiers)[Architecture: How the Gateway Works](#4-architecture-how-the-gateway-works)[Integration Guides](#5-integration-guides)- 5.1\n[Claude Code (CLI)](#51-claude-code-cli) - 5.2\n[Cursor AI](#52-cursor-ai) - 5.3\n[Continue.dev (VS Code)](#53-continuedev-vs-code) - 5.4\n[LangChain / LangGraph](#54-langchain--langgraph) - 5.5\n[LlamaIndex](#55-llamaindex) - 5.6\n[N8N Automation](#56-n8n-automation) - 5.7\n[Raw HTTP / cURL](#57-raw-http--curl) - 5.8\n[Python SDK](#58-python-sdk) - 5.9\n[Node.js / TypeScript SDK](#59-nodejs--typescript-sdk)\n\n- 5.1\n[Practical Use Cases with Code Examples](#6-practical-use-cases-with-code-examples)[Competitive Landscape](#7-competitive-landscape)[Cost Modeling & Credit Optimization](#8-cost-modeling--credit-optimization)[Limitations, Risks & Mitigations](#9-limitations-risks--mitigations)[Security & Privacy Considerations](#10-security--privacy-considerations)[Community Feedback & Real Developer Experiences](#11-community-feedback--real-developer-experiences)[Who Should (and Should Not) Use AgentRouter](#12-who-should-and-should-not-use-agentrouter)[Step-by-Step Onboarding Walkthrough](#13-step-by-step-onboarding-walkthrough)[Troubleshooting Reference](#14-troubleshooting-reference)[Final Verdict](#15-final-verdict)\n\nAgentRouter is an **OpenAI-compatible, unified LLM API gateway** operated as a non-profit initiative. It consolidates access to dozens of commercial and open-source AI models — from Anthropic's Claude family to OpenAI's GPT series to Google's Gemini — behind a single base URL and a single API key.\n\n| Without AgentRouter | With AgentRouter |\n|---|---|\n| Separate API keys per provider | One API key, one endpoint |\n| Multiple billing dashboards | Single credit balance |\n| Subscription lock-in per provider | Pay-per-token, model-agnostic |\n| $40–$100/month in subscriptions to access top models | $0 upfront (with $200 free credit) |\n| Code changes required to switch models | Change one string: the model name |\n\nUnlike commercial aggregators such as OpenRouter (which charges a 5.5% platform fee on credit purchases) or Together.ai (which targets enterprise throughput), AgentRouter was built around a single premise: **lower the barrier to AI experimentation for developers who don't have venture-backed budgets.**\n\nThe platform explicitly states it provides *\"assistance to developers within our capacity, offering free quotas to support AI Coding.\"* This isn't a freemium funnel — it's an infrastructure-layer gift to the developer community.\n\nAgentRouter operates a tiered credit allocation based on how you sign up:\n\n```\nStandard sign-up  →  $100 free credits\nReferral sign-up  →  $200 free credits  ✅ (use link below)\nReferring a friend → +$100 per successful referral\n```\n\n👉 [Sign Up via Referral → Get $200 Instead of $100](https://agentrouter.org/register?aff=DWBb)\n\n**GitHub account**(OAuth-based authentication — no password needed)** No credit card**required** No trial period**— credits don't expire on a fixed countdown- Credits are deposited\n**immediately** upon account creation\n\nBased on developer reports across Reddit (r/ClaudeCode, r/buildinpublic, r/MachineLearning) and GitHub Gist reviews, here are approximate usage patterns for $200 in credits:\n\n| Activity | Estimated Credit Consumption | How Long $200 Lasts |\n|---|---|---|\n| Claude Sonnet 3.7 — general coding assistant, 50 msgs/day | ~$1.80/day | ~111 days |\n| GPT-4o — daily document drafting, 30 msgs/day | ~$0.60/day | ~333 days |\n| DeepSeek R1 — data analysis pipelines, 200 req/day | ~$0.10/day | ~2,000 days |\n| Mixed model usage (prototyping a SaaS) | ~$3–$8/day | 25–65 days |\n| Batch embeddings job (1M tokens/day) | ~$0.10–$0.20/day | ~1,000–2,000 days |\n\nReal data point:One developer on r/ClaudeCode reported 362 API requests consuming ~$20 in credits, leaving $279 remaining after combining the initial referral bonus with earned referral credits. Your mileage will vary based on model choice and context length.\n\n```\nYou sign up via referral   → You receive $200\nYou refer 1 friend         → You earn +$100 (total: $300)\nYou refer 2 friends        → You earn +$200 (total: $400)\nYou refer 5 friends        → You earn +$500 (total: $700)\n```\n\nFor developers writing blog posts, building tutorials, or running developer communities, the referral system can effectively make AgentRouter free indefinitely.\n\nThese models consume **$0 from your credit balance** and are suitable for high-volume, low-stakes tasks:\n\n| Model | Provider | Strengths | Context Window |\n|---|---|---|---|\n| GLM-4.5 Air | Z.ai | Fast inference, multilingual | 128K |\n| GLM-4.6 | Z.ai | Strong reasoning, low latency | 128K |\n| DeepSeek-V2 Lite | DeepSeek | Code generation, math | 32K |\n| Qwen2-7B-Instruct | Alibaba | Instruction following | 32K |\n| Mistral-7B-Instruct | Mistral AI | General purpose, fast | 32K |\n\nBest for: classification, routing decisions, background summarization, high-frequency tool calls.\n\n| Model | Input Cost | Output Cost | Best Use |\n|---|---|---|---|\n| Claude Haiku 3.5 | ~$0.25/1M | ~$1.25/1M | Tool routing, classification |\n| GPT-3.5 Turbo | ~$0.50/1M | ~$1.50/1M | Chat interfaces, legacy support |\n| Gemini 1.5 Flash | ~$0.075/1M | ~$0.30/1M | Document parsing, OCR post-processing |\n| DeepSeek Coder V2 Lite | ~$0.14/1M | ~$0.28/1M | Code completion, refactoring |\n\nBest for: production-grade code generation, agentic tasks, complex reasoning.\n\n| Model | Input Cost | Output Cost | Context Window | Best Use |\n|---|---|---|---|---|\n| Claude Sonnet 4.5 | ~$3/1M | ~$15/1M | 200K | Full agentic coding workflows |\n| Claude Sonnet 3.7 | ~$3/1M | ~$15/1M | 200K | Complex reasoning + tool use |\n| GPT-4o | ~$2.50/1M | ~$10/1M | 128K | Vision, structured outputs |\n| GPT-4o Mini | ~$0.15/1M | ~$0.60/1M | 128K | Cost-efficient GPT-4-class tasks |\n| Gemini 2.0 Pro | ~$3.50/1M | ~$10.50/1M | 1M | Long-document analysis |\n| Qwen3 Coder 480B | ~$2/1M | ~$6/1M | 64K | Specialized code generation |\n\nBest for: mission-critical generation, extremely long contexts, highest-capability needs.\n\n| Model | Input Cost | Output Cost | Context Window | Best Use |\n|---|---|---|---|---|\n| Claude Opus 4.5 | ~$15/1M | ~$75/1M | 200K | Deep research, long-form synthesis |\n| Claude Opus 4.0 | ~$15/1M | ~$75/1M | 200K | Complex multi-step reasoning |\n| GPT-5 | ~$10/1M | ~$30/1M | 128K | Frontier capability tasks |\n| Gemini 3 Pro | ~$7/1M | ~$21/1M | 2M | Ultra-long document processing |\n| DeepSeek R1 | ~$0.55/1M | ~$2.19/1M | 64K | Math, science, STEM reasoning |\n\nCost-saving tip:DeepSeek R1 provides premium-tier reasoning (math, science, coding logic) at near-free pricing. For structured reasoning tasks that don't require Claude/GPT's conversational polish, R1 is an exceptional value.\n\nUnderstanding AgentRouter's architecture helps you reason about latency, reliability, and data flow.\n\n```\nYour Application\n      │\n      │  (HTTPS, OpenAI-compatible JSON)\n      ▼\n┌─────────────────────────┐\n│     AgentRouter         │\n│   API Gateway Layer     │\n│                         │\n│  • Auth & key routing   │\n│  • Model name mapping   │\n│  • Credit accounting    │\n│  • Request queuing      │\n│  • Response passthrough │\n└──────────┬──────────────┘\n           │\n    ┌──────┼──────┐\n    ▼      ▼      ▼\nAnthropic OpenAI Google   ...and more\n Claude    GPT   Gemini\n```\n\n**OpenAI-Compatible REST API**\nAgentRouter exposes the `/v1/chat/completions`\n\nendpoint with the same request/response schema as OpenAI. Any library or tool that supports `openai.base_url`\n\nconfiguration will work out of the box.\n\n**Thin Proxy, Not a Fine-Tune Host**\nAgentRouter does not host or modify model weights. It routes requests to upstream providers. This means:\n\n- Response quality is identical to using the provider directly\n- New model versions appear as soon as providers release them\n- Prompt/response content is handled as-is (see Section 10 for privacy notes)\n\n**Singapore-Based Infrastructure**\nAgentRouter's primary infrastructure appears to be hosted in Singapore. This adds:\n\n- ~80–150ms additional latency for US East Coast users\n- ~20–60ms additional latency for Southeast Asian users\n- Negligible impact for batch/async workloads\n\nPrerequisites:Create your account and generate an API key before starting any integration.\n\n- Registration:\n[agentrouter.org/register?aff=DWBb]- Token console:\n`agentrouter.org/console/token`\n\n- Base URL:\n`https://agentrouter.org/v1`\n\nClaude Code is Anthropic's official command-line agentic coding tool. It reads your entire codebase, edits files, runs terminal commands, and leverages Claude's reasoning — all via AgentRouter.\n\n**Installation:**\n\n```\nnpm install -g @anthropic-ai/claude-code\n```\n\n**Configuration (macOS / Linux):**\n\n```\n# Add to ~/.bashrc, ~/.zshrc, or ~/.profile\nexport ANTHROPIC_BASE_URL=\"https://agentrouter.org/\"\nexport ANTHROPIC_AUTH_TOKEN=\"sk-your-agentrouter-key-here\"\nexport ANTHROPIC_API_KEY=\"sk-your-agentrouter-key-here\"\n```\n\n**Configuration (Windows PowerShell):**\n\n```\n$env:ANTHROPIC_BASE_URL = \"https://agentrouter.org/\"\n$env:ANTHROPIC_AUTH_TOKEN = \"sk-your-agentrouter-key-here\"\n$env:ANTHROPIC_API_KEY = \"sk-your-agentrouter-key-here\"\n```\n\n**Launch:**\n\n```\nsource ~/.zshrc   # Reload env vars\nclaude            # Start Claude Code\n```\n\n**Verify it's working:**\n\n```\n# Inside Claude Code, try:\n> What files are in this directory?\n# Claude should list your project files, confirming it's reading the codebase\n```\n\n**Recommended model for Claude Code via AgentRouter:**\n\n```\nclaude-sonnet-4-5-20250929   # Best balance of speed + reasoning\nclaude-opus-4-5-20250929     # For complex architectural tasks\nclaude-haiku-3-5-20241022    # For quick edits, low credit consumption\n```\n\nCursor is a VS Code fork with deep AI integration. Configuring it with AgentRouter unlocks any model in the catalog — not just the models Cursor bundles.\n\n**Step 1:** Open Cursor → Settings (⌘+Shift+J or Ctrl+Shift+J) → `Models`\n\n**Step 2:** Click `+ Add Model`\n\nand select `OpenAI Compatible`\n\n**Step 3:** Fill in:\n\n```\nProvider Name:  AgentRouter\nBase URL:       https://agentrouter.org/v1\nAPI Key:        sk-your-agentrouter-key-here\nModel Name:     claude-sonnet-4-5-20250929\n```\n\n**Step 4:** Click `Verify`\n\n— Cursor will ping the endpoint with a test request.\n\n**Step 5:** Select your AgentRouter model from the model picker in the Cursor chat panel.\n\n**Pro tip:** Add multiple model entries (one for Claude Sonnet, one for GPT-4o, one for DeepSeek R1) so you can switch mid-session without re-entering credentials.\n\nContinue is an open-source AI coding assistant for VS Code and JetBrains IDEs.\n\n**Install the Continue extension**, then edit `~/.continue/config.json`\n\n:\n\n```\n{\n  \"models\": [\n    {\n      \"title\": \"Claude Sonnet (AgentRouter)\",\n      \"provider\": \"openai\",\n      \"model\": \"claude-sonnet-4-5-20250929\",\n      \"apiBase\": \"https://agentrouter.org/v1\",\n      \"apiKey\": \"sk-your-agentrouter-key-here\"\n    },\n    {\n      \"title\": \"DeepSeek R1 (Free via AgentRouter)\",\n      \"provider\": \"openai\",\n      \"model\": \"deepseek-r1\",\n      \"apiBase\": \"https://agentrouter.org/v1\",\n      \"apiKey\": \"sk-your-agentrouter-key-here\"\n    }\n  ],\n  \"tabAutocompleteModel\": {\n    \"title\": \"GLM-4.5 Air (Free Autocomplete)\",\n    \"provider\": \"openai\",\n    \"model\": \"glm-4.5-air\",\n    \"apiBase\": \"https://agentrouter.org/v1\",\n    \"apiKey\": \"sk-your-agentrouter-key-here\"\n  }\n}\n```\n\nNote:Using a free model for tab autocomplete (`glm-4.5-air`\n\n) keeps your credit burn to near-zero for inline suggestions, while reserving premium models for chat and complex edits.\n\nLangChain's `ChatOpenAI`\n\nclass accepts a custom `base_url`\n\n, making AgentRouter a drop-in replacement.\n\n**Python:**\n\n``` python\nfrom langchain_openai import ChatOpenAI\nfrom langchain_core.messages import HumanMessage, SystemMessage\n\n# Swap in AgentRouter with zero code changes to your chain logic\nllm = ChatOpenAI(\n    model=\"claude-sonnet-4-5-20250929\",\n    openai_api_key=\"sk-your-agentrouter-key-here\",\n    openai_api_base=\"https://agentrouter.org/v1\",\n    temperature=0.7,\n    max_tokens=2048,\n)\n\n# Use it exactly like any other LangChain LLM\nresponse = llm.invoke([\n    SystemMessage(content=\"You are a senior Python engineer.\"),\n    HumanMessage(content=\"Refactor this code to use async/await: [paste code]\")\n])\nprint(response.content)\n```\n\n**LangGraph multi-agent example:**\n\n``` python\nfrom langchain_openai import ChatOpenAI\nfrom langgraph.graph import StateGraph, END\nfrom typing import TypedDict\n\n# Define different models for different agents in the same graph\nplanner_llm = ChatOpenAI(\n    model=\"claude-opus-4-5-20250929\",     # High-capability for planning\n    openai_api_key=\"sk-your-agentrouter-key-here\",\n    openai_api_base=\"https://agentrouter.org/v1\",\n)\n\nexecutor_llm = ChatOpenAI(\n    model=\"claude-sonnet-4-5-20250929\",   # Balanced for execution\n    openai_api_key=\"sk-your-agentrouter-key-here\",\n    openai_api_base=\"https://agentrouter.org/v1\",\n)\n\nreviewer_llm = ChatOpenAI(\n    model=\"deepseek-r1\",                   # Free model for review\n    openai_api_key=\"sk-your-agentrouter-key-here\",\n    openai_api_base=\"https://agentrouter.org/v1\",\n)\n\nclass AgentState(TypedDict):\n    task: str\n    plan: str\n    result: str\n    review: str\n\ndef plan_node(state: AgentState):\n    response = planner_llm.invoke(f\"Create a step-by-step plan for: {state['task']}\")\n    return {\"plan\": response.content}\n\ndef execute_node(state: AgentState):\n    response = executor_llm.invoke(f\"Execute this plan:\\n{state['plan']}\")\n    return {\"result\": response.content}\n\ndef review_node(state: AgentState):\n    response = reviewer_llm.invoke(f\"Review this output for correctness:\\n{state['result']}\")\n    return {\"review\": response.content}\n\n# Build the graph\ngraph = StateGraph(AgentState)\ngraph.add_node(\"plan\", plan_node)\ngraph.add_node(\"execute\", execute_node)\ngraph.add_node(\"review\", review_node)\ngraph.set_entry_point(\"plan\")\ngraph.add_edge(\"plan\", \"execute\")\ngraph.add_edge(\"execute\", \"review\")\ngraph.add_edge(\"review\", END)\n\napp = graph.compile()\nresult = app.invoke({\"task\": \"Write a FastAPI CRUD service for a blog\"})\npython\nfrom llama_index.llms.openai import OpenAI\nfrom llama_index.core import Settings, VectorStoreIndex, SimpleDirectoryReader\n\n# Configure AgentRouter as the LLM backend\nSettings.llm = OpenAI(\n    model=\"gpt-4o\",\n    api_key=\"sk-your-agentrouter-key-here\",\n    api_base=\"https://agentrouter.org/v1\",\n)\n\n# Build a RAG pipeline over local documents\ndocuments = SimpleDirectoryReader(\"./docs\").load_data()\nindex = VectorStoreIndex.from_documents(documents)\nquery_engine = index.as_query_engine()\n\nresponse = query_engine.query(\"What are the key findings in the Q3 report?\")\nprint(response)\n```\n\nN8N's HTTP Request node can call AgentRouter directly, enabling LLM-powered automation without code.\n\n**Node configuration:**\n\n```\nMethod:         POST\nURL:            https://agentrouter.org/v1/chat/completions\nAuthentication: Header Auth\nHeader Name:    Authorization\nHeader Value:   Bearer sk-your-agentrouter-key-here\n\nBody (JSON):\n{\n  \"model\": \"claude-sonnet-4-5-20250929\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are an email classifier. Respond with JSON only.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Classify this email: {{ $json.email_body }}\"\n    }\n  ],\n  \"response_format\": { \"type\": \"json_object\" }\n}\n```\n\n**Example use cases in N8N:**\n\n- Classify incoming support emails → route to Slack channels\n- Summarize Google Sheets rows → send digest to email\n- Parse unstructured form submissions → write to Airtable\n- Generate weekly reports from Notion databases → post to Confluence\n\nUse this to test your API key and verify connectivity before integrating into a framework.\n\n```\ncurl https://agentrouter.org/v1/chat/completions \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer sk-your-agentrouter-key-here\" \\\n  -d '{\n    \"model\": \"claude-sonnet-4-5-20250929\",\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"content\": \"Say hello and tell me your model name.\"\n      }\n    ],\n    \"max_tokens\": 100\n  }'\n```\n\n**Expected response shape:**\n\n```\n{\n  \"id\": \"chatcmpl-abc123\",\n  \"object\": \"chat.completion\",\n  \"model\": \"claude-sonnet-4-5-20250929\",\n  \"choices\": [\n    {\n      \"index\": 0,\n      \"message\": {\n        \"role\": \"assistant\",\n        \"content\": \"Hello! I'm Claude Sonnet, routing through AgentRouter.\"\n      },\n      \"finish_reason\": \"stop\"\n    }\n  ],\n  \"usage\": {\n    \"prompt_tokens\": 14,\n    \"completion_tokens\": 17,\n    \"total_tokens\": 31\n  }\n}\n```\n\n**Streaming response:**\n\n```\ncurl https://agentrouter.org/v1/chat/completions \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer sk-your-agentrouter-key-here\" \\\n  -d '{\n    \"model\": \"gpt-4o\",\n    \"stream\": true,\n    \"messages\": [{\"role\": \"user\", \"content\": \"Write a haiku about APIs.\"}]\n  }'\n```\n\nUsing the official `openai`\n\nPython package with AgentRouter requires only changing two parameters:\n\n``` python\nfrom openai import OpenAI\n\nclient = OpenAI(\n    api_key=\"sk-your-agentrouter-key-here\",\n    base_url=\"https://agentrouter.org/v1\",\n)\n\n# ── Basic chat completion ──────────────────────────────────────────────────────\nresponse = client.chat.completions.create(\n    model=\"claude-sonnet-4-5-20250929\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are an expert software architect.\"},\n        {\"role\": \"user\", \"content\": \"Design a microservice architecture for an e-commerce platform.\"}\n    ],\n    temperature=0.5,\n    max_tokens=2000,\n)\nprint(response.choices[0].message.content)\n\n# ── Streaming ──────────────────────────────────────────────────────────────────\nwith client.chat.completions.stream(\n    model=\"gpt-4o\",\n    messages=[{\"role\": \"user\", \"content\": \"Explain WebSockets in 3 paragraphs.\"}],\n) as stream:\n    for chunk in stream:\n        if chunk.choices[0].delta.content:\n            print(chunk.choices[0].delta.content, end=\"\", flush=True)\n\n# ── Structured output (JSON mode) ──────────────────────────────────────────────\nimport json\n\nresponse = client.chat.completions.create(\n    model=\"gpt-4o\",\n    response_format={\"type\": \"json_object\"},\n    messages=[\n        {\"role\": \"system\", \"content\": \"Return only valid JSON.\"},\n        {\"role\": \"user\", \"content\": \"Give me a JSON object with 3 Python library recommendations and their use cases.\"}\n    ],\n)\ndata = json.loads(response.choices[0].message.content)\nprint(data)\n\n# ── Model comparison helper ────────────────────────────────────────────────────\ndef compare_models(prompt: str, models: list[str]) -> dict:\n    results = {}\n    for model in models:\n        resp = client.chat.completions.create(\n            model=model,\n            messages=[{\"role\": \"user\", \"content\": prompt}],\n            max_tokens=500,\n        )\n        results[model] = {\n            \"response\": resp.choices[0].message.content,\n            \"tokens\": resp.usage.total_tokens,\n        }\n    return results\n\n# Compare Claude vs GPT-4o on the same prompt\ncomparison = compare_models(\n    prompt=\"What is the time complexity of a balanced BST lookup?\",\n    models=[\"claude-sonnet-4-5-20250929\", \"gpt-4o\", \"deepseek-r1\"]\n)\nfor model, data in comparison.items():\n    print(f\"\\n--- {model} ({data['tokens']} tokens) ---\")\n    print(data[\"response\"])\npython\nimport OpenAI from \"openai\";\n\nconst client = new OpenAI({\n  apiKey: process.env.AGENTROUTER_API_KEY!,\n  baseURL: \"https://agentrouter.org/v1\",\n});\n\n// ── Basic completion ───────────────────────────────────────────────────────────\nasync function complete(prompt: string, model = \"claude-sonnet-4-5-20250929\") {\n  const response = await client.chat.completions.create({\n    model,\n    messages: [{ role: \"user\", content: prompt }],\n    max_tokens: 1000,\n  });\n  return response.choices[0].message.content;\n}\n\n// ── Streaming to the browser (Next.js App Router) ─────────────────────────────\n// app/api/chat/route.ts\nexport async function POST(req: Request) {\n  const { message } = await req.json();\n\n  const stream = await client.chat.completions.create({\n    model: \"gpt-4o\",\n    stream: true,\n    messages: [{ role: \"user\", content: message }],\n  });\n\n  const encoder = new TextEncoder();\n  const readable = new ReadableStream({\n    async start(controller) {\n      for await (const chunk of stream) {\n        const text = chunk.choices[0]?.delta?.content ?? \"\";\n        if (text) controller.enqueue(encoder.encode(text));\n      }\n      controller.close();\n    },\n  });\n\n  return new Response(readable, {\n    headers: { \"Content-Type\": \"text/plain; charset=utf-8\" },\n  });\n}\n\n// ── Tool calling (function calling) ───────────────────────────────────────────\nconst weatherTool: OpenAI.ChatCompletionTool = {\n  type: \"function\",\n  function: {\n    name: \"get_weather\",\n    description: \"Fetches current weather for a given city\",\n    parameters: {\n      type: \"object\",\n      properties: {\n        city: { type: \"string\", description: \"The city name\" },\n        unit: { type: \"string\", enum: [\"celsius\", \"fahrenheit\"] },\n      },\n      required: [\"city\"],\n    },\n  },\n};\n\nasync function agentWithTools(userMessage: string) {\n  const messages: OpenAI.ChatCompletionMessageParam[] = [\n    { role: \"user\", content: userMessage },\n  ];\n\n  const response = await client.chat.completions.create({\n    model: \"claude-sonnet-4-5-20250929\",\n    tools: [weatherTool],\n    tool_choice: \"auto\",\n    messages,\n  });\n\n  const choice = response.choices[0];\n  if (choice.finish_reason === \"tool_calls\") {\n    const toolCall = choice.message.tool_calls![0];\n    const args = JSON.parse(toolCall.function.arguments);\n    console.log(`Tool called: ${toolCall.function.name}`, args);\n    // → Execute actual weather API call here\n  }\n}\npython\nimport subprocess\nfrom openai import OpenAI\n\nclient = OpenAI(\n    api_key=\"sk-your-agentrouter-key-here\",\n    base_url=\"https://agentrouter.org/v1\",\n)\n\ndef get_git_diff() -> str:\n    result = subprocess.run(\n        [\"git\", \"diff\", \"--cached\"],\n        capture_output=True, text=True\n    )\n    return result.stdout\n\ndef review_code(diff: str) -> str:\n    response = client.chat.completions.create(\n        model=\"claude-sonnet-4-5-20250929\",  # Strong reasoning model\n        messages=[\n            {\n                \"role\": \"system\",\n                \"content\": (\n                    \"You are a senior software engineer performing a code review. \"\n                    \"Focus on: bugs, security issues, performance, readability, and test coverage. \"\n                    \"Format your response as: CRITICAL / MAJOR / MINOR / SUGGESTION sections.\"\n                ),\n            },\n            {\n                \"role\": \"user\",\n                \"content\": f\"Review this git diff:\\n\\n``` diff\\n{diff}\\n```\",\n            },\n        ],\n        max_tokens=2000,\n    )\n    return response.choices[0].message.content\n\nif __name__ == \"__main__\":\n    diff = get_git_diff()\n    if not diff:\n        print(\"No staged changes to review.\")\n    else:\n        print(review_code(diff))\npython\nfrom openai import OpenAI\nimport time, json\n\nclient = OpenAI(\n    api_key=\"sk-your-agentrouter-key-here\",\n    base_url=\"https://agentrouter.org/v1\",\n)\n\nBENCHMARK_PROMPTS = [\n    \"Implement a binary search tree in Python with insert, delete, and search.\",\n    \"Explain the CAP theorem to a junior developer.\",\n    \"Write a regex to validate ISO 8601 datetime strings.\",\n    \"What is the difference between mutex and semaphore?\",\n]\n\nMODELS = [\n    \"claude-sonnet-4-5-20250929\",\n    \"gpt-4o\",\n    \"gemini-2-0-pro\",\n    \"deepseek-r1\",\n]\n\ndef benchmark():\n    results = []\n    for prompt in BENCHMARK_PROMPTS:\n        prompt_results = {\"prompt\": prompt[:60] + \"...\", \"models\": {}}\n        for model in MODELS:\n            start = time.time()\n            try:\n                resp = client.chat.completions.create(\n                    model=model,\n                    messages=[{\"role\": \"user\", \"content\": prompt}],\n                    max_tokens=800,\n                )\n                latency = round(time.time() - start, 2)\n                prompt_results[\"models\"][model] = {\n                    \"latency_s\": latency,\n                    \"tokens\": resp.usage.total_tokens,\n                    \"preview\": resp.choices[0].message.content[:100],\n                }\n            except Exception as e:\n                prompt_results[\"models\"][model] = {\"error\": str(e)}\n        results.append(prompt_results)\n\n    with open(\"benchmark_results.json\", \"w\") as f:\n        json.dump(results, f, indent=2)\n    print(\"Benchmark complete. Results saved to benchmark_results.json\")\n\nbenchmark()\npython\nfrom openai import OpenAI\nfrom pathlib import Path\n\nclient = OpenAI(\n    api_key=\"sk-your-agentrouter-key-here\",\n    base_url=\"https://agentrouter.org/v1\",\n)\n\ndef process_document(file_path: str) -> dict:\n    text = Path(file_path).read_text()\n\n    # Step 1: Classify the document (cheap model)\n    classification = client.chat.completions.create(\n        model=\"glm-4.5-air\",  # Free model for cheap classification\n        messages=[\n            {\"role\": \"system\", \"content\": \"Classify the document type in one word: contract, report, email, invoice, or other.\"},\n            {\"role\": \"user\", \"content\": text[:2000]},\n        ],\n        max_tokens=10,\n    ).choices[0].message.content.strip().lower()\n\n    # Step 2: Extract entities (mid-tier model)\n    entities = client.chat.completions.create(\n        model=\"gpt-4o-mini\",\n        response_format={\"type\": \"json_object\"},\n        messages=[\n            {\"role\": \"system\", \"content\": \"Extract key entities as JSON: {parties, dates, amounts, obligations}\"},\n            {\"role\": \"user\", \"content\": text[:4000]},\n        ],\n        max_tokens=500,\n    ).choices[0].message.content\n\n    # Step 3: Deep analysis (premium model, only if contract)\n    analysis = None\n    if classification == \"contract\":\n        analysis = client.chat.completions.create(\n            model=\"claude-opus-4-5-20250929\",  # Premium model for critical legal docs\n            messages=[\n                {\"role\": \"system\", \"content\": \"You are a legal analyst. Identify risks, obligations, and red flags.\"},\n                {\"role\": \"user\", \"content\": text},\n            ],\n            max_tokens=3000,\n        ).choices[0].message.content\n\n    return {\n        \"document_type\": classification,\n        \"entities\": entities,\n        \"legal_analysis\": analysis,\n    }\n```\n\n| Feature | AgentRouter | OpenRouter |\n|---|---|---|\n| Model count | ~30–50 models | 400+ models |\n| Platform fee | 0% (non-profit) | 5.5% on credits |\n| Free credit offer | $200 via referral | $1 trial credit |\n| Enterprise features | None | Routing, fallbacks, A/B testing |\n| Uptime SLA | None published | 99.9% SLA available |\n| Best for | Students, indie hackers, prototyping | Production apps, enterprise teams |\n\n| Factor | AgentRouter | Direct (OpenAI/Anthropic/Google) |\n|---|---|---|\n| API keys needed | 1 | 1 per provider (3+) |\n| Latency overhead | +80–150ms (Singapore) | Baseline (regional) |\n| Code to switch models | Change model string only | Change base URL + SDK |\n| Billing | Single balance | Separate invoices |\n| Support | Community / email | Tier-based enterprise support |\n| Privacy | Third-party proxy | Direct with provider |\n| Cost | Provider pricing | Provider pricing |\n\n| Factor | AgentRouter (API) | Claude Pro ($20/mo) | ChatGPT Plus ($20/mo) |\n|---|---|---|---|\n| Provider access | All providers | Anthropic only | OpenAI only |\n| Programmatic access | Yes (API) | Limited (Projects API) | Limited |\n| Cost model | Pay-per-token | Flat monthly | Flat monthly |\n| Usage limits | Credit-based | Rate limited | Rate limited |\n| Web UI included | No | Yes | Yes |\n| Ideal user | Developer | Power user (non-dev) | Power user (non-dev) |\n\n**Verdict:** If you're a developer who writes code, AgentRouter almost always wins on economics and flexibility. If you're a non-developer who wants a chat interface, direct subscriptions are simpler.\n\nProfessional teams and experienced indie developers use a tiered approach to model selection that can reduce costs by 60–90% versus always using premium models:\n\n```\nTier 1 → Routing / Classification / Triage\n  Use: GLM-4.5 Air, DeepSeek-V2 Lite (free)\n  When: \"Is this question about billing or technical support?\"\n\nTier 2 → Execution / Generation / Standard tasks\n  Use: Claude Haiku, GPT-4o Mini, Gemini Flash\n  When: \"Write a 3-sentence summary of this article.\"\n\nTier 3 → Complex Reasoning / Critical Paths\n  Use: Claude Sonnet, GPT-4o, DeepSeek R1\n  When: \"Architect this distributed system and identify failure modes.\"\n\nTier 4 → Mission-Critical / Long Context\n  Use: Claude Opus, GPT-5, Gemini 3 Pro\n  When: \"Analyze this 150-page contract for legal risks.\"\n# Rough credit cost estimator\nTOKEN_COSTS = {\n    \"glm-4.5-air\":                {\"input\": 0.0,    \"output\": 0.0},\n    \"claude-haiku-3-5-20241022\":  {\"input\": 0.00025, \"output\": 0.00125},\n    \"gpt-4o-mini\":                {\"input\": 0.00015, \"output\": 0.0006},\n    \"claude-sonnet-4-5-20250929\": {\"input\": 0.003,   \"output\": 0.015},\n    \"gpt-4o\":                     {\"input\": 0.0025,  \"output\": 0.01},\n    \"claude-opus-4-5-20250929\":   {\"input\": 0.015,   \"output\": 0.075},\n}\n\ndef estimate_cost(model: str, input_tokens: int, output_tokens: int) -> float:\n    costs = TOKEN_COSTS.get(model, {\"input\": 0.005, \"output\": 0.015})\n    return (input_tokens / 1000) * costs[\"input\"] + (output_tokens / 1000) * costs[\"output\"]\n\n# Example: 1,000 requests with avg 500 input + 300 output tokens\nfor model, _ in TOKEN_COSTS.items():\n    daily_cost = estimate_cost(model, 500, 300) * 1000\n    days_on_200 = round(200 / daily_cost, 1) if daily_cost > 0 else float(\"inf\")\n    print(f\"{model:45s} → ${daily_cost:.2f}/day → ${200} lasts {days_on_200} days\")\n```\n\n-\n**Cache repeated prompts.** If your app hits the same system prompt + static context repeatedly, cache the response and only re-call the API when the user input changes. -\n**Use streaming for UX, not for tokens.** Streaming doesn't reduce token count — use it for perceived responsiveness, not cost savings. -\n**Trim context aggressively.** Claude and GPT charge for input tokens. If your conversation history grows, summarize older turns rather than passing the full history. -\n**Route simple queries to free models.** A 3-way classifier (Is this: simple FAQ / moderate / complex?) using GLM-4.5 Air costs $0 and lets you avoid spending $0.018 per Sonnet call on questions like \"What's your return policy?\" -\n**Set** Without a ceiling, models may generate verbose responses. Setting`max_tokens`\n\nexplicitly.`max_tokens: 400`\n\nfor short answers can halve your output token spend.\n\n| Scenario | Typical Overhead | Impact | Mitigation |\n|---|---|---|---|\n| Singapore → US East | +120–180ms per call | Interactive chat: noticeable | Use streaming to mask latency |\n| Singapore → EU | +100–140ms per call | Moderate | Stream responses; async UX |\n| Singapore → SEA/APAC | +10–50ms per call | Negligible | None needed |\n| Batch processing | Irrelevant | None | Use async batch jobs |\n\nAgentRouter is a **non-profit service with no published SLA.** This means:\n\n- No contractual uptime guarantee\n- Community/email support only\n- No incident response commitments\n\n**Mitigation pattern:**\n\n``` python\nimport httpx\nfrom openai import OpenAI, APIConnectionError\n\ndef create_client_with_fallback():\n    \"\"\"Returns AgentRouter client with fallback to direct Anthropic.\"\"\"\n    return {\n        \"primary\": OpenAI(\n            api_key=\"sk-agentrouter-key\",\n            base_url=\"https://agentrouter.org/v1\"\n        ),\n        \"fallback\": OpenAI(\n            api_key=\"sk-anthropic-direct-key\",\n            base_url=\"https://api.anthropic.com/v1\"\n        ),\n    }\n\ndef robust_complete(prompt: str, clients: dict) -> str:\n    for client_name, client in clients.items():\n        try:\n            resp = client.chat.completions.create(\n                model=\"claude-sonnet-4-5-20250929\",\n                messages=[{\"role\": \"user\", \"content\": prompt}],\n                timeout=30.0,\n            )\n            return resp.choices[0].message.content\n        except (APIConnectionError, Exception) as e:\n            print(f\"[{client_name}] failed: {e}. Trying next...\")\n    raise RuntimeError(\"All providers failed.\")\n```\n\nAgentRouter's docs cover the essentials but lack:\n\n- Video walkthroughs\n- Advanced configuration guides\n- Per-model quirks and known issues\n- Detailed troubleshooting decision trees\n\n**Mitigation:** This document, community threads on r/ClaudeCode and r/LocalLLaMA, and AgentRouter's GitHub issues serve as supplementary documentation.\n\nThe platform's funding model is not publicly disclosed. Long-term sustainability questions are legitimate.\n\n**Risk level by use case:**\n\n```\nExperimentation / learning    → Low risk  (credits already claimed)\nSide project / prototype      → Low risk  (not mission-critical)\nProduction secondary traffic  → Medium    (have backup provider)\nPrimary production system     → High risk (use direct APIs instead)\n```\n\nAs an API proxy, AgentRouter processes every request before forwarding it to the underlying provider. This means:\n\n**Prompts and system messages** pass through AgentRouter's infrastructure**Response content** is routed back through AgentRouter**API key** for AgentRouter (not your provider keys) is transmitted per request\n\n- PII governed by GDPR, HIPAA, or CCPA (patient records, SSNs, financial account data)\n- Trade secrets or proprietary source code in regulated industries\n- Authentication credentials (passwords, private keys, OAuth tokens)\n- Classified or government-sensitive information\n\n- Public documentation, articles, or research\n- Open-source code\n- Non-PII product descriptions, marketing copy\n- General programming questions and coding tasks\n- Non-sensitive business logic in prototyping contexts\n\n```\n# Never hardcode API keys — use environment variables\nexport AGENTROUTER_API_KEY=\"sk-...\"\n\n# Add to .gitignore\necho \".env\" >> .gitignore\necho \"*.env\" >> .gitignore\n\n# Use a secrets manager in production\n# AWS Secrets Manager / HashiCorp Vault / Doppler\npython\n# Load from environment, never from code\nimport os\napi_key = os.environ[\"AGENTROUTER_API_KEY\"]  # Will raise if not set — intentional\n```\n\n**\"It actually works\"** — The most common first reaction. The credits appear, the API responds, the models are real.\n\n\"cuz it works, i have used and if i invite someone i get $100 free of charge\"— Reddit, r/ClaudeCode\n\n**Model breadth at zero cost**:\n\n\"That extra credit works across GPT-4, Claude, LLaMA, and other models, so it's pretty handy if you're experimenting or building AI projects.\"— Reddit, r/buildinpublic\n\n**Pragmatic endorsement from a careful reviewer:**\n\n\"AgentRouter won't replace a proper Anthropic or OpenAI subscription for serious production work. But for developers who want to tinker, prototype, or learn, it removes the cost barrier completely.\"— GitHub Gist, \"AgentRouter Review 2026\"\n\n**Latency concerns** — Users on US-based infrastructure report 100–200ms additional latency versus direct APIs. Universally noted as a non-issue for non-interactive use cases.\n\n**Documentation gaps** — The platform's official docs are functional but terse. Advanced configuration (streaming, function calling, vision inputs) requires trial-and-error or community guidance.\n\n**\"Is this legit?\" skepticism** — Multiple users noted initial distrust of a Singapore-based provider offering $200 free credits. Post-verification, the sentiment converged on \"it is what it says it is.\"\n\n| Profile | Why AgentRouter Works |\n|---|---|\nStudents & Learners |\n$200 gives virtually unlimited experimentation time without financial risk |\nSolo developers / indie hackers |\nDefers infrastructure costs until product-market fit is found |\nResearchers & academics |\nSingle API for cross-model comparison studies; unified billing for grants |\nAgency / freelance developers |\nPay-per-use aligns with unpredictable client project volumes |\nHackathon participants |\nCredits last well beyond a weekend, free models available for high-volume tasks |\nEducators building curriculum |\nEasy to teach one API structure instead of three provider SDKs |\n\n| Profile | Better Alternative |\n|---|---|\nProduction systems requiring SLA |\nDirect provider APIs with uptime contracts |\nHIPAA / GDPR / regulated data |\nDirect APIs with DPA agreements signed |\nUltra-low latency (<50ms) requirements |\nDirect regional provider endpoints |\nEnterprise teams needing support contracts |\nOpenRouter Enterprise or direct provider support |\nCompanies requiring audit logs |\nDirect APIs with your own logging infrastructure |\n\nNavigate to the referral link to ensure you receive $200 instead of the standard $100:\n\n👉 [agentrouter.org/register?aff=DWBb](https://agentrouter.org/register?aff=DWBb)\n\nClick **\"Sign in with GitHub\"** → Authorize the OAuth app → Account created.\n\nIn the AgentRouter console, confirm your balance shows `$200.00`\n\nbefore proceeding. If you see `$100.00`\n\n, you may have signed up without the referral link — contact support.\n\nVisit: `https://agentrouter.org/console/token`\n\nClick **\"Generate New Token\"** → Copy the key immediately (it will not be shown again).\n\nStore it securely:\n\n```\n# macOS Keychain\nsecurity add-generic-password -a \"$USER\" -s \"agentrouter\" -w \"sk-your-key-here\"\n\n# Or in a .env file (never commit to git)\necho 'AGENTROUTER_API_KEY=sk-your-key-here' >> .env\ncurl https://agentrouter.org/v1/chat/completions \\\n  -H \"Authorization: Bearer sk-your-key-here\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"model\":\"glm-4.5-air\",\"messages\":[{\"role\":\"user\",\"content\":\"ping\"}],\"max_tokens\":5}'\n```\n\nA successful response confirms your key works and the free GLM model is reachable.\n\nRefer to Section 5 for detailed guides. **Recommended starting path by profile:**\n\n```\nWriting code in a terminal? → Section 5.1 (Claude Code)\nUsing VS Code daily?        → Section 5.3 (Continue.dev)\nBuilding a Python app?      → Section 5.8 (Python SDK)\nBuilding a Node.js app?     → Section 5.9 (Node.js SDK)\nBuilding automations?       → Section 5.6 (N8N)\nExploring AI frameworks?    → Section 5.4 (LangChain)\n# Phase 1: Validate your integration works — zero cost\nmodel = \"glm-4.5-air\"\n\n# Phase 2: Test quality — small spend\nmodel = \"gpt-4o-mini\"\n\n# Phase 3: Production-quality output\nmodel = \"claude-sonnet-4-5-20250929\"\n```\n\nCheck your credit balance and usage breakdown in the AgentRouter console regularly. Identify your top token consumers and apply Section 8's optimization tips if needed.\n\nOnce you've confirmed the platform works for your needs, retrieve your personal referral link from the console. Sharing it with each colleague, student, or community member adds $100 to your balance.\n\n| Problem | Likely Cause | Solution |\n|---|---|---|\n`401 Unauthorized` |\nWrong API key or missing `Bearer` prefix |\nVerify key at console; ensure header is `Authorization: Bearer sk-...` |\n`404 Not Found` |\nWrong base URL | Use `https://agentrouter.org/v1` (with `/v1` ) |\n`model not found` error |\nIncorrect model identifier string | Check AgentRouter docs for exact model ID; try `gpt-4o` or `claude-sonnet-4-5-20250929` |\nCredits showing `$0` |\nStandard signup used instead of referral | Contact support with account email |\n| Latency >500ms | Peak traffic on AgentRouter servers | Retry with exponential backoff; switch to free model temporarily |\n| Streaming not working | Missing `stream: true` in request body |\nAdd `\"stream\": true` to request JSON |\n`claude-code` ignoring env vars |\nShell not reloaded after export | Run `source ~/.zshrc` or restart terminal |\n`Connection reset by peer` |\nTimeout on long-running requests | Increase `timeout` parameter; break request into smaller chunks |\n\nAgentRouter occupies a unique position in the AI infrastructure stack. It's not trying to compete with OpenRouter's enterprise feature set or replace direct provider APIs for mission-critical production systems. It's doing something more specific and arguably more valuable: **removing the cost of entry for developers who want to experiment.**\n\nThe $200 free credits matter less than the psychological shift they enable. The difference between \"I can't afford to run 500 test API calls this week\" and \"I have $200 to burn through experimenting\" is the difference between a project idea staying in a Notion doc versus becoming a deployed application.\n\nFor learners, that shift is how skills are built. For indie developers, it's how MVPs get validated. For researchers, it's how hypotheses get tested. For educators, it's how curriculum gets built without grant-budget anxiety.\n\n| Dimension | Score | Notes |\n|---|---|---|\n| Value for money | ★★★★★ | $200 free credits with no friction |\n| Model breadth | ★★★★☆ | ~30–50 models; not as deep as OpenRouter's 400+ |\n| API compatibility | ★★★★★ | Drop-in OpenAI replacement; works with every major framework |\n| Documentation | ★★★☆☆ | Functional but terse; this guide fills the gap |\n| Latency | ★★★☆☆ | ~100–150ms overhead from Singapore; fine for most use cases |\n| Reliability | ★★★☆☆ | No SLA; community support; stable for months per user reports |\n| Privacy transparency | ★★☆☆☆ | No published data retention policy; use with non-sensitive data only |\n| Production readiness | ★★☆☆☆ | Not recommended as sole provider for critical systems |\n\nGiven that it costs nothing to try and $200 to explore every major AI model on the market — what have you been putting off building because the API costs felt prohibitive?\n\nStart there.\n\n👉 [Claim $200 in Free Credits at AgentRouter → agentrouter.org/register?aff=DWBb](https://agentrouter.org/register?aff=DWBb)\n\n*Last updated: April 2026 · Model pricing and availability subject to change — verify current rates in the AgentRouter console.*", "url": "https://wpnews.pro/news/agentrouter-the-definitive-developer-guide", "canonical_source": "https://gist.github.com/jidetheblogger/f5ee6d1f865f72f89ecf1f11bfa16a33", "published_at": "2026-08-10 13:01:06+00:00", "updated_at": "2026-08-10 13:09:29.315588+00:00", "lang": "en", "topics": ["ai-products", "developer-tools", "large-language-models", "ai-infrastructure"], "entities": ["AgentRouter", "Anthropic", "OpenAI", "Google", "DeepSeek", "OpenRouter", "Together.ai"], "alternates": {"html": "https://wpnews.pro/news/agentrouter-the-definitive-developer-guide", "markdown": "https://wpnews.pro/news/agentrouter-the-definitive-developer-guide.md", "text": "https://wpnews.pro/news/agentrouter-the-definitive-developer-guide.txt", "jsonld": "https://wpnews.pro/news/agentrouter-the-definitive-developer-guide.jsonld"}}