Blog

CArouter now speaks Anthropic's Messages API

Applications built on an Anthropic SDK, and coding agents such as Claude Code, can now reach the models of our catalog by changing one address. The key, the safeguards and the bill stay the same.

ProductBy Flavien Berwick
New feature: CArouter now speaks Anthropic's Messages API, at POST /v1/messages. An application on an Anthropic SDK changes its base URL, Claude Code changes ANTHROPIC_BASE_URL in its settings, and a model of the catalog answers. Prompts, tools and streaming code do not change. Same key and bill, same residency rules, same privacy tools.

AI applications are written against one of two interfaces: OpenAI's, which CArouter has answered since its first day, or Anthropic's Messages API. A team that built on the second had to rewrite its calls to use us, and a tool that speaks only that one, such as the coding agent Claude Code, could not reach us at all. CArouter now answers the Messages API too, at /v1/messages.

The models that answer are those of our catalog, served by Canadian-owned providers unless you decide otherwise. The route does not add Claude models. It lets the tools written for them work with ours.

An application on an Anthropic SDK moves by changing two lines

If your application uses one of Anthropic's SDKs, give it CArouter's address and a CArouter key. The messages, the system prompt, your own tools, the streamed answer and the errors keep the shape your code already handles.

from anthropic import Anthropic

client = Anthropic(
    base_url="https://carouter.ai",      # was Anthropic's address
    api_key="$CAROUTER_API_KEY",         # was an Anthropic key
)

message = client.messages.create(
    model="<a chat model from carouter.ai/docs>",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Bonjour!"}],
)
print(message.content[0].text)

This is useful when an application already in production has to run on a model hosted in Canada, for a client, a regulator or a pilot: the test takes an afternoon, not a rewrite, and the same code keeps working against both.

Before release we ran Anthropic's official Python SDK against the route: a plain answer, a streamed one, a tool call followed by its result, a token count and the SDK's typed errors.

A coding agent that follows your residency rules

A coding agent reads your source files, your configuration and sometimes your secrets, and sends them to a model at every step. For a team under a residency requirement, that is often why the agent is not allowed at all.

Claude Code accepts another address in its settings file, and that address can now be CArouter. The agent still runs on your machine, and what it reads goes to a model of our catalog under your workspace's residency rules, which allow Canadian-owned providers only until you change them.

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://carouter.ai",
    "ANTHROPIC_AUTH_TOKEN": "<your CArouter key>",
    "ANTHROPIC_MODEL": "<a model that calls tools>",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "<the same, or a smaller one>"
  }
}

The Claude Code tab of our documentation writes this block for your workspace, with a model your keys can reach and its real context window, which Claude Code would otherwise guess.

Two things to know before you rely on it:

  • Claude Code is written for Claude models, and Anthropic does not support running it on others. How well a session goes depends on the model, so choose one that calls tools reliably and try it on your own work first. In our test before release, Claude Code read a file with its own tool and answered from it through the route.
  • The tools Anthropic runs on its own servers, web search among them, are not available through us. The tools that run on your machine, such as reading and editing files or running commands, are passed to the model like any tool of your own.

Any other tool that lets you set the address of an Anthropic-compatible API can be pointed at CArouter the same way, within the limits listed below.

The same safeguards and the same bill

A request that arrives in Anthropic's format is translated into the one the rest of CArouter works in before anything else reads it. Everything you have already set up therefore applies, with nothing to configure a second time:

  • Residency: your provider permissions and border controls decide who may answer, as on every other route.
  • Privacy tools: the PII filter and the content filter set on an API key read these requests too, and a key that requires a filter is still refused when the filter is unavailable.
  • One key, one bill: your existing API key works, sent the way Anthropic's tools send it. Each request appears in Usage as Messages, with its cost.
  • Reliability: a request moves to another provider when the first one fails, as on the chat route. While a model prepares a long answer, the route sends the keep-alive signal Anthropic's tools expect, so they do not hang up.

What the route does not do

  • Thinking budgets and effort settings are accepted and not passed on. Each model reasons by its own defaults, and its reasoning comes back in the form Anthropic's tools read.
  • Refused, with a message that says why: the tools Anthropic defines or runs itself (web search, code execution, computer use), its MCP connector, PDF documents and files uploaded to Anthropic.
  • Message batches and file uploads have no route here.

Open the documentation and its Claude Code tab. Read the route's technical reference.