mirror of
https://github.com/justlovemaki/AIClient-2-API.git
synced 2026-04-25 17:35:58 +03:00
[GH-ISSUE #98] 刷新Token失败:Token refresh failed: Request failed with status code 401 #83
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/AIClient-2-API-justlovemaki#83
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kuangquanshuisn on GitHub (Dec 5, 2025).
Original GitHub issue: https://github.com/justlovemaki/AIClient-2-API/issues/98
现象
使用本地最新的kiro-auth-token.json上传到服务器运行AIClient-2-API,可以在CC中使用。
过一段时间(1-2小时)以后,在CC中使用就报错,重启2api应用以后,CC使用还是报错。
异常日志
`[Config] Ignoring invalid MODEL_PROVIDER in path segment: v1
[ProviderPoolManager] No available and healthy providers for type: claude-kiro-oauth
[API Service] No healthy provider found in pool for claude-kiro-oauth. Falling back to main config.
[Adapter] getServiceAdapter, provider: claude-kiro-oauth, uuid: undefined
[Request Convert] Request format matches backend provider. No conversion needed.
[Content Generation] Model: claude-sonnet-4-5-20250929, Stream: false
[ProviderPoolManager] No available providers for type: claude-kiro-oauth that support model: claude-sonnet-4-5-20250929
[API Service] No healthy provider found in pool for claude-kiro-oauth supporting model: claude-sonnet-4-5-20250929. Falling back to main config.
[Adapter] getServiceAdapter, provider: claude-kiro-oauth, uuid: undefined
[Content Generation] Re-selected service adapter based on model: claude-sonnet-4-5-20250929
[System Prompt Manager] System prompt updated in file for provider 'claude'.
[Kiro] Expiry date: 1764872613672, Current time: 1764911676136, 15 minutes from now: 1764912576136
[Kiro] Token is near expiry, refreshing before generateContent request...
[Kiro Auth] Attempting to load credentials from directory: /home/user/AIClient-2-API
[Kiro Auth] Successfully loaded OAuth credentials from /home/user/AIClient-2-API/kiro-auth-token.json
[Kiro Auth] Loaded Client credentials from config.json
[Kiro Auth] Loaded Client credentials from package-lock.json
[Kiro Auth] Loaded Client credentials from package.json
[Kiro Auth] Loaded Client credentials from provider_pools.json
[Kiro Auth] Loaded Client credentials from token-store.json
[Kiro Auth] Token refresh failed: Request failed with status code 401
[Server] Error during unary processing: Error: Token refresh failed: Request failed with status code 401
at KiroApiService.initializeAuth (file:///home/user/AIClient-2-API/src/claude/claude-kiro.js:505:19)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async KiroApiService.generateContent (file:///home/user/AIClient-2-API/src/claude/claude-kiro.js:1061:13)
at async handleUnaryRequest (file:///home/user/AIClient-2-API/src/common.js:268:32)
at async handleContentGenerationRequest (file:///home/user/AIClient-2-API/src/common.js:417:9)
at async handleAPIRequests (file:///home/user/AIClient-2-API/src/api-manager.js:52:13)
at async Server.requestHandler (file:///home/user/AIClient-2-API/src/request-handler.js:129:32)
[ProviderPoolManager] Invalid providerConfig in markProviderUnhealthy`
环境
系统:unbuntu
登录方式:Builder ID
cc版本:v2.0.58
是否vps:是
启动脚本:sh install-and-run.sh
config.js内容如下:
{ "REQUIRED_API_KEY": "sk-123456", "SERVER_PORT": 3000, "HOST": "127.0.0.1", "MODEL_PROVIDER": "claude-kiro-oauth", "OPENAI_API_KEY": "xxx", "OPENAI_BASE_URL": "https://openai/v1", "CLAUDE_API_KEY": "xxx", "CLAUDE_BASE_URL": "https://anthropic/v1", "PROJECT_ID": null, "GEMINI_OAUTH_CREDS_BASE64": null, "GEMINI_OAUTH_CREDS_FILE_PATH": null, "KIRO_OAUTH_CREDS_BASE64": null, "KIRO_OAUTH_CREDS_FILE_PATH": "/home/user/AIClient-2-API/kiro-auth-token.json", "QWEN_OAUTH_CREDS_FILE_PATH": null, "SYSTEM_PROMPT_FILE_PATH": "input_system_prompt.txt", "SYSTEM_PROMPT_MODE": "overwrite", "PROMPT_LOG_BASE_NAME": "prompt_log", "PROMPT_LOG_MODE": "none", "REQUEST_MAX_RETRIES": 3, "REQUEST_BASE_DELAY": 1000, "CRON_NEAR_MINUTES": 15, "CRON_REFRESH_TOKEN": false, "PROVIDER_POOLS_FILE_PATH": null, "MAX_ERROR_COUNT": 3 }@justlovemaki commented on GitHub (Dec 5, 2025):
google和github注册的号不支持轮询
@kuangquanshuisn commented on GitHub (Dec 5, 2025):
我是用Builder ID账号登陆的,没用google和github号。不支持轮询是什么意思,就是一个账号在用。
@kuangquanshuisn commented on GitHub (Dec 6, 2025):
已经发现问题:在 BuilderId 登录方式下(authMethod=IdC),系统会使用 clientId 和 clientSecret 刷新凭证。 kiro-auth-token.json原始文件中不包含 clientId 和 clientSecret 属性,导致凭证刷新失败。用户需要从 ~/.aws/sso/cache 目录下的其他 JSON 文件中复制这两个属性到 kiro-auth-token.json 文件中。https://github.com/justlovemaki/AIClient-2-API/pull/99#issue-3700844082
@justlovemaki commented on GitHub (Dec 6, 2025):
BuilderId 登录的有两个文件,放在同一目录下,两个文件都会读取。可以刷新token,client文件需要半年后手动刷新。
PR我就关了。
@kuangquanshuisn commented on GitHub (Dec 6, 2025):
在vps上部署AIClient-2-API时,readme文档以及config.json只提到要指定kiro-auth-token.json,没说上传另外一个文件。这个是否要在文档里面说一下。现有的异常日志(上面贴了日志)只提示刷新token失败,不知道为什么失败,我是困惑了几天,查了源码才发现还要使用clientId 和 clientSecret 属性。另外,使用账号池时,也只是上传了kiro-auth-token.json,可能也会有刷新token失败的问题。如果有日志提示,可以快速定位问题。
`[Kiro Auth] Attempting to load credentials from directory: /home/user/AIClient-2-API
[Kiro Auth] Successfully loaded OAuth credentials from /home/user/AIClient-2-API/kiro-auth-token.json
[Kiro Auth] Loaded Client credentials from config.json
[Kiro Auth] Loaded Client credentials from package-lock.json
[Kiro Auth] Loaded Client credentials from package.json
[Kiro Auth] Loaded Client credentials from provider_pools.json
[Kiro Auth] Loaded Client credentials from token-store.json
[Kiro Auth] clientId not found in credentials.
[Kiro Auth] clientSecret not found in credentials.
[Kiro Auth] Token refresh failed: Request failed with status code 401
[Server] Error during unary processing: Error: Token refresh failed: Request failed with status code 401
at KiroApiService.initializeAuth (file:///home/user/AIClient-2-API/src/claude/claude-kiro.js:511:19)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async KiroApiService.generateContent (file:///home/user/AIClient-2-API/src/claude/claude-kiro.js:1067:13)
at async handleUnaryRequest (file:///home/user/AIClient-2-API/src/common.js:268:32)
at async handleContentGenerationRequest (file:///home/user/AIClient-2-API/src/common.js:417:9)
at async handleAPIRequests (file:///home/user/AIClient-2-API/src/api-manager.js:52:13)
at async Server.requestHandler (file:///home/user/AIClient-2-API/src/request-handler.js:129:32)`
@justlovemaki commented on GitHub (Dec 6, 2025):
账号池时,上传的kiro-auth-token.json可以把clientId 和 clientSecret 属性加进去,合并到一个文件中