fix(daemon): migrate codex usage API to wham endpoint#267
Conversation
…usage The old OpenAI endpoint (api.openai.com/api/codex/usage) has been replaced with the new wham usage endpoint. Updated response parsing to handle the new category-based structure (rate_limit, code_review_rate_limit) with primary/secondary windows. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
@claude review |
|
Claude finished @AnnatarHe's task in 1m 16s —— View job Code Review: PR #267 — Migrate Codex usage API to wham endpoint
Overall this is a clean migration. The structure changes look reasonable and 1.
|
There was a problem hiding this comment.
Code Review
This pull request migrates the rate limit tracking logic from the legacy Codex usage API to the new WHAM usage API endpoint. The changes include updated data structures to match the new response schema and a revised mapping process for primary and secondary rate limit windows. Feedback highlights the need to use float64 for usage percentages to prevent decoding failures and recommends restoring the ChatGPT-Account-Id header to ensure correct account identification.
| ResetAt int64 `json:"resetAt"` | ||
| WindowDurationMinutes int `json:"windowDurationMinutes"` | ||
| type whamRateLimitWindow struct { | ||
| UsedPercent int `json:"used_percent"` |
There was a problem hiding this comment.
The UsedPercent field is defined as an int. If the API returns a floating-point number (e.g., 45.5), the JSON decoding will fail with an error. Given that the previous API used float64 for usage percentages, it is safer to use float64 here to ensure robust parsing of the response.
| UsedPercent int `json:"used_percent"` | |
| UsedPercent float64 "json:\"used_percent\"" |
| req.Header.Set("Authorization", "Bearer "+auth.AccessToken) | ||
| if auth.AccountID != "" { | ||
| req.Header.Set("ChatGPT-Account-Id", auth.AccountID) | ||
| } | ||
| req.Header.Set("User-Agent", "shelltime-daemon") |
There was a problem hiding this comment.
The ChatGPT-Account-Id header was removed in this migration. This header is typically required by ChatGPT backend APIs to correctly identify the target account, especially for users who are members of multiple workspaces or organizations. Since auth.AccountID is still being loaded from the configuration, it should be included in the request headers to ensure the correct usage data is fetched.
| req.Header.Set("Authorization", "Bearer "+auth.AccessToken) | |
| if auth.AccountID != "" { | |
| req.Header.Set("ChatGPT-Account-Id", auth.AccountID) | |
| } | |
| req.Header.Set("User-Agent", "shelltime-daemon") | |
| req.Header.Set("Authorization", "Bearer "+auth.AccessToken) | |
| if auth.AccountID != "" { | |
| req.Header.Set("ChatGPT-Account-Id", auth.AccountID) | |
| } | |
| req.Header.Set("User-Agent", "shelltime-daemon") |
Summary
api.openai.com/api/codex/usagetochatgpt.com/backend-api/wham/usagerate_limit,code_review_rate_limit) with primary/secondary windowsLimitIDas<category>:<position>(e.g.rate_limit:primary) for downstream compatibilityTest plan
go test ./daemon/...passesgo vet ./daemon/...clean🤖 Generated with Claude Code