Skip to content

fix: route Codex Claude/chat requests through responses conversion - #4285

Closed
fanruan-tuco wants to merge 2 commits into
QuantumNous:mainfrom
fanruan-tuco:main
Closed

fix: route Codex Claude/chat requests through responses conversion#4285
fanruan-tuco wants to merge 2 commits into
QuantumNous:mainfrom
fanruan-tuco:main

Conversation

@fanruan-tuco

@fanruan-tuco fanruan-tuco commented Apr 16, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

  • Claude 协议请求可经由 Codex 渠道转发

📝 变更描述 / Description

本次修改让 Codex (OpenAI OAuth) 渠道能够正确处理 Claude /v1/messages 和 OpenAI Chat /v1/chat/completions 请求。

在此之前,Codex 渠道本身只实现了 Responses API 路径,请求如果落到 ConvertClaudeRequest 或 ConvertOpenAIRequest 会直接返回 endpoint not supported。
但项目内部已经存在完整的转换链:

  • Claude → OpenAI Chat
  • OpenAI Chat → Responses
  • Responses → 再转换回调用方需要的响应格式

问题不在于缺少转换能力,而在于这条转换链原本只会在策略条件命中时启用。对于 Codex 渠道来说,这不应该是可选策略,而应该是固定路径,因为它本身只支持 Responses API。

因此这次改动在两个 handler 中增加了 Codex 渠道判断:

  • relay/claude_handler.go
  • relay/compatible_handler.go

当渠道类型为 Codex 时,直接进入现有的 chatCompletionsViaResponses 路径,而不是继续走 Codex adaptor 中未实现的 Claude / Chat 原生转换入口。这样可以复用项目已有的协议转换逻辑,并确保最终请求以 Responses 格式发送给 Codex 上游。

实际效果:

  • Claude 协议请求可经由 Codex 渠道转发
  • OpenAI Chat 请求可经由 Codex 渠道转发
  • 原有的 Responses 请求行为保持不变

🚀 变更类型 / Type of change

  • [ x ] 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • [ x ] 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • [ x ] 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • [ x ] Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • [ x ] 变更理解: 我已理解这些更改的工作原理及可能影响。
  • [ x ] 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • [ x ] 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

企业微信截图_17763258204000

Summary by CodeRabbit

  • Bug Fixes
    • Improved request routing for Codex channel requests to ensure they bypass unnecessary conditional checks and are processed through the proper handling path consistently.

fanruan-tuco and others added 2 commits April 16, 2026 16:25
Codex only supports the responses API, so force Claude messages and chat completions requests onto the existing responses conversion path instead of hitting unsupported adaptor endpoints.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f042c148-4139-427c-a863-a21579419b00

📥 Commits

Reviewing files that changed from the base of the PR and between 3cad6b9 and 43b5494.

📒 Files selected for processing (2)
  • relay/claude_handler.go
  • relay/compatible_handler.go

Walkthrough

The PR modifies request routing logic in Claude and compatible handlers to unconditionally route Codex channel requests through the chatCompletionsViaResponses path, bypassing previous pass-through and global response configuration checks.

Changes

Cohort / File(s) Summary
Codex channel routing
relay/claude_handler.go, relay/compatible_handler.go
Introduces codexChannel detection for Codex requests and forces them through chatCompletionsViaResponses path regardless of pass-through settings or global response configuration.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • feat: /v1/messages -> /v1/responses #2889: Both PRs modify claude_handler.go to route Claude-related requests through chatCompletionsViaResponses, with this PR further forcing Codex-channel requests to unconditionally take that path.
  • fix: deepseek claude response #1833: Related changes to Claude-specific request/response routing, where this PR forces Codex-channel requests through the responses path while the other adjusts deepseek adaptor dispatch to Claude handlers.

Suggested reviewers

  • seefs001
  • Calcium-Ion

Poem

🐰 A Codex knocks upon Claude's door,
"Let me speak your format true!"
So we reroute the winding way,
Through responses, straight and new,
No gates shall bar the Codex's day! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: routing Codex Claude/chat requests through responses conversion, which is the core modification across both handler files.
Linked Issues check ✅ Passed The changes directly address issue #3097 by enabling the Codex channel to accept Claude-format requests (/v1/messages) and OpenAI Chat-format requests through the responses conversion path, fixing the OperationNotSupported error.
Out of Scope Changes check ✅ Passed All changes are scoped to the stated objective: adding Codex channel routing logic to relay/claude_handler.go and relay/compatible_handler.go, with no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@seefs001

Copy link
Copy Markdown
Collaborator

不考虑对Codex渠道做除了本身就支持的行为的适配处理

@seefs001 seefs001 closed this Apr 16, 2026
@fanruan-tuco

Copy link
Copy Markdown
Author

不考虑对Codex渠道做除了本身就支持的行为的适配处理

我们确实很需要这个功能! 这个pr经过本地验证可以使用,需要的话自行patch

@Ech0xff

Ech0xff commented Apr 17, 2026

Copy link
Copy Markdown

不考虑对Codex渠道做除了本身就支持的行为的适配处理

我们确实很需要这个功能! 这个pr经过本地验证可以使用,需要的话自行patch

请问用在claude code中使用可以支持缓存吗

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.

希望codex支持claude调用格式

3 participants