Skip to content

feat(codex-inspection): add xAI/Grok provider inspection support#330

Closed
lost9999 wants to merge 2 commits into
seakee:mainfrom
lost9999:feat/xai-inspection
Closed

feat(codex-inspection): add xAI/Grok provider inspection support#330
lost9999 wants to merge 2 commits into
seakee:mainfrom
lost9999:feat/xai-inspection

Conversation

@lost9999

Copy link
Copy Markdown
Contributor

希望 Codex 账号巡检功能支持 xAI/Grok 凭证

背景

CPAMP 的 Quota 页面和监控已经能显示 xAI/Grok 凭证的用量和错误统计了(最近几个版本加了 Grok billing API 查询、xAI provider 标准化、暗色图标),非常方便。

但最大的问题是:Quota 页面只能看,不能自动管。Codex 的 Inspection 系统能做到"额度耗尽自动暂停、额度恢复自动启用",而 Grok 这边完全需要手动操作。

场景

我们有 900 多个 Grok 免费账号,每天对外提供 grok-4.5 服务。

  • 免费账号有 1M token / 天的额度
  • 单次 agent 会话就能吃掉 30 万 token
  • 经常一个会话还没跑完,当前绑定的账号就额度耗尽了
  • 然后 CPA 的 session-affinity 切账号,下一个账号又耗尽
  • 最终耗尽所有账号,客户端收到 502

如果有 Grok Inspection:

  1. 每小时巡检一次,调 CPA api-call 打到 Grok billing API
  2. 发现额度耗尽→自动 PATCH /auth-files/status 暂停
  3. 下一个计费周期恢复→自动重新启用

技术上几乎已经准备好了

看源码发现,Inspection 的核心流程是 provider 无关的:

type ManagerCodexInspectionConfig struct {
    TargetType  string  // ← 目前写死 "codex",放开就行
    Workers     int
    // ...
}

流程是:GET /auth-files → 按 TargetType 过滤 → api-call 探测 → PATCH /auth-files/status disable/enable。

Codex 和 Grok 的唯一区别是探测 API 的路径不同(Codex 走 OpenAI usage API,Grok 走 billing API),7 月初的 release 已经能调 Grok billing 了。

优先级

Grok 的 token 消耗速度远高于 Codex(免费账号 1M/天 vs Codex 数十万/周),自动化管理的紧迫性其实比 Codex 更高。

希望能考虑支持,感谢!


附:CPAMP 版本 v1.10.5,当前通过外部 cron 脚本兜底,但非常期待原生集成。

lost9999 added 2 commits July 11, 2026 17:16
- Add TargetTypeXAI constant and TargetTypeCodex constant in model layer
- Add xAI billing API probe (requestXaiBilling / requestXaiBillingAt)
- Add resolveXaiBillingProbeAction for Grok-specific quota logic:
  - 402 spending-limit -> disable
  - 401/403 (non-region) -> disable
  - 429 rate-limit -> disable
  - Parse billing config for monthlyLimit/used/onDemandCap thresholds
  - Auto re-enable recommendation when quota recovers
- Add readMapValue helper for xAI's {val: N} nested value format
- Route probe to xai or codex based on account provider field

Free-tier Grok accounts have 1M token/day quota and short rolling windows,
making automated inspection even more critical than for Codex.
The Hermes commit filter corrupted
into [redacted], causing CI build failure. Restore the correct comparison.
@lost9999

Copy link
Copy Markdown
Contributor Author

Closing this draft implementation in favor of a clean redesign. The next proposal will use CPAMP-owned provider-aware cooldown state, event-driven disablement, active recovery probes, ownership protection, and tests instead of extending Codex Inspection directly.

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