Skip to content

feat(http): Anthropic Messages API at /v1/messages - #138

Merged
coyl merged 2 commits into
mainfrom
feat/anthropic-messages
Oct 28, 2026
Merged

coyl merged 2 commits into
mainfrom
feat/anthropic-messages

Conversation

@coyl

@coyl coyl commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Claude Code (ANTHROPIC_BASE_URL) and the Anthropic SDKs run through Keystone with a KTMS key. Experimental in 1.x.

  • POST /v1/messages turns a Messages request into the same GenerateText request as chat completions: routing, fallback, limits, guardrails, cache, X-KTMS-* headers and usage events are shared, and any vendor's answer is rendered as a Messages response.
  • Request: system (string or text blocks), text/image/document/tool_use/tool_result blocks, client tools with input_schema, tool_choice, max_tokens (required), metadata.user_id, the key in x-api-key or Authorization. Thinking and server-tool blocks in assistant turns are dropped; server tools are rejected with 400.
  • Streaming: message_start, ping, content_block_* (text_delta, input_json_delta), message_delta, message_stop; errors after the first byte are an error event.
  • Errors in the Messages shape with the HTTP statuses of the error table.
  • POST /v1/messages/count_tokens: an estimate, marked X-KTMS-Token-Count: estimate.
  • writeAPIError, the route headers and wrap are split so both formats share them; grpcapi.EstimateTokens is exported for message_start and count_tokens.

Checked live against a scripted OpenAI-compatible vendor behind KTMS: Claude Code 2.1.287 (claude -p, ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN) runs a session with streaming and a Bash tool call; the Python (2.3.0) and TypeScript (1.3.0) SDKs create, stream, send tool results, count tokens and raise typed errors unpatched; usage events in light-tokenmeter are the same as for chat completions.

Closes ai-process/docs#184

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedOct 28, 2026, 12:27 AM

Streamed tool calls open once their name is complete and send no null arguments, stream write
errors stop the vendor stream, mid-stream errors use the shared error mapping, count_tokens does
not fetch url sources, Claude Code's session-scoped user_id keeps its device or account as the
user, and budget estimates count tools and tool calls.
@coyl
coyl merged commit 08832a9 into main Oct 28, 2026
11 checks passed
@coyl
coyl deleted the feat/anthropic-messages branch October 28, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant