Skip to content
Claude through the AI gateway

Task guides

Claude through the AI gateway

ts
import Anthropic from "@anthropic-ai/sdk";const client = new Anthropic({  baseURL: process.env.AI_GATEWAY_URL,  apiKey: process.env.AI_GATEWAY_TOKEN,});const { data: message, response } = await client.messages  .create({    model: "claude-opus-5-5",    max_tokens: 16000,    messages: [{ role: "user", content: "Summarise this shipment note." }],  })  .withResponse();const usage = JSON.parse(response.headers.get("x-spaceboy-usage") ?? "{}");console.log(message.stop_reason, usage.costUsd);

A deployed app calls Anthropic's Claude models through the platform's AI gateway with no Anthropic account. The gateway's /messages route (also /v1/messages, the SDK's path) speaks the Anthropic Messages API, so the official SDK works unchanged: base URL AI_GATEWAY_URL, API key AI_GATEWAY_TOKEN. Both are set on deployed environments of projects with the AI capability that run on the gateway (the default, unless both your own OpenAI and ElevenLabs keys are connected). Local runs and sandboxes do not have them. Calls are billed from the organization's prepaid credits.

Models and prices

Anthropic's list prices in US dollars per million tokens, no markup:

ModelInputOutput
claude-fable-5-28.0040.00
claude-opus-5-54.0020.00
claude-sonnet-5-52.0010.00
claude-haiku-5-5, prompt up to 100K tokens0.100.50
claude-haiku-5-5, prompt over 100K tokens0.502.50

The prompt is input plus cache-write plus cache-read tokens; over 100K the whole Haiku request is billed at the higher rate. Prompt-cache reads and writes are both billed at the model's normal input rate, a deliberate simplification: cached reads cost more here than on your own Anthropic account, and cache writes a little less.

What the gateway forwards

  • The request body as you send it. The gateway checks only the model; fields it does not know are passed on, and Anthropic judges the rest (a missing max_tokens is Anthropic's own 400).
  • Your anthropic-version and anthropic-beta headers.
  • The response, streamed or not. A refusal is a normal response with stop_reason: "refusal"; check stop_reason and it is billed like any other.

What each call cost

Non-streamed responses carry an x-spaceboy-usage header. A stream ends with one extra event after message_stop:

text
event: spaceboy.usagedata: {"type":"spaceboy.usage","usage":{"endpoint":"MESSAGES","model":"claude-haiku-5-5","unit":"TOKENS","quantity":1500,"inputTokens":1000,"outputTokens":500,"costMicros":350,"costUsd":0.00035}}

inputTokens includes cache reads and writes; costMicros is what was debited, in millionths of a dollar. The SDK's stream helper passes the event through without using it, so finalMessage() still works; iterate the raw events to read it.

Errors

StatusCodeMeaning
400model_not_allowedNot one of the models above. Claude ids are also refused on the OpenAI routes.
401missing_token / invalid_tokenAI_GATEWAY_TOKEN missing or wrong; redeploy to refresh it.
402out_of_creditsTop up credits.
502upstream_key_rejectedPlatform-side key problem, not your request.
503gateway_not_configuredClaude is not enabled on this platform yet.

Anything else Anthropic returns (a 400 for a bad body, a 429) is passed through unchanged and not billed. Credits and billing: Pricing and billing.

For agents: /docs/agents/claude.md · llms.txt