Anthropic · Node
The @anthropic-ai/sdk package accepts baseURL and apiKey on the client
constructor. Swap the base URL and your client.messages.create calls
route through the gateway.
Drop-in switch
const client = new Anthropic({
baseURL: "https://gateway.iq-routing.com",
apiKey: process.env.IQ_API_KEY,
});
The gateway exposes the Anthropic surface at /v1/messages; the SDK
appends /v1/messages itself when constructing the request URL. Pass the
gateway origin only.
Verify it routes
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://gateway.iq-routing.com",
apiKey: process.env.IQ_API_KEY!,
timeout: 60_000,
maxRetries: 0,
});
const response = await client.messages
.create({
model: "claude-haiku-5-5",
max_tokens: 64,
messages: [{ role: "user", content: "Summarise: routing-aware gateway." }],
})
.withResponse();
console.log("X-Request-Id:", response.response.headers.get("x-request-id"));
console.log(response.data.content[0]);
Drop into a fresh pnpm init project with @anthropic-ai/sdk. Set
IQ_API_KEY in your environment, run with npx tsx verify.ts.
Using capability aliases
Pass cap:<name> in the model field to request a capability; check
the x-iq-model response header for the dispatched or recorded model and
manage your workspace's overrides at /settings/capabilities.
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
baseURL: "https://gateway.iq-routing.com",
apiKey: process.env.IQ_API_KEY!,
});
const message = await anthropic.messages.create({
model: "cap:reason-heavy",
max_tokens: 1024,
messages: [{ role: "user", content: "Plan the migration in three phases." }],
});
Add .withResponse() to read the response headers, as in the Verify it
routes example. When routing telemetry is enabled, replies can also
include x-iq-routing with JSON fields such as chosen_model,
chosen_provider and cache_hit. See the capability aliases
docs for the full list of default capabilities and
how to override them. A workspace owner or admin can override the default
capability mapping in the editor at /settings/capabilities.
Common gotchas
The Node SDK retries some errors by default (see the Retries section
of the Anthropic TypeScript SDK README).
Set maxRetries: 0 to avoid burning attempts inside the cooldown window
and handle backoff in your own queue.
Streaming via client.messages.stream works transparently. The
MessageStream instance exposes .finalMessage() and event listeners that
match the direct-to-Anthropic shape exactly.
Tool use (the tools parameter on messages.create) works through the
gateway. When a non-Anthropic model serves the call, IQ translates the tools
to that provider's format. The gateway's tool_choice defaults
align with Anthropic's defaults so existing tool-using clients work
without behaviour changes.
The gateway forwards anthropic-beta identifiers to Anthropic and Claude
Bedrock, may normalize the comma-separated values or add required beta
identifiers, and omits them for other providers.
Browser usage is rejected by the SDK by default. The gateway's
recommended pattern is server-side: call the SDK from your own backend
with the gateway base URL; the gateway authenticates with your gw_live_
key, never the upstream Anthropic key.
The gateway allows up to 600 seconds per provider attempt and 1800 seconds across the fallback loop; streaming limits cover upstream stream readiness rather than the full token stream, so set an explicit client timeout if you need a shorter limit.
When the fallback chain runs out because providers are overloaded or
returning server errors, the gateway returns 503
(an overloaded_error in the Anthropic error body). That response
carries no Retry-After header, so back off on your own schedule.
IQ's own rate-limit and daily-budget 429s carry a Retry-After
hint; monthly-budget and spend-ceiling 429s do not. With maxRetries: 0, a caller-side
queue should read Retry-After when it is present and apply its own
backoff otherwise, including on the 503. Every error body on
this surface carries a request_id field for correlation against the
gateway's requests view.