Documentation
¶
Overview ¶
Package codexusage reads a Codex account's quota.
One unauthenticated-by-nothing GET returns what the Claude side needs two calls for: the identity, the tier and both quota windows. It costs NOTHING — no inference request, no billed turn, no model call. That matters because the obvious alternative, which the largest prior-art proxy in this field actually ships, is to POST a minimal real inference request and cancel the body once the rate-limit headers arrive. That measures quota with money.
What this package does NOT do, and the reasons are not stylistic:
- it never spoofs a browser user agent. At least one shipped tool does, with an in-source note that the honest client agent triggers a Cloudflare challenge. ccdad names itself; if an endpoint starts challenging, this feature degrades rather than evades.
- it never polls faster than the poll policy's Codex floor. The endpoint advertises no budget: no Retry-After on a good response, no x-ratelimit-* headers, and upstream's own client never polls on a timer at all. A background poller is therefore a traffic shape no official client emits, so the floor is timid by construction and is tightened only against measurement.
Index ¶
Constants ¶
const UsageURL = "https://chatgpt.com/backend-api/wham/usage"
UsageURL is the quota endpoint.
The path prefix is not interchangeable and this is measured, not assumed: /backend-api/wham/usage answers 200, and /backend-api/api/codex/usage answers a Cloudflare-shaped 403. Upstream picks between the two by whether the base URL contains /backend-api, and ccdad only ever speaks to the one that works.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Identity ¶
Identity is who the reading was about.
UserID is the ACCOUNT and AccountID is the WORKSPACE, and they answer different questions: two seats in one team workspace share the second, so keying an account on it would let a colleague's login overwrite the first.
func Fetch ¶
func Fetch(ctx context.Context, client *http.Client, accessToken, accountID, version string) (*usage.Snapshot, Identity, error)
Fetch reads accessToken's quota.
accountID is the WORKSPACE. Sent, it populates the account-scoped fields; omitted, the bearer alone still answers 200 with a slightly smaller body. An empty value is therefore not sent at all rather than sent empty.
Errors name the status and the network cause, never the token and never the response body.
func Parse ¶
Parse turns a /wham/usage body into a snapshot and the identity beside it.
It is pure so the pinned live capture can be a fixture: the one measurement this whole package rests on is a real 200 from a real account, and a parser that needed a server to exercise would be tested against a body somebody made up instead.