mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 18:06:46 +00:00
feat: 全面增强 Claude Code 客户端支持与错误处理
## 🚀 新功能 - **智能认证系统**: 根据 API Key 格式自动选择认证方式 - `sk-ant-*` 开头使用 `x-api-key` 认证(兼容 Anthropic 官方) - 其他格式使用 `Authorization: Bearer` 认证(兼容标准 REST API) - **Claude Code 客户端完整支持**: 新增必需的 API 端点 - `GET /v1/models` - 返回支持的模型列表 - `GET /v1/me` - 用户信息端点 - `GET /v1/organizations/:org_id/usage` - 使用统计查询 ## 🔧 修复与优化 - **HTTP 协议合规性**: 修复响应头冲突导致的 502 错误 - 避免同时发送 `Content-Length` 和 `Transfer-Encoding` 头部 - 优化响应头过滤机制,确保代理兼容性 - **完全透传错误响应**: 保持上游 API 原始响应格式 - 透传原始状态码、响应头和内容 - 移除错误包装,直接转发原始 JSON 格式 - 支持流式和非流式请求的错误透传 - **流式响应处理优化**: - 添加 `validateStatus: () => true` 配置 - 改进错误处理逻辑,避免异常中断 ## 📝 代码质量 - 修复 ESLint 代码规范警告 - 优化敏感头部过滤列表 - 改进调试日志输出 ## 🎯 解决的问题 - Claude Code 客户端无法连接(502 Bad Gateway) - 错误响应被包装而非透传原始格式 - sk-ant-* 格式 API Key 认证失败 - HTTP/2 代理环境下的响应头冲突 ## ✅ 测试验证 - 本地测试完全透传上游错误响应 - Claude Code 客户端连接测试通过 - 智能认证机制验证成功 - HTTP 协议合规性确认
This commit is contained in:
@@ -314,7 +314,7 @@ class PricingService {
|
||||
// 记录初始的修改时间
|
||||
let lastMtime = fs.statSync(this.pricingFile).mtimeMs;
|
||||
|
||||
fs.watchFile(this.pricingFile, watchOptions, (curr, prev) => {
|
||||
fs.watchFile(this.pricingFile, watchOptions, (curr, _prev) => {
|
||||
// 检查文件是否真的被修改了(不仅仅是访问)
|
||||
if (curr.mtimeMs !== lastMtime) {
|
||||
lastMtime = curr.mtimeMs;
|
||||
|
||||
Reference in New Issue
Block a user