Skip to content

feat: codex alpha search - #6156

Closed
seefs001 wants to merge 1 commit into
QuantumNous:mainfrom
seefs001:feature/alpha-search
Closed

feat: codex alpha search#6156
seefs001 wants to merge 1 commit into
QuantumNous:mainfrom
seefs001:feature/alpha-search

Conversation

@seefs001

@seefs001 seefs001 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)

为Codex渠道增加/v1/alpha/search支持

🚀 变更类型 / Type of change

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

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

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

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

Summary by CodeRabbit

  • New Features

    • Added support for Codex standalone web search through POST /v1/alpha/search.
    • Added request validation for model and maximum output token settings.
    • Added Codex channel routing, model-aware web search pricing, quota handling, and usage tracking.
    • Improved channel selection to ensure requests are routed only to compatible channels.
  • Bug Fixes

    • Added validation and error handling for unsupported channels, invalid responses, pricing issues, and excessive token limits.
  • Tests

    • Added coverage for Codex Search token limits and model-aware web search pricing.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a Codex Search API endpoint with request validation, Codex-specific channel routing, upstream forwarding, model-aware pricing, quota settlement, consumption logging, and boundary tests.

Changes

Codex Search relay

Layer / File(s) Summary
Codex Search contracts and request entry
constant/codex.go, dto/codex_search.go, types/relay_format.go, relay/constant/relay_mode.go, router/relay-router.go, relay/helper/valid_request.go, relay/common/relay_info.go
Defines the Codex Search request, relay format and mode, /alpha/search route, validation rules, and relay metadata construction.
Request-path channel selection
model/channel.go, model/channel_cache.go, model/ability.go, middleware/distributor.go
Centralizes channel path support checks and applies Codex-only filtering across channel selection paths.
Codex Search upstream forwarding
controller/relay.go, relay/codex_search_handler.go, relay/channel/codex/adaptor.go
Dispatches Codex Search requests, maps the upstream endpoint, validates responses, and copies upstream response bodies to clients.
Pricing, quota settlement, and validation coverage
relay/helper/price.go, controller/relay.go, service/codex_search_billing.go, relay/helper/*_test.go
Adds web-search pricing, attempt pre-consumption, settlement fallback, consumption logging, and request/pricing boundary tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: calcium-ion, creamlike1024

Poem

I’m a rabbit hopping through search,
With quota counted neat and fair.
A Codex path now joins the route,
And upstream answers fill the air.
Tests guard tokens, prices too—
Hop, hop, the new flow’s true!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.73% 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 clearly matches the main change: adding Codex alpha search support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
relay/helper/max_tokens_bounds_test.go (1)

90-91: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use assert for non-fatal value checks per coding guidelines.

Lines 90–91 use require.Equal/require.EqualValues for non-fatal value checks. The coding guideline mandates assert for non-fatal value checks so all failures are reported. require.NoError (line 89) is correctly fatal.

♻️ Suggested change
 require.NoError(t, err)
-require.Equal(t, "gpt-5.4", req.Model)
-require.EqualValues(t, 4096, *req.MaxOutputTokens)
+assert.Equal(t, "gpt-5.4", req.Model)
+assert.EqualValues(t, 4096, *req.MaxOutputTokens)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@relay/helper/max_tokens_bounds_test.go` around lines 90 - 91, Replace the
non-fatal require.Equal and require.EqualValues checks in the test with their
assert equivalents, while keeping require.NoError unchanged for the fatal setup
check.

Source: Coding guidelines

relay/helper/price_test.go (1)

97-101: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use assert for non-fatal value checks per coding guidelines.

Lines 97–101 use require.Equal/require.True for non-fatal value checks. The coding guideline mandates assert for non-fatal value checks so all failures are reported instead of stopping at the first. require.NoError (line 96) is correctly fatal.

♻️ Suggested change
 require.NoError(t, err)
-require.Equal(t, 0.03, priceData.ModelPrice)
-require.Equal(t, 22500, priceData.QuotaToPreConsume)
-require.Equal(t, 22500, priceData.Quota)
-require.True(t, priceData.UsePrice)
-require.Equal(t, priceData, info.PriceData)
+assert.Equal(t, 0.03, priceData.ModelPrice)
+assert.Equal(t, 22500, priceData.QuotaToPreConsume)
+assert.Equal(t, 22500, priceData.Quota)
+assert.True(t, priceData.UsePrice)
+assert.Equal(t, priceData, info.PriceData)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@relay/helper/price_test.go` around lines 97 - 101, In the priceData
assertions within the test, replace the non-fatal require.Equal and require.True
checks with their assert equivalents, while preserving the existing comparisons
and keeping the require.NoError check fatal.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@relay/helper/max_tokens_bounds_test.go`:
- Around line 90-91: Replace the non-fatal require.Equal and require.EqualValues
checks in the test with their assert equivalents, while keeping require.NoError
unchanged for the fatal setup check.

In `@relay/helper/price_test.go`:
- Around line 97-101: In the priceData assertions within the test, replace the
non-fatal require.Equal and require.True checks with their assert equivalents,
while preserving the existing comparisons and keeping the require.NoError check
fatal.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d58f9cdd-dbc2-4dd0-abb3-001fb2ba1f7d

📥 Commits

Reviewing files that changed from the base of the PR and between 7c28993 and 7f9004b.

📒 Files selected for processing (18)
  • constant/codex.go
  • controller/relay.go
  • dto/codex_search.go
  • middleware/distributor.go
  • model/ability.go
  • model/channel.go
  • model/channel_cache.go
  • relay/channel/codex/adaptor.go
  • relay/codex_search_handler.go
  • relay/common/relay_info.go
  • relay/constant/relay_mode.go
  • relay/helper/max_tokens_bounds_test.go
  • relay/helper/price.go
  • relay/helper/price_test.go
  • relay/helper/valid_request.go
  • router/relay-router.go
  • service/codex_search_billing.go
  • types/relay_format.go

@Ryan-CW-Code

Copy link
Copy Markdown

@Calcium-Ion 辛苦关注一下这个PR

#6114

@seefs001

Copy link
Copy Markdown
Collaborator Author

@Calcium-Ion 辛苦关注一下这个PR

#6114

目前没有支持的计划

@Ryan-CW-Code

Copy link
Copy Markdown

好的,方便透露原因吗?联网搜索功能还挺有用的

@PurpleSwords

Copy link
Copy Markdown

好的,方便透露原因吗?联网搜索功能还挺有用的

这个pr我本地测试过了,只支持codex格式。而绝大多数人用的都是openai格式的,要想真正支持还得再修改

@Calcium-Ion

Copy link
Copy Markdown
Member

好的,方便透露原因吗?联网搜索功能还挺有用的

该端点仅codex订阅支持,无法确认上游是否支持(目前除codex外均没有上游支持),如果添加该功能后直接请求,请求到不支持的上游渠道上会报错

@Oliver0128AIbot

Oliver0128AIbot commented Jul 18, 2026

Copy link
Copy Markdown

好的,方便透露原因吗?联网搜索功能还挺有用的

该端点仅codex订阅支持,无法确认上游是否支持(目前除codex外均没有上游支持),如果添加该功能后直接请求,请求到不支持的上游渠道上会报错

大佬求一个啊 🙏 最近 Codex 用户也挺多的,联网搜索被卡住之后 Codex 默认转 curl 抓取,慢得难受。求个修复! @Calcium-Ion 辛苦大佬

@Calcium-Ion

Copy link
Copy Markdown
Member

好的,方便透露原因吗?联网搜索功能还挺有用的

该端点仅codex订阅支持,无法确认上游是否支持(目前除codex外均没有上游支持),如果添加该功能后直接请求,请求到不支持的上游渠道上会报错

大佬求一个啊 🙏 最近 Codex 用户也挺多的,联网搜索被卡住之后 Codex 默认转 curl 抓取,慢得难受。求个修复! @Calcium-Ion 辛苦大佬

这个项目不是逆向项目,不可能为了一个订阅逆向单独加接口,如果openai把这个作为标准开放newapi会立刻加上,目前这个情况,如果真的需要请二开

@BiFangKNT

Copy link
Copy Markdown

@Calcium-Ion 至少做个选项也行吧,给这个选项单独加路由,又不影响别的功能

现在是一刀切完全不兼容,也并不合理,对于需要这个功能的用户来说,这是p1~p0级事故

@Calcium-Ion

Copy link
Copy Markdown
Member

@Calcium-Ion 至少做个选项也行吧,给这个选项单独加路由,又不影响别的功能

现在是一刀切完全不兼容,也并不合理,对于需要这个功能的用户来说,这是p1~p0级事故

目前考虑的做法是和相关项目合作,针对某个渠道类型做兼容,可能会在几个版本后上线

@BiFangKNT

Copy link
Copy Markdown

@Calcium-Ion 感谢。请问大概要多久呢,月内可以实现吗?

@cipherTing

Copy link
Copy Markdown

@Calcium-Ion 你好,大大,同样需要这个功能,增加一个功能选项是否可行?

@Calcium-Ion

Copy link
Copy Markdown
Member

该功能已在 v1.0.0-rc.22 中支持,请升级后使用。因此关闭此 Issue。

@QuantumNous QuantumNous locked as resolved and limited conversation to collaborators Jul 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants