# A Messages API surface for Claude Code and compatible models

> KeepRouter exposes an Anthropic-compatible /v1/messages route for supported chat models. Claude Code and the Anthropic SDK can point at the same base URL, while model-specific capabilities still require testing.

_Last reviewed 2026-08-15 · [Editorial review](https://keeprouter.com/editorial-policy#editorial-team)_

## The client-facing contract

Anthropic-style requests use `POST https://keeprouter.com/v1/messages`, an `x-api-key` header, and the required `anthropic-version` header. For Claude Code, set `ANTHROPIC_BASE_URL=https://keeprouter.com` and `ANTHROPIC_AUTH_TOKEN` to your KeepRouter key.

The [Claude Code guide](/use-cases/claude-code) provides the two-line setup and a current list of example model IDs. The live catalog—not the guide—is authoritative for route availability and price.

## Native shape, model-dependent behavior

The client sees the Messages request and response shape. Behind that surface, a configured route may relay Anthropic-format traffic or translate it to another compatible chat protocol. Translation can preserve common messages, streaming, and supported tool calls, but it cannot manufacture a provider-only capability that the selected model does not implement.

For a coding-agent workload, test these behaviors separately:

- system prompts and long conversation history;
- content blocks and tool-result continuation;
- streaming event order and terminal usage;
- extended-thinking or reasoning controls;
- image blocks if your workflow sends screenshots;
- model-specific context and output limits.

## Switching models in Claude Code

Claude Code accepts a model selection, but compatibility is more than accepting an ID. A replacement must support Messages traffic and the tool workflow your session uses. Start a fresh session for the evaluation, use the same repository state and task, then compare completion status, tool sequence, token counts, latency, and charge.

## Key and spend boundaries

Create a key that only allows the models approved for the coding workflow. Set a spend limit appropriate for automated loops, and cap output tokens in any direct API calls. A model switch should not silently expand the application's access to every catalog entry.

## When OpenAI format is a better fit

Use the OpenAI-compatible surface when your application is built around Chat Completions or Responses and does not need a Messages-native client. KeepRouter supports both client families so the interface choice can follow the application rather than the model maker's brand.

## Frequently asked questions

### Does Claude Code work with KeepRouter?

Yes. Point ANTHROPIC_BASE_URL at KeepRouter and use a KeepRouter key, then select a Messages-compatible catalog model.

### Can the Messages endpoint call non-Anthropic models?

It can call configured models that support the compatible Messages route. Capability parity is not implied; tools, vision, and reasoning must be tested.

### Is protocol translation visible to my client?

The client keeps the Messages shape. Errors or unsupported provider-specific features can still reveal behavioral differences, so handle them explicitly.

### Should I reuse one key for every coding agent?

Prefer separate scoped keys or clear per-application controls so spend and model access can be attributed and limited.

## Sources reviewed

1. [Anthropic Messages API](https://docs.anthropic.com/en/api/messages)
2. [Claude Code settings](https://docs.anthropic.com/en/docs/claude-code/settings)

## Related guides

- [claude code](https://keeprouter.com/use-cases/claude-code.md)
- [Can Claude Code use non-Claude models?](https://keeprouter.com/answers/can-claude-code-use-non-claude-models.md)
- [Compare Claude Code model costs without a static price snapshot](https://keeprouter.com/blog/cut-claude-code-costs.md)
- [API observability](https://keeprouter.com/features/api-observability.md)

## Connect Claude Code in two environment variables

Create a scoped key, open a fresh session, and measure one representative repository task.

[Create a free key](https://keeprouter.com/login?returnTo=%2Fconsole%2Fkeys%3Fmodel%3Dfree) · [Live models and pricing](https://keeprouter.com/models.md)
