Anthropic Messages API facade — native Claude SDK compatibility

2026-03-15

apirouteridentity-bridge

What We Built

BrainstormRouter now accepts requests in Anthropic Messages API format via POST /v1/messages. This endpoint runs through the exact same pipeline as /v1/chat/completions — same BYOK, budget, guardian, guardrails, tool firewall, audit, and routing — but translates between Anthropic and OpenAI formats at the boundary. Streaming and non-streaming are both supported.

Alongside the facade, we fixed three Identity Bridge issues: tenant.claimed event payload now falls back to direct tenant table queries when membership resolution returns empty metadata, revokePendingTokens() is wired before claim token generation, and RBAC entries for all identity bridge routes are confirmed present.

Why It Matters

Tools like the Claude for Excel/PowerPoint add-in, Anthropic's official SDKs, and custom integrations that speak the Anthropic Messages API can now connect to BrainstormRouter without any client-side format conversion. This is critical for enterprise adoption where teams use Anthropic tooling natively but want BrainstormRouter's routing, budget controls, and governance.

How It Works

The /v1/messages path is implemented as a middleware + shared handler pattern inside completionsRoute(). Pre-processing middleware translates the Anthropic body to OpenAI format and stores it as _parsedBody on the Hono context. The same handleCompletion function runs for both paths. Post-processing translates the response back:

  • Non-streaming: JSON response is translated via openAIToAnthropic()
  • Streaming: Response body is piped through a TransformStream that converts

OpenAI SSE events to Anthropic SSE events (message_start, content_block_delta, etc.)

Anthropic headers (anthropic-version, anthropic-beta) are captured from the inbound request, stored on the translated body as _anthropicHeaders, and forwarded upstream by the AnthropicAdapter when the request routes to Claude.

Cross-provider routing works: you can send "model": "openai/gpt-4o" via /v1/messages and get back an Anthropic-format response.

The Numbers

  • 19 deterministic protocol tests covering request translation, response translation, and SSE streaming
  • 0 additional latency from translation (pure JSON manipulation, no I/O)
  • Same X-BR-* headers on both endpoints (full pipeline parity verified)

Competitive Edge

Neither Portkey nor OpenRouter offer a native Anthropic Messages API facade that runs through a full governance pipeline. They accept OpenAI format only, forcing Anthropic-native tools to use format adapters. BrainstormRouter accepts both formats natively with zero behavioral divergence.

Lockstep Checklist

  • [x] API Routes: src/api/routes/completions.ts updated with /v1/messages handler.
  • [x] TS SDK: packages/sdk-tsMessages resource with create() method, types exported.
  • [x] Python SDK: packages/sdk-pyMessages + AsyncMessages resources with create() method.
  • [x] MCP Schemas: Not applicable (completions not exposed as MCP tool).
  • [ ] Master Record: Deferred — no new capability system, just a new access path.