Skip to content
LUNAROUTEDocs

Messages (Anthropic)

POST /v1/messages speaks the Anthropic Messages shape, so an Anthropic client can route through LunaRoute by changing its base URL and key.

Terminal window
curl https://gw.lunaroute.com/v1/messages \
-H "LUNAROUTE-API-KEY: $LUNAROUTE_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "glm-5.3",
"max_tokens": 256,
"messages": [{"role": "user", "content": "hello"}]
}'

POST /v1/messages/count_tokens counts input tokens for the same shape.

Use the LUNAROUTE-API-KEY header. Authorization: Bearer lr_… and x-api-key: lr_… are also accepted when the value is lr_-prefixed — which means an Anthropic client configured with x-api-key works unchanged.

Claude Code authenticates with a Bearer token instead: lunaroute setup claude-code exports ANTHROPIC_AUTH_TOKEN (LunaRoute authenticates the lr_ key at the edge and strips the header before forwarding).

The MCP server is a separate step — lunaroute setup claude-code does not register it. Add it with lunaroute skill install, or see MCP server.

text, image, tool_use and tool_result blocks are carried to every model. Two Anthropic block types reach the model with a caveat:

  • document — a text payload (source.type: "text", or a base64 source whose media_type is text/*) is inlined as text with a [document: …] label. A PDF has no representation on an OpenAI-dialect model, so it is refused with 400 and error.code: "unsupported_request" naming the media type; send the text instead.
  • fallback — the server-side-fallback handoff marker carries no content of its own. It is dropped (the drop is logged as a translation warning) so an echoed turn keeps working.

Inside a tool_result, a PDF or other non-text document becomes a short placeholder and a warning, the same way images already do: OpenAI tool messages are text-only, and rejecting the turn would break every later turn of the session.

Background model variants and project attribution work exactly as in Chat completions. Both /v1/messages and /v1/responses route to the same models as /v1/chat/completions.