Este artigo está disponível apenas em inglês.

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

PatternAgent speaksBackend speaksWhat you editWhen to use it
A. Native OpenAI-compatibleOpenAI chat completionsOpenAI chat completionsOPENAI_BASE_URL or client base_urlContinue, Cline, aider-style tools, your own scripts
B. Anthropic-nativeAnthropic messages APIAnthropic messages APIANTHROPIC_BASE_URL, ANTHROPIC_MODELClaude Code against an Anthropic-protocol gateway
C. Translation routerAnthropic messages APIOpenAI chat completionsRouter config plus ANTHROPIC_BASE_URL pointing at itClaude 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:

RouterGitHub stars (Nov 22)ShapeNotes
claude-code-router38,295Claude Code traffic to local router, router to OpenAI-compatible upstreamsPurpose-built; per-request model routing rules
LiteLLM proxy63,671 on the main repo, last push Nov 22Unified OpenAI-format proxy with an Anthropic-compatible frontendVirtual 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

FailureSymptomCauseFix
Tool-call JSON driftAgent emits malformed arguments mid-runBackend formats function arguments differently across turnsSchema-strict parsing in the harness, retry-on-malformed loop, canary assertions
Streaming delta mismatchUI renders garbage or stallsSSE chunk shapes differ between dialectsTerminate streaming at the router, or test SSE explicitly before rollout
Caching semantics gapBill triples on long sessionsAnthropic caching uses explicit cache_control blocks; OpenAI-compatible endpoints cache implicitlyMeasure hit rate before and after the switch; the math is in our prompt caching cost analysis
Context truncationSessions compact or drop context earlyUnrecognized gateway alias IDs get assumed context windowsUse recognized IDs or size the alias mapping explicitly at the router
Silent model swapOutput quality shifts week to weekUpstream provider changes weights behind the same nameRun 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:

  1. Scope the key. One API key per engagement, revoked at the end. Never reuse a personal long-lived key in agent config.
  2. Log at your choke point. Router or gateway logs give you the audit trail an upstream dashboard cannot, and you control retention.
  3. 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.
  4. 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.
  5. 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:

SKUInput / output per 1M tokensCached inputAgent workload
unst33r-deepseek$0.15 / $0.5625$0.03125Repo-wide analysis and scan triage across 1M-token contexts, the cheapest loop for bulk code review
unst33r-flash$0.50 / $1.50none publishedFast tool loops: recon scripting, fuzzing harness iteration, one-shot file edits
unst33r-pro$2.50 / $4.50none publishedExploit 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.