feat(proxy): serve the Anthropic Messages API#170
Open
OnlyTerp wants to merge 6 commits into
Open
Conversation
added 6 commits
July 1, 2026 22:30
Collaborator
|
Solid translation layer — clean state machine, real tests, and the live Claude Code validation is convincing. One blocker: main inlined |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes Local Studio a native
ANTHROPIC_BASE_URLtarget — the integration llama.cpp (Jan 2026), Ollama, and LM Studio all shipped this year because Claude Code and other Anthropic-wire-protocol agents became the default way people use local models for real work.POST /v1/messages— translates Anthropic requests to OpenAI internally (llama.cpp's approach) and forwards to the running backend, so it works for every engine. Handles: system (string or blocks), text/image(base64+url)/tool_use/tool_result content blocks, tools + tool_choice (auto/any/tool), stop_sequences, temperature/top_p.message_start→content_block_start/delta/stop→message_delta→message_stop) translated from OpenAI chunks by a pure state machine, includinginput_json_deltafor streamed tool calls and text→tool block transitions. 15spingkeepalive (same Cloudflare-prefill rationale as the OpenAI path).POST /v1/messages/count_tokens— flattens the request and tokenizes upstream, with a fallback chain (/tokenize→ TabbyAPI's/v1/token/encode)./v1/messagesare recorded by the existing inference accounting — per-model requests, tokens, TTFT show up in the usage page. None of the other local Anthropic endpoints have this.{type:"error",error:{...}}), and the model-not-running guard behaves exactly like the OpenAI route (proxy never launches models).Live validation — RTX 5090, TabbyAPI/ExLlamaV3 backend (branch of #168)
/v1/messages: correct message shape,stop_reasonmappingmessage_deltacarried real usage ({"input_tokens":39,"output_tokens":19})count_tokens:{"input_tokens":27}via the TabbyAPI fallbackllama32-1b-exl3 | requests: 3 | tokens: 27171 | avg TTFT 931msTest plan
bun run typecheck,node scripts/validate-shared-contracts.mjscheck:qualitygateNote: fresh-clone
npm ci(without--legacy-peer-deps) currently fails on main — the frontend lockfile looks out of sync with the pinned deps;npm installresolves. Happy to PR the regenerated lockfile separately if wanted.