feat(opencode): expose account usage limits - #146
Open
Aser-Osama wants to merge 2 commits into
Open
Conversation
Aser-Osama
force-pushed
the
feat/opencode-go-usage
branch
from
September 10, 2026 15:10
f8d309b to
eb0457c
Compare
Aser-Osama
marked this pull request as draft
September 10, 2026 15:20
Aser-Osama
force-pushed
the
feat/opencode-go-usage
branch
from
September 10, 2026 20:06
eb0457c to
184749b
Compare
Aser-Osama
marked this pull request as ready for review
September 10, 2026 20:08
Contributor
Author
|
@raine Kept this PR "OpenCode Go" only to avoid overlapping with the existing Codex usage work in #62, but I’m happy to extend the same account/usage surface to Codex as part of this PR if you’d prefer a unified implementation. Also happy to adjust the HTTP/API shape if you have a preferred direction. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenCode Go exposes rolling five-hour, weekly, and monthly quota windows, but claude-code-proxy currently surfaces only per-request token usage and limit failures. Users cannot inspect their remaining account allowance before sending a request, and dashboards pointed at the proxy have no account endpoint to poll.
This PR builds on #145, which refreshed the OpenCode Go catalog and runtime behavior, by adding focused account-usage support on top of that provider foundation.
What changes
claude-code-proxy opencode usageclaude-code-proxy opencode usage --jsonfor scripts/usageendpoint with a bounded response body, a 10-second timeout, disabled redirects, and the versioned claude-code-proxy User-AgentGET /.well-known/ccr/accountGET /v1/account/limitsOpenCode implements the upstream usage endpoint, including all three quota windows, although it is not yet listed as a stable public API contract. The parser therefore keeps known fields typed while tolerating missing fields and unknown additions. It rejects responses with no recognizable quota information instead of fabricating values.
Caching and HTTP behavior
The server keeps the latest successful upstream result in a small 60-second in-process cache. Frequent Claude Code Router polling therefore reuses the same snapshot, and concurrent refreshes are coalesced.
After the cache expires, an upstream failure is returned explicitly instead of serving an unmarked stale quota. Upstream status codes are retained, including
Retry-Afteron HTTP 429 responses. All local account responses includeCache-Control: no-store.Claude Code Router compatibility
The local responses follow Claude Code Router's Standard usage endpoint contract. Configure the CCP provider with Fetch usage enabled and select Standard usage endpoint; CCR discovers
/.well-known/ccr/accountautomatically.A generic CCP
/usageendpoint is deliberately omitted because #62 already proposes that API for Codex with a separate provider-neutral design discussion.Security
The account routes intentionally ignore incoming placeholder bearer and API-key headers and use CCP's configured OpenCode credential, consistent with generation routes.
The credential is never serialized or recorded in traffic capture. Upstream error text is also scrubbed if it echoes the configured key. Since the local proxy does not authenticate clients, account usage remains visible to anyone who can reach a non-loopback listener; the documentation calls for a firewall or authenticating reverse proxy in that configuration.
Scope
Codex quota support is deliberately outside this PR. CCP currently receives some Codex rate-limit telemetry internally, while #62 proposes exposing Codex usage. This change remains scoped to OpenCode Go and does not alter Kimi, Grok, Cursor, or Codex behavior.
Validation
cargo fmt --all --checkcargo test --allcargo clippy --all-targets -- -D warnings -A deprecatedllms.txtgit diff --checkRust 1.100 reports an existing
AtomicU64::fetch_updatedeprecation in unchanged Codex websocket code. Current main has the same finding; the required Clippy invocation above passes.