mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 12:55:51 +00:00
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.
This commit is contained in:
@@ -509,10 +509,30 @@ export function getAPIMetadata() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deviceId = getOrCreateUserID()
|
||||||
|
|
||||||
|
// Third-party API providers (DeepSeek, etc.) validate user_id against
|
||||||
|
// ^[a-zA-Z0-9_-]+$ which rejects JSON strings containing {, ", :, etc.
|
||||||
|
// When using a non-Anthropic base URL, send only the device_id (hex string).
|
||||||
|
const baseUrl = process.env.ANTHROPIC_BASE_URL
|
||||||
|
const isThirdParty =
|
||||||
|
baseUrl &&
|
||||||
|
(() => {
|
||||||
|
try {
|
||||||
|
return new URL(baseUrl).host !== 'api.anthropic.com'
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
|
if (isThirdParty) {
|
||||||
|
return { user_id: deviceId }
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user_id: jsonStringify({
|
user_id: jsonStringify({
|
||||||
...extra,
|
...extra,
|
||||||
device_id: getOrCreateUserID(),
|
device_id: deviceId,
|
||||||
// Only include OAuth account UUID when actively using OAuth authentication
|
// Only include OAuth account UUID when actively using OAuth authentication
|
||||||
account_uuid: getOauthAccountInfo()?.accountUuid ?? '',
|
account_uuid: getOauthAccountInfo()?.accountUuid ?? '',
|
||||||
session_id: getSessionId(),
|
session_id: getSessionId(),
|
||||||
|
|||||||
Reference in New Issue
Block a user