Repository navigation
Conversation
…ic endpoint tests - anthropicMessagesToOpenAI: tool_result blocks must convert to OpenAI 'tool' messages BEFORE the trailing user text (they answer the previous assistant tool_calls; strict OpenAI order otherwise). - export the pure converters for testability. - test/anthropic.test.js: 9 tests (converter unit tests + HTTP integration against a mock upstream: JSON mode, tool_use round-trip, SSE lifecycle, model fallback).
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.
What
Adds Anthropic Messages API compatibility to the relay without touching the OpenAI surface, so a single
baseURLworks for both client families at the same endpoint:POST /v1/chat/completions— OpenAI shape (unchanged)POST /v1/messages— Anthropic shape (new): message blocks (text,tool_use,tool_result),system(string or block array),tools[].input_schema,max_tokens/temperature/top_p,streamBoth route to the same free-tier upstream pipeline (fingerprint injection, tool bridging, quota tracking).
Why
A growing set of Anthropic-protocol clients (Claude Code and similar) assume the
POST /v1/messagescontract. Prior art for serving both dialects from one proxy:maxnowack/anthropic-proxy(★414) andAntonioAEMartins/claude-code-proxy;mizaawa/ZakoProxyCLIlikewise advertises Responses + Chat Completions + Messages. This change follows the same dual-shape pattern while keeping the relay pure-forwarding (no tool execution, no CLI/dialect side effects).Converter details
systemblocks flattened;toolsinput_schema→function.parameters; assistanttool_use→message.tool_calls; usertool_result→toolrole messages emitted before any trailing user text (they answer the previous assistanttool_calls; strict OpenAI ordering rejects text interleaved before tool results — this ordering bug is caught by the new tests).finish_reason→stop_reason(stop→end_turn,tool_calls→tool_use,length→max_tokens), usage mapped toinput_tokens/output_tokens,msg_…ids.message_start,content_block_start,content_block_delta,content_block_stop,message_delta,message_stop).x-api-key(Anthropic convention) or Bearer both accepted; documentedanthropic-versionheader accepted.OPENCODE_ANTHROPIC_MODELwhen an unknown model id is requested.Also in this branch
src/proxy-pool.js+upstream.js: optional egress proxy pool (PROXY_POOL_FILE) with automatic rotation + retry onFreeUsageLimitError(free-tier quota is partly IP-tied; rotation gives repeatable escapes).MAX_REQUEST_ATTEMPTSnow env-overridable.Tests
test/anthropic.test.js: converter unit tests + HTTP integration against a mock upstream (JSON mode, tool_use round-trip, Anthropic SSE lifecycle, model fallback).npm test)./v1/chat/completions, Anthropic sentinel via/v1/messages(JSON + SSE) on the same base URL.