Skip to content

fix(native-api): 修复 Gemini :verb 路径中 %3A URL 编码导致上游 400 的兼容问题#237

Merged
ThreeFish-AI merged 1 commit into
feature/1.x.xfrom
ThreeFish-AI/fix-gemini-batch-embed
May 12, 2026
Merged

fix(native-api): 修复 Gemini :verb 路径中 %3A URL 编码导致上游 400 的兼容问题#237
ThreeFish-AI merged 1 commit into
feature/1.x.xfrom
ThreeFish-AI/fix-gemini-batch-embed

Conversation

@ThreeFish-AI
Copy link
Copy Markdown
Owner

Summary

  • 修复 litellm 等客户端将 Gemini 路径中冒号 URL 编码为 %3A 时,代理透传至上游导致 400 Bad Request 的问题
  • handler.dispatch() 中添加防御性 unquote(rest_path) 解码,确保上游收到字面冒号
  • OperationClassifier 正则模式兼容字面 :%3A 两种编码形态

修改文件

  • src/coding/proxy/native_api/handler.py — dispatch() 中对 rest_path 做 unquote() 解码
  • src/coding/proxy/native_api/operation.py — Gemini :verb 正则兼容 %3A
  • tests/test_native_api_handler.py — 新增 batchEmbedContents 及 %3A 端到端测试
  • tests/test_native_api_operation.py — 新增 %3A 操作分类测试用例

Test plan

  • 74 个测试全部通过(含新增 7 个测试用例)
  • 现有测试无回归
  • 部署后验证 litellm → proxy → Gemini embedding 链路正常

🤖 Generated with Claude Code, CodeX, Gemini

litellm 等客户端会将 Gemini 路径中的冒号 URL 编码为 %3A,
导致上游 API 无法识别 :batchEmbedContents 等 verb 后缀。

修复内容:
- handler: dispatch() 中对 rest_path 做防御性 unquote() 解码
- operation: Gemini 正则模式兼容字面 : 与 %3A 两种形态
- 新增 batchEmbedContents 端到端测试及 %3A 编码路径测试

🤖 Generated with [Claude Code](https://github.com/claude), [CodeX](https://openai.com), [Gemini](https://github.com/apps/gemini-code-assist)
Co-Authored-By: Aurelius Huang<threefish.ai@gmail.com>
@ThreeFish-AI ThreeFish-AI merged commit ec9e866 into feature/1.x.x May 12, 2026
6 checks passed
@ThreeFish-AI ThreeFish-AI deleted the ThreeFish-AI/fix-gemini-batch-embed branch May 12, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant