By UNST33R
Point Claude Code at your own model: base URLs, gateway routers, and what actually breaks
Claude Code's own documentation describes ANTHROPIC_BASE_URL as the variable that changes where requests are sent. That one environment variable is the control point for running a coding agent on a backend you selected, audited, and pay for per token. Three rewiring patterns with working commands, the failure modes that bite in production (tool-call drift, caching semantics, context accounting), a security checklist covering what your agent leaks to its base URL, and tier picks for offensive-tooling workloads.
The Claude Code model configuration docs contain one sentence that deserves a wider audience: "ANTHROPIC_BASE_URL changes where requests are sent, not which model answers them." Read it as an invitation. A coding agent is a prompt engine wired to a URL, and once you control the URL, you control the model behind it, the logging on the path, and the price per token. The demand is visible in the ecosystem: claude-code-router, a local router that fronts arbitrary model backends for Claude Code, sat at 38,295 GitHub stars when we read the API on November 22, with its last push the day before.
For authorized red-team work the three drivers are concrete. Refusal friction kills multi-hour agent loops the moment the harness touches offensive tooling. Data handling matters because an agent ships your repository source, exploit notes, and sometimes live credentials in its context window to whatever the base URL resolves to. And bulk code analysis at frontier-model pricing adds up fast. This guide covers the three rewiring patterns, what breaks when you use them, and the security hygiene most tutorials skip. The same patterns apply to any agent that accepts a custom OpenAI-compatible endpoint, from OpenClaw deployments to IDE assistants.
Pick the pattern before you touch a config file
| Pattern | Agent speaks | Backend speaks | What you edit | When to use it |
|---|---|---|---|---|
| A. Native OpenAI-compatible | OpenAI chat completions | OpenAI chat completions | OPENAI_BASE_URL or client base_url | Continue, Cline, aider-style tools, your own scripts |
| B. Anthropic-native | Anthropic messages API | Anthropic messages API | ANTHROPIC_BASE_URL, ANTHROPIC_MODEL | Claude Code against an Anthropic-protocol gateway |
| C. Translation router | Anthropic messages API | OpenAI chat completions | Router config plus ANTHROPIC_BASE_URL pointing at it | Claude Code on any OpenAI-compatible backend, including ours |
Our own endpoint at https://api.unst33r.si/v1 speaks the OpenAI wire protocol, so Claude Code users land on pattern C. Tools that already speak OpenAI use pattern A directly.
Pattern A: the native OpenAI-compatible path
Every serious agent framework exposes a base URL setting. In the official Python SDK the client reads OPENAI_BASE_URL from the environment; other SDKs expose an equivalent base_url argument. A thirty-second smoke test:
export OPENAI_BASE_URL=https://api.unst33r.si/v1
export OPENAI_API_KEY=$UNST33R_API_KEY
curl "$OPENAI_BASE_URL/chat/completions" \
-H "Authorization: Bearer $UNST33R_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "unst33r-deepseek",
"messages": [{"role": "user", "content": "Summarize the auth flow in this repo."}]
}'
If that returns a completion, every OpenAI-compatible tool in your kit works with two environment variables. We keep a step-by-step version of this in the base URL switching guide. Verify tool support before committing a model to agent duty, because reduced-refusal variants can shift JSON formatting behavior; the JSON mode vs function calling comparison covers the failure shapes.
Pattern B: Claude Code against an Anthropic-protocol gateway
Claude Code sends Anthropic messages-API traffic, so the native path only works when your gateway terminates that protocol. The settings documentation accepts an env block in project and user settings, which keeps secrets out of shell dotfiles:
{
"env": {
"ANTHROPIC_BASE_URL": "https://your-anthropic-protocol-gateway.example",
"ANTHROPIC_MODEL": "your-gateway-alias"
}
}
Three behaviors from the official docs are worth knowing before you rely on this in a engagement. First, model IDs the tool recognizes keep their API context windows behind a gateway, while unrecognized alias IDs compact at the context window the tool assumes for them, so a router alias can silently truncate long sessions. Second, the ANTHROPIC_DEFAULT_OPUS_MODEL_NAME and sibling display-name variables also take effect behind a gateway, which keeps the model picker readable. Third, plan and usage-credit checks apply only when the tool connects to the Anthropic API directly, so a gateway with a saved login skips them. For credentials, prefer the documented API key helper mechanism over long-lived tokens in plaintext config.
Pattern C: the translation router
When the backend speaks OpenAI and the agent speaks Anthropic, put a translator between them. The two mature options:
| Router | GitHub stars (Nov 22) | Shape | Notes |
|---|---|---|---|
| claude-code-router | 38,295 | Claude Code traffic to local router, router to OpenAI-compatible upstreams | Purpose-built; per-request model routing rules |
| LiteLLM proxy | 63,671 on the main repo, last push Nov 22 | Unified OpenAI-format proxy with an Anthropic-compatible frontend | Virtual keys, budgets, spend tracking; heavier footprint |
The router terminates the agent's Anthropic dialect, forwards completions to your chosen backend, and gives you one choke point for logging and key rotation. That choke point is where the security value concentrates. We have written the gateway hardening checklist for LiteLLM already: pin the deployment version, issue virtual keys per engagement, and log at the proxy rather than trusting upstream dashboards.
What actually breaks in production
| Failure | Symptom | Cause | Fix |
|---|---|---|---|
| Tool-call JSON drift | Agent emits malformed arguments mid-run | Backend formats function arguments differently across turns | Schema-strict parsing in the harness, retry-on-malformed loop, canary assertions |
| Streaming delta mismatch | UI renders garbage or stalls | SSE chunk shapes differ between dialects | Terminate streaming at the router, or test SSE explicitly before rollout |
| Caching semantics gap | Bill triples on long sessions | Anthropic caching uses explicit cache_control blocks; OpenAI-compatible endpoints cache implicitly | Measure hit rate before and after the switch; the math is in our prompt caching cost analysis |
| Context truncation | Sessions compact or drop context early | Unrecognized gateway alias IDs get assumed context windows | Use recognized IDs or size the alias mapping explicitly at the router |
| Silent model swap | Output quality shifts week to week | Upstream provider changes weights behind the same name | Run the five-probe canary suite on a schedule |
The last row deserves emphasis in this market. Reduced-refusal providers re-quantize, re-merge, and swap base revisions behind unchanged model names, and the only reliable detection is behavioral: fixed prompts, fixed seeds where supported, and probes whose answers you have fingerprinted.
The security checklist most tutorials skip
Your agent context is an engagement digest. It contains source code under test, hostnames, sometimes credentials that slipped into a file the agent read, and your exploit reasoning. Everything in that context goes to the base URL. Before the first session:
- Scope the key. One API key per engagement, revoked at the end. Never reuse a personal long-lived key in agent config.
- Log at your choke point. Router or gateway logs give you the audit trail an upstream dashboard cannot, and you control retention.
- Keep tokens out of CI and dotfiles. The wfx-loot campaign drained 4,837 GitHub accounts and explicitly harvested AI-provider credential patterns from runner environments; agent tokens belong in a secret manager, full stop.
- Pin the egress. Resolve your base URL, know which networks receive engagement data, and treat a provider's region and retention policy as part of your engagement paperwork.
- Stay inside authorization. Reduced-refusal backends widen what the model will discuss; the acceptable use policy still bounds what you point it at.
Tiers for agent workloads
Model choice per workload, using the public lineup on this site:
| SKU | Input / output per 1M tokens | Cached input | Agent workload |
|---|---|---|---|
| unst33r-deepseek | $0.15 / $0.5625 | $0.03125 | Repo-wide analysis and scan triage across 1M-token contexts, the cheapest loop for bulk code review |
| unst33r-flash | $0.50 / $1.50 | none published | Fast tool loops: recon scripting, fuzzing harness iteration, one-shot file edits |
| unst33r-pro | $2.50 / $4.50 | none published | Exploit development and chain reasoning where output quality dominates cost |
The longer decision walkthrough, including refusal-behavior tradeoffs per tier, is in which model tier for which security workload. A working pattern for heavy engagements: deepseek for the read-everything passes, pro for the write-the-exploit passes, with the router directing traffic between them per request.
The base URL is the control point of an agent stack. Set it deliberately, log what crosses it, and canary what answers behind it.