- 新增 CLAUDE_CONSOLE_BLOCKED_HANDLING_MINUTES 配置项,自动处理账户临时禁用的 400 错误(如 "organization has been disabled"、"too many active sessions" 等)。
- 添加 errorSanitizer 工具模块,自动清理上游错误响应中的供应商特定信息(URL、供应商名称等),避免泄露中转服务商信息。
- 统一调度器现在会主动检查并恢复已过期的封禁账户,确保账户在临时封禁时长结束后可以立即重新使用。
- Created new src/routes/unified.js (225 lines)
- detectBackendFromModel(): Detects backend from model name
- routeToBackend(): Routes to Claude/OpenAI/Gemini with permission checks
- POST /v1/chat/completions: OpenAI-compatible endpoint with intelligent routing
- POST /v1/completions: Legacy completions endpoint with intelligent routing
- Updated src/routes/api.js (reduced from 1185 to 968 lines)
- Removed ~217 lines of routing logic
- Kept Claude-specific endpoints (/api/v1/messages)
- Maintained all other Claude API functionality
- Updated src/app.js
- Added unifiedRoutes registration at /api prefix
Benefits:
- Single responsibility: api.js focuses on Claude API routes
- Better organization: routing logic isolated in unified.js
- Easier maintenance: changes to routing won't affect Claude code
- File size reduction: api.js reduced by 18%
Tested:
- ✅ Claude model routing via /v1/chat/completions
- ✅ OpenAI model routing (correct backend detection)
- ✅ Gemini model routing (correct backend detection)
- ✅ Legacy /v1/completions endpoint
- ✅ All tests pass, no regressions
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add modelService for centralized model management
- Support dynamic model list from config file (data/supported_models.json)
- Include 2025 latest models: GPT-4.1, o3, o4-mini, Gemini 2.5, etc.
- File watcher for hot-reload configuration changes
- Improve model detection logic in api.js
- Priority: modelService lookup → prefix matching fallback
- Smart backend routing based on model provider
- Add intelligent routing endpoints
- /v1/chat/completions: unified OpenAI-compatible endpoint
- /v1/completions: legacy format support
- Auto-route to Claude/OpenAI/Gemini based on requested model
- Add Xcode system prompt support in openaiToClaude
- Detect and preserve Xcode-specific system messages
- Export handler functions for reuse
- openaiClaudeRoutes: export handleChatCompletion
- openaiRoutes: export handleResponses
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add dedicated API endpoint to fetch Claude account OAuth usage data
asynchronously, improving user experience by eliminating the need for
multiple page refreshes to view session window statistics.
Backend changes:
- Add GET /admin/claude-accounts/usage endpoint for batch fetching
- Implement fetchOAuthUsage() to call Claude API /api/oauth/usage
- Add buildClaudeUsageSnapshot() to construct frontend data structure
- Add updateClaudeUsageSnapshot() to persist data to Redis
- Add _toNumberOrNull() helper for safe type conversion
- Update getAllAccounts() to return claudeUsage from Redis cache
Data structure:
- Store three window types: 5h, 7d, 7d-Opus
- Track utilization percentage and reset timestamps
- Calculate remaining seconds for each window
Performance optimizations:
- Concurrent batch requests using Promise.allSettled
- Graceful error handling per account
- Non-blocking async execution