Skip to content

Commit 941bcbd

Browse files
Simple6Klizk172
authored andcommitted
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.
1 parent 5c107e5 commit 941bcbd

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/services/api/claude.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,30 @@ export function getAPIMetadata() {
509509
}
510510
}
511511

512+
const deviceId = getOrCreateUserID()
513+
514+
// Third-party API providers (DeepSeek, etc.) validate user_id against
515+
// ^[a-zA-Z0-9_-]+$ which rejects JSON strings containing {, ", :, etc.
516+
// When using a non-Anthropic base URL, send only the device_id (hex string).
517+
const baseUrl = process.env.ANTHROPIC_BASE_URL
518+
const isThirdParty =
519+
baseUrl &&
520+
(() => {
521+
try {
522+
return new URL(baseUrl).host !== 'api.anthropic.com'
523+
} catch {
524+
return false
525+
}
526+
})()
527+
528+
if (isThirdParty) {
529+
return { user_id: deviceId }
530+
}
531+
512532
return {
513533
user_id: jsonStringify({
514534
...extra,
515-
device_id: getOrCreateUserID(),
535+
device_id: deviceId,
516536
// Only include OAuth account UUID when actively using OAuth authentication
517537
account_uuid: getOauthAccountInfo()?.accountUuid ?? '',
518538
session_id: getSessionId(),

0 commit comments

Comments
 (0)