Repository navigation
feat: align CC Compatible requests with Claude CLI parity - #1419
diegosouzapw merged 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Claude Code compatibility layer to align with the latest Claude CLI (v2.1.113) wire image. Key changes include switching from x-api-key to Authorization: Bearer headers, hardcoding the Accept header to application/json, and refactoring request body construction for metadata, thinking, and output configuration. The dynamic billing header and several built-in system blocks were removed to match the official client's behavior. Feedback includes a suggestion to remove a redundant function call for effort resolution and a note regarding the potential impact of removing the hash truncation for the device ID.
|
|
||
| return { | ||
| ...outputConfig, | ||
| effort: resolveClaudeCodeCompatibleEffort(sourceBody, normalizedBody, model) || effort, |
There was a problem hiding this comment.
The call to resolveClaudeCodeCompatibleEffort is redundant here. The effort variable passed into this function is already the result of that same calculation performed in the caller (buildClaudeCodeCompatibleRequest at line 242). You can simplify this to just use the effort parameter directly.
| effort: resolveClaudeCodeCompatibleEffort(sourceBody, normalizedBody, model) || effort, | |
| effort: effort, |
| metadata.user_id = JSON.stringify({ | ||
| device_id: createHash("sha256") | ||
| .update(String(cwd || "")) | ||
| .digest("hex"), |
There was a problem hiding this comment.
The .slice(0, 24) was removed from the device_id generation. This changes the fingerprint from a 24-character string to a full 64-character SHA-256 hex string. If the upstream relay specifically expects a 24-character ID (which is common for some Anthropic-based client gating), this might cause requests to be rejected. Please confirm if the current Claude CLI indeed uses the full hash without truncation.
There was a problem hiding this comment.
Pull request overview
This PR updates the Claude Code (CC) compatible bridge to better match current Claude CLI wire behavior (auth/header fingerprinting) while preserving more Claude-native request fields and avoiding bridge-injected synthetic system/context blocks.
Changes:
- Switch CC-compatible auth/header profile to
Authorization: Bearer ...and update fingerprint ordering to match the stable Claude CLI API-key profile. - Stop rewriting request bodies with synthetic billing/CWD/date/context-management blocks; preserve caller-provided Claude-native fields (
thinking,output_config,metadata,max_tokens) with minimal defaults. - Expand Claude Code client detection so cache-control preservation recognizes modern
claude-cli/... (external, sdk-cli)user agents.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| open-sse/services/claudeCodeCompatible.ts | Updates CC-compatible header profile and request shaping to preserve Claude-native fields and remove synthetic blocks. |
| open-sse/config/cliFingerprints.ts | Adjusts CC-compatible fingerprint header/body field ordering for the new CLI parity profile. |
| open-sse/utils/cacheControlPolicy.ts | Recognizes modern Claude CLI user agents to preserve cache markers on deterministic routes. |
| tests/unit/executor-default-base.test.ts | Updates header expectations for CC-compatible auth and Accept behavior. |
| tests/unit/claude-code-compatible-request.test.ts | Updates request-building assertions to reflect preserved Claude-native fields and new system handling. |
| tests/unit/claude-code-compatible-helpers.test.ts | Updates helper tests for bearer auth headers and the trimmed beta set. |
| tests/unit/chatcore-translation-paths.test.ts | Updates chatCore translation expectations for CC-compatible upstream calls. |
| tests/unit/cc-compatible-provider.test.ts | Updates CC-compatible provider behavior expectations for headers and request body shape. |
| tests/unit/cache-control-policy.test.ts | Adds test coverage for modern claude-cli/... (external, sdk-cli) UA detection. |
| export const CLAUDE_CODE_COMPATIBLE_DEFAULT_CHAT_PATH = "/v1/messages?beta=true"; | ||
| export const CLAUDE_CODE_COMPATIBLE_DEFAULT_MODELS_PATH = "/models"; | ||
| export const CLAUDE_CODE_COMPATIBLE_DEFAULT_MAX_TOKENS = 8092; | ||
| export const CLAUDE_CODE_COMPATIBLE_DEFAULT_MAX_TOKENS = 64000; |
7443585
into
cheaper-inference:release/v3.6.9
Summary
messages,system,tools,thinking,output_config,metadata, andmax_tokensinstead of injecting bridge-owned billing/context blocksDetails
Authorization: Bearer ...and trim the default beta set to the stable Claude CLI API-key profilestream=true, but stop rewriting the request body with synthetic billing headers, CWD/date system prompts, andcontext_managementthinking,output_config,metadata, andmax_tokenswherever possible, only filling required defaults when they are absentclaude-cli/... (external, sdk-cli)user agents in cache preservation logic so Claude Code cache markers survive deterministic routesValidation
npx prettier --check open-sse/config/cliFingerprints.ts open-sse/services/claudeCodeCompatible.ts open-sse/utils/cacheControlPolicy.ts tests/unit/cache-control-policy.test.ts tests/unit/cc-compatible-provider.test.ts tests/unit/chatcore-translation-paths.test.ts tests/unit/claude-code-compatible-helpers.test.ts tests/unit/claude-code-compatible-request.test.ts tests/unit/executor-default-base.test.tsnpx eslint open-sse/config/cliFingerprints.ts open-sse/services/claudeCodeCompatible.ts open-sse/utils/cacheControlPolicy.ts tests/unit/cache-control-policy.test.ts tests/unit/cc-compatible-provider.test.ts tests/unit/chatcore-translation-paths.test.ts tests/unit/claude-code-compatible-helpers.test.ts tests/unit/claude-code-compatible-request.test.ts tests/unit/executor-default-base.test.tsnpm run typecheck:corenode --import tsx/esm --test tests/unit/claude-code-compatible-helpers.test.ts tests/unit/claude-code-compatible-request.test.ts tests/unit/cache-control-policy.test.ts tests/unit/executor-default-base.test.ts tests/unit/cc-compatible-provider.test.ts tests/unit/chatcore-translation-paths.test.ts tests/unit/provider-validation-specialty.test.tshttps://anyrouter.topwithcontext1m=true->200 OKhttps://www.openclaudecode.cnwithcontext1m=true->200 OK