fix: third-party API user_id validation error (DeepSeek, etc.)#420
Conversation
When ANTHROPIC_BASE_URL points to a non-Anthropic endpoint (e.g.
DeepSeek), the JSON-formatted user_id containing {, ", : characters
fails validation against ^[a-zA-Z0-9_-]+$. Send only the hex device_id
for third-party providers.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
📝 WalkthroughWalkthroughThe PR refactors API metadata assembly in ChangesProvider-Aware API Metadata Assembly
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/services/api/claude.ts (1)
517-526: ⚡ Quick winUse the shared first-party URL helper to avoid drift
Line 517-Line 526 reimplements first-party detection with a host literal, while this file already uses
isFirstPartyAnthropicBaseUrl()(Line 1922). Reusing the shared helper keeps metadata and header behavior aligned.♻️ Proposed refactor
- const baseUrl = process.env.ANTHROPIC_BASE_URL - const isThirdParty = - baseUrl && - (() => { - try { - return new URL(baseUrl).host !== 'api.anthropic.com' - } catch { - return false - } - })() + const isThirdParty = + Boolean(process.env.ANTHROPIC_BASE_URL) && + !isFirstPartyAnthropicBaseUrl()🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/services/api/claude.ts` around lines 517 - 526, The function currently computes isThirdParty by parsing process.env.ANTHROPIC_BASE_URL and comparing host against 'api.anthropic.com' (using local logic with baseUrl and isThirdParty); replace that local first-party detection with a call to the shared helper isFirstPartyAnthropicBaseUrl() (invert its result to get isThirdParty) so the file uses the same canonical first-party logic as elsewhere (e.g., the usage at isFirstPartyAnthropicBaseUrl() on line ~1922), ensuring metadata and header behavior remain consistent; update any references to baseUrl/isThirdParty to rely on the helper's result.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/services/api/claude.ts`:
- Around line 517-526: The function currently computes isThirdParty by parsing
process.env.ANTHROPIC_BASE_URL and comparing host against 'api.anthropic.com'
(using local logic with baseUrl and isThirdParty); replace that local
first-party detection with a call to the shared helper
isFirstPartyAnthropicBaseUrl() (invert its result to get isThirdParty) so the
file uses the same canonical first-party logic as elsewhere (e.g., the usage at
isFirstPartyAnthropicBaseUrl() on line ~1922), ensuring metadata and header
behavior remain consistent; update any references to baseUrl/isThirdParty to
rely on the helper's result.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 178e0d65-2d99-4940-b5ad-b2a2a0baf07a
📒 Files selected for processing (1)
src/services/api/claude.ts
…rd-party-api-user-id fix: third-party API user_id validation error (DeepSeek, etc.)
When ANTHROPIC_BASE_URL points to a non-Anthropic endpoint (e.g. DeepSeek), the JSON-formatted user_id containing {, ", : characters fails validation against ^[a-zA-Z0-9_-]+$. Send only the hex device_id for third-party providers. 就是跳过用户id的输入。
Need help on this PR? Tag
@codesmithwith what you need.Summary by CodeRabbit