codexusage

package
v0.29.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

type Identity struct {
	UserID    string
	AccountID string
	Email     string
	PlanType  string
}

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

func Parse(body []byte) (*usage.Snapshot, Identity, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL