feat: native Anthropic pass-through for Claude models (#38)#48
Merged
Conversation
- H1: Remove dead [DONE] sentinel from native SSE loop (Anthropic terminates via connection close) - H3: Conditionally set accept: text/event-stream only when streaming - M1: buildUpstreamPayload returns rest (not payload) when thinking absent, stripping output_config - M2: Truncate raw SSE data to 200 chars in warn log to prevent log injection - L2: Remove claude_ underscore prefix heuristic (no known Anthropic model uses it) - L3: Document >= 7 threshold comment in isAdaptiveThinkingModel - L4: Replace verbose JSDoc on nativeAnthropicModelIds with concise standard form - Export buildUpstreamPayload for direct unit testing - Add tests/native-passthrough.test.ts with T1-T9 covering payload transform and model routing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
4 tasks
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
Route Anthropic
/v1/messagesrequests for Claude models directly to GitHub Copilot's native Anthropic endpoint, bypassing the OpenAI translation layer. This preserves:thinkingblocks withsignaturefield (required for multi-turn reasoning)cache_creation_input_tokensin usagetop_kparametercache_controlon system/user blocksChanges
src/services/copilot/create-messages-native.ts(new) — POSTs Anthropic payloads directly to${copilotBaseUrl}/v1/messages; stripsopenai-intentheader; auto-upgrades{ type: "enabled" }→{ type: "adaptive" }for claude-opus-4.7+ modelssrc/services/copilot/native-models.ts(new) —isNativeAnthropicModel()checksstate.modelsvendor field first, falls back toclaude-prefix heuristicsrc/routes/messages/handler.ts— dispatch logic: Claude → native path, everything else → translation path;manualApprovegate moved before dispatch so both paths are gatedsrc/routes/messages/anthropic-types.ts—signature?onAnthropicThinkingBlock; unionthinkingtype for adaptive;output_config;AnthropicImageBlockURL source;AnthropicToolResultBlock.contentwidenedsrc/routes/messages/non-stream-translation.ts— imagesource.type === "base64"narrowing; updated commenttests/native-passthrough.test.ts(new) — 19 tests coveringbuildUpstreamPayload(T1–T6 incl. empty output_config),isNativeAnthropicModel(T5–T9), andisAdaptiveThinkingModelboundaries (B1–B6: 4.6/4.7/4.8, dot/dash separator, non-opus, multi-digit)Test plan
bun test)claude-sonnet-4-5) request routes to native pathgpt-4o) routes to translation pathclaude-opus-4.7+with legacy thinking auto-upgraded to adaptive formatCloses #38, #44, #45
🤖 Generated with Claude Code