Repository navigation
feat(upstream): add shared Claude Code client profile for custom upstreams - #802
Merged
Merged
Conversation
…upstreams Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…file defaults Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…aude Code requests Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…haping Claude Code requests Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…dropdown and dirty state Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…list into client-profiles Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…after upstream rebase Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…hropic Messages endpoint Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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
Some third-party relays and Claude Code pool resellers enforce Claude Code client checks:
User-Agent,X-Stainless-*,x-app,anthropic-beta, the billing header,metadata.user_id, and the identity system blocks. The wire mimicry that satisfies those checks lived only inside@floway-dev/upstream-claude-code, so a Custom upstream layered on top of such a relay had no way to reuse it.Extract the OAuth-independent Claude Code wire profile into the shared
@floway-dev/upstream/client-profileslayer, and expose it as an extensibleclientProfile?: 'claude-code'preset on Custom upstreams. The shared package owns request detection (isClaudeCodeShapedRequest,parseMetadataUserID), the pinned header surface (pickClaudeCodeHeaders,buildClaudeCodeReshapedHeaders,headersForClaudeCodeCountTokensCall), the inbound header allowlist, the Anthropic Messages mimicry chain (backfill required fields, synthesizemetadata.user_id, hoist caller system text, then inject the billing, identity, and cached template blocks), and the per-profile default flags.@floway-dev/upstream-claude-codedelegates to the same layer and keeps OAuth, quota, and account state provider-local.On a profiled Custom upstream, genuine Claude Code-shaped Messages requests pass through with their own system blocks,
anthropic-betaopt-ins, andmetadata.user_idintact. Other requests run the mimicry chain and receive the pinned header surface while caller-requested beta tokens are merged without duplicates, explicitingressHeadersRuleskeep override precedence, and headers admitted only for the profile do not leak into non-Messages protocols. The profile layersstrip-billing-attribution: falseandrewrite-disallowed-mid-conv-system-to-user: truebeneath operator and model flag overrides; explicitly enablingstrip-billing-attributionremoves the billing block and theclaude-code-20250219token from reshaped requests, and cached auto-model flags are recomputed when the profile changes.The dashboard adds a Client profile (
None/Claude Code) dropdown to Custom upstream settings withenandzh-Hansstrings, warns when the profile is selected without the Anthropic Messages endpoint, and reflects the profile's effective defaults in both the upstream and per-model flag editors.Verification
@floway-dev/upstream,@floway-dev/upstream-custom,@floway-dev/upstream-claude-code,@floway-dev/gateway, and@floway-dev/web.pnpm run build:web.Nonepersist.Verifypassed on1c4df73d2.