sczheng189
f4f88091c1
feat: 扩展熔断机制支持所有5xx错误码
...
- 扩展错误检测从单一500错误到所有5xx错误码(500-599)
- 新增temp_error状态,连续3次5xx错误触发临时熔断
- 支持流式和非流式请求的统一5xx错误处理
- 添加定时清理机制,60分钟后自动恢复temp_error状态
- 完善错误计数和清理逻辑,提高系统可靠性
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-08-25 19:14:14 +08:00
shaw
b426a759a8
feat: 支持后台配置webhook
2025-08-23 20:20:32 +08:00
shaw
cb29b3f7e4
fix: 代理ip使用重构为统一方法
2025-08-20 23:21:32 +08:00
shaw
a45c832278
feat: 统一代理配置管理,支持IPv4/IPv6协议族选择
...
- 新增统一代理工具 ProxyHelper,支持 SOCKS5/HTTP/HTTPS 代理
- 添加 IPv4/IPv6 协议族配置选项,默认使用 IPv4 确保兼容性
- 移除 OpenAI 路由中硬编码的 family: 4 限制
- 统一 8 个服务文件中的代理创建逻辑,避免重复维护
- 支持 OAuth 和 token 交换过程中的代理使用
- 新增配置项:PROXY_USE_IPV4(默认 true)
- 向后兼容:现有配置无需手动更新
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-08-20 22:36:34 +08:00
shaw
77f80ef1f4
fix: claude token统计问题
2025-08-17 00:41:16 +08:00
shaw
4643e471ee
fix: 修复claude转发usage统计问题
2025-08-17 00:03:17 +08:00
shaw
681cb8cd82
feat: 优化 Claude 模型缓存费用计算,支持 5 分钟和 1 小时两种缓存类型
...
- 在 pricingService 中硬编码 1 小时缓存价格(Opus: $30/MTok, Sonnet: $6/MTok, Haiku: $1.6/MTok)
- 更新 usage 捕获逻辑以分别记录 ephemeral_5m 和 ephemeral_1h 缓存 tokens
- 改进费用计算逻辑,正确计算两种缓存类型的费用
- 新增 recordUsageWithDetails 方法支持详细的缓存数据
- 保持向后兼容性,支持旧的数据格式
- 删除测试脚本 test-openai-refresh.js
- 修复 OpenAI token 刷新逻辑
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-08-16 22:31:20 +08:00
shaw
31bdb4aa8c
feat: add comprehensive 401 error handling and account status management
...
- Add 401 error detection and automatic account suspension after 3 consecutive failures
- Implement account status reset functionality for clearing all error states
- Enhance admin interface with status reset controls and improved status display
- Upgrade service management script with backup protection and retry mechanisms
- Add mandatory code formatting requirements using Prettier
- Improve account selector with detailed status information and color coding
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-08-08 00:35:26 +08:00
千羽
8a74bf5afe
refactor: standardize code formatting and linting configuration
...
- Replace .eslintrc.js with .eslintrc.cjs for better ES module compatibility
- Add .prettierrc configuration for consistent code formatting
- Update package.json with new lint and format scripts
- Add nodemon.json for development hot reloading configuration
- Standardize code formatting across all JavaScript and Vue files
- Update web admin SPA with improved linting rules and formatting
- Add prettier configuration to web admin SPA
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-08-07 18:19:31 +09:00
andersonby
9a9a82c86f
feat: Add comprehensive Amazon Bedrock integration support
...
Add complete Amazon Bedrock integration to Claude Relay Service with:
## Core Features
- ✅ Bedrock account management with encrypted AWS credential storage
- ✅ Full request routing to AWS Bedrock with streaming support
- ✅ Integration with unified Claude scheduler system
- ✅ Support for Inference Profiles and Application Inference Profiles
- ✅ Configurable default and small-fast model settings
## Backend Services
- Add bedrockAccountService.js for account management
- Add bedrockRelayService.js for request forwarding
- Integrate Bedrock accounts into unifiedClaudeScheduler.js
- Update admin and API routes to support Bedrock endpoints
- Add comprehensive configuration options to config.example.js
## Frontend Integration
- Complete Vue.js Web UI for Bedrock account management
- Account creation form with AWS credentials and model configuration
- Real-time account status monitoring and statistics
- Edit/update capabilities for existing accounts
## CLI Support
- Interactive CLI commands for Bedrock account operations
- Account creation, listing, updating, and testing
- Status monitoring and connection validation
## Security & Performance
- AES encrypted storage of AWS credentials in Redis
- Support for temporary credentials (session tokens)
- Region-specific configuration support
- Rate limiting and error handling
This integration enables the relay service to support three AI platforms:
1. Claude (OAuth) - Original Claude.ai integration
2. Gemini - Google AI integration
3. Amazon Bedrock - New AWS Bedrock integration
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-08-06 17:41:16 +08:00
mouyong
80c6bed8c2
fix: 修复无法转发 opus 4.1 的问题
2025-08-06 15:26:49 +08:00
shaw
7fa75df1fd
fix: 修复分组调度功能和API Keys统计弹窗UI问题
...
1. 分组调度功能修复:
- 统一使用 unifiedClaudeScheduler 和 unifiedGeminiScheduler
- 修复 schedulable 字段数据类型不一致问题(布尔值/字符串)
- 添加 _isSchedulable() 辅助方法确保兼容性
- 修复所有路由文件中的调度器调用
2. API Keys 统计弹窗UI优化:
- 统一弹窗样式与系统UI风格
- 添加右上角关闭按钮
- 修复移动端宽度问题(设置为95%屏幕宽度)
- 使用 Teleport 组件和项目通用样式
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-08-05 17:06:52 +08:00
shaw
8e89311dac
feat: 使用API响应头中的准确时间戳修正会话窗口和限流时间
...
- 从429响应中提取 anthropic-ratelimit-unified-reset 响应头
- 使用准确的重置时间戳设置限流结束时间和会话窗口
- 会话窗口开始时间 = 重置时间戳 - 5小时
- 兼容旧逻辑:无响应头时使用预估的会话窗口时间
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-31 16:29:44 +08:00
leslie
5522967792
添加claude账号维度计算token费用
2025-07-25 21:27:17 +08:00
shaw
3553f5cc1f
fix: 修复流式响应的 Parse Error 和缓冲问题
...
主要修改:
1. 从 compression 中间件中排除 SSE 流式响应,避免压缩导致的缓冲
2. 移除导致 Parse Error 的 res.flushHeaders() 调用
3. 改进流式响应的错误处理,发送 SSE 错误事件而不是破坏流
4. 在写入数据前检查流状态,避免写入已销毁的流
5. 优化响应结束时的处理逻辑,确保缓冲区数据正确处理
这些修改确保了流式请求能够正常显示打字机效果,同时保留了 usage token 收集功能。
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-23 16:13:07 +08:00
shaw
1e372dd365
fix: 修复流式响应缓冲问题,实现真正的实时流传输
...
- 配置 compression 中间件排除 SSE 流式响应,避免压缩导致的缓冲
- 添加 X-Accel-Buffering: no 响应头,禁用 Nginx 等代理的缓冲
- 使用 res.flushHeaders() 立即发送响应头
- 禁用 Nagle 算法确保数据立即发送
- 在每次写入流数据后调用 flush() 确保实时传输
这些修复确保了流式请求能够正常显示打字机效果,数据从上游 Claude API 接收后能够立即转发给客户端。
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-23 15:56:27 +08:00
shaw
d6675a4d8e
feat: 添加 /claude/v1/messages 路由别名并优化非 Claude Code 客户端支持
...
- 添加 /claude 路由作为 /api 的别名,支持 /claude/v1/messages 端点
- 实现智能判断请求来源,通过 user-agent 和系统提示词识别真实的 Claude Code 请求
- 为非 Claude Code 客户端自动设置系统提示词和必要的 headers
- 优化 headers 更新逻辑,只有真实的 Claude Code 请求才更新缓存
- 确保 /api 和 /claude 路由功能完全一致
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-22 21:07:25 +08:00
shaw
e2cece6162
fix 修复x-request-id问题
2025-07-22 18:36:53 +08:00
shaw
dabf3bf7ea
feat: 实现 Claude Code headers 动态管理功能
...
- 创建 claudeCodeHeadersService 管理各账号的 Claude Code headers
- 自动捕获成功请求的 headers 并按账号存储在 Redis
- 智能版本管理,只保留最新版本的 headers
- OpenAI 转发时根据账号动态获取对应的 headers
- 添加管理端点查看和清除各账号的 headers 信息
- 完整支持 Claude Code 必需的 beta headers
解决了 "This credential is only authorized for use with Claude Code" 错误
避免了固定版本号带来的风控问题
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-22 16:03:31 +08:00
shaw
b2ad2a4a61
fix: 修复 OpenAI 兼容路由的 Claude API 认证和 Function Calling 支持
...
- 添加必需的系统消息 "You are Claude Code, Anthropic's official CLI for Claude."
- 修改 anthropic-beta header 为 OAuth-only 模式 (oauth-2025-04-20)
- 不再传递客户端 headers,使用固定的 4 个必需 headers
- 增强流式响应的 Function Calling 支持,正确处理 tool_use 事件
- 支持自定义 beta header 参数,允许不同路由使用不同的认证模式
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-22 14:38:30 +08:00
shaw
38c1fc4785
feat: 添加多模型支持和OpenAI兼容接口
...
- 新增 Gemini 模型支持和账户管理功能
- 实现 OpenAI 格式到 Claude/Gemini 的请求转换
- 添加自动 token 刷新服务,支持提前刷新策略
- 增强 Web 管理界面,支持 Gemini 账户管理
- 优化 token 显示,添加掩码功能
- 完善日志记录和错误处理
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-22 10:17:39 +08:00
shaw
088ce266ba
feat: 添加API Key时间窗口限流功能并移除累计总量限制
...
- 新增时间窗口限流功能,支持按分钟设置时间窗口
- 支持在时间窗口内限制请求次数和Token使用量
- 移除原有的累计总量限制,只保留时间窗口限制
- Token统计包含所有4种类型:输入、输出、缓存创建、缓存读取
- 前端UI优化,明确显示限流参数的作用范围
- 限流触发时提供友好的错误提示和重置时间
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-20 15:58:00 +08:00
shaw
4291983c87
chore: remove raw sse chunk logging
2025-07-20 00:19:00 +08:00
shaw
4bb2050093
fix: 修复API Key模型限制功能不生效的问题
...
- 在apiKeyService.validateApiKey()中添加缺失的enableModelRestriction和restrictedModels字段返回
- 添加详细的调试日志来追踪模型限制检查的执行流程
- 解析存储在Redis中的restrictedModels JSON数据
- 确保模型限制数据正确传递到claudeRelayService
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-19 21:13:11 +08:00
shaw
f962083752
feat: 为API Key添加模型限制功能
...
- 前端:在API Key创建和编辑表单中添加模型限制开关和标签输入
- 前端:支持动态添加/删除限制的模型列表
- 后端:更新API Key数据结构,新增enableModelRestriction和restrictedModels字段
- 后端:在中转请求时检查模型访问权限
- 修复:Enter键提交表单问题,使用@keydown.enter.prevent
- 优化:限制模型数据持久化,关闭开关时不清空数据
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-19 20:54:26 +08:00
shaw
f5968e518e
feat: 改进管理界面弹窗体验和滚动条美化
...
- 修复API Key创建/编辑弹窗和账户信息修改弹窗在低高度屏幕上被遮挡的问题
- 为所有弹窗添加自适应高度支持,最大高度限制为90vh
- 美化Claude账户弹窗的滚动条样式,使用紫蓝渐变色与主题保持一致
- 添加响应式适配,移动设备上弹窗高度调整为85vh
- 优化滚动条交互体验,支持悬停和激活状态
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-18 23:49:55 +08:00
shaw
ee9bd4aea4
feat: 实现Claude账户专属绑定功能
...
- 添加账户类型(dedicated/shared)支持
- API Key可绑定专属账户,优先使用绑定账户
- 未绑定的API Key继续使用共享池和粘性会话
- 修复专属账户下拉框显示问题(isActive类型不匹配)
- 修复getBoundAccountName方法未定义错误
- 添加删除账户前的API Key绑定检查
- 完全保留原有粘性会话机制
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-17 08:50:12 +08:00
shaw
a64ced0e36
fix: 修复非流式响应JSON解析错误和max_tokens参数校验
...
- 修复gzip压缩响应处理:添加zlib模块支持,正确解压缩Claude API响应
- 优化max_tokens验证机制:从硬编码改为动态读取model_pricing.json文件
- 改进错误处理:增强响应数据处理的容错性
- 修复SSE错误事件格式:统一字符串引号风格
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-16 18:12:19 +08:00
shaw
8ca9ffee68
fix: 改进socket hang up和网络错误处理机制
...
- 修复socket hang up错误导致返回空字符串的问题
- 改进非流式请求的错误处理,根据错误类型返回适当的HTTP状态码
- 优化流式请求的错误处理,返回SSE格式的错误事件
- 增强错误日志记录,包含详细的网络错误信息
- 确保在任何情况下都返回有效的JSON响应格式
修复内容:
- ECONNRESET错误返回502状态码和明确的错误信息
- ENOTFOUND错误返回502状态码和DNS解析失败信息
- ECONNREFUSED错误返回502状态码和连接被拒绝信息
- ETIMEDOUT错误返回504状态码和超时信息
- 流式请求错误时返回符合SSE规范的错误事件
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-16 17:56:29 +08:00
shaw
59bc309ae4
fix: 修复 User-Agent 暴露问题并实现安全的 header 转发
...
- 移除硬编码的 'claude-relay-service/1.0.0' User-Agent,防止代理身份暴露
- 添加 _filterClientHeaders 方法过滤敏感请求头
- 实现完整的客户端 header 转发功能
- 默认 User-Agent 设置为 'claude-cli/1.0.53 (external, cli)'
- 过滤 x-api-key, authorization, host 等敏感 headers
- 更新所有 _makeClaudeRequest 方法支持 clientHeaders 参数
- 修改 API 路由传递 req.headers 到服务层
安全改进:
- 防止代理服务身份暴露
- 提升请求透明性和安全性
- 保持客户端原始请求特征
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-16 16:01:11 +08:00
shaw
567e3b25aa
feat: 优化并发控制和移除冗余限制功能
...
主要改进:
1. 改进并发控制机制
- 使用 once 代替 on 避免重复监听
- 监听多个事件确保可靠性(close、finish)
- 支持客户端断开时立即释放并发槽位
2. 支持非流式请求的客户端断开处理
- 客户端断开时立即中断上游请求
- 避免资源浪费和不必要的 API 调用
3. 移除 requestLimit(请求数限制)功能
- 移除配置和验证逻辑
- 保留请求统计用于监控分析
4. 移除速率限制(Rate Limit)功能
- 移除 RATE_LIMIT_* 配置
- 简化中间件逻辑
- 避免与并发控制重复
现在系统仅保留:
- Token 使用量限制
- 并发数限制(更精确的资源控制)
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-16 14:40:37 +08:00
shaw
b2b8d8c719
feat: 添加智能sticky会话保持功能
...
- 新增 sessionHelper.js 实现会话哈希生成,基于Anthropic的prompt caching机制
- 扩展 claudeAccountService.selectAvailableAccount 支持会话绑定
- 更新 claudeRelayService 集成会话保持功能
- 添加 Redis 会话映射存储,支持1小时过期
- 支持故障转移:绑定账户不可用时自动重新选择
- 三级fallback策略:cacheable内容 → system内容 → 第一条消息
- 完全向后兼容,自动启用无需配置
🤖 Generated with [Claude Code](https://claude.ai/code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-07-15 18:15:53 +08:00
shaw
b1ca3f307e
first commit
2025-07-14 18:14:13 +08:00