|
| 1 | +# `/api/oauth/usage` — HTTP contract |
| 2 | + |
| 3 | +The endpoint this statusline polls for 5h / 7d / per-model quota. This file |
| 4 | +documents the observed wire contract so parser changes can be checked against |
| 5 | +ground truth instead of guesswork. |
| 6 | + |
| 7 | +- Synced with: **Claude Code v2.1.201** (captured 2026-07-06 via a local |
| 8 | + mitm reverse proxy in front of the official CLI) |
| 9 | +- All credentials, org IDs, and request IDs below are redacted or fabricated. |
| 10 | +- Fields marked *reserved* were observed only as `null`; names are as sent by |
| 11 | + the server. |
| 12 | + |
| 13 | +## Request |
| 14 | + |
| 15 | +``` |
| 16 | +GET https://api.anthropic.com/api/oauth/usage |
| 17 | +``` |
| 18 | + |
| 19 | +| Header | Value | Notes | |
| 20 | +|--------|-------|-------| |
| 21 | +| `Authorization` | `Bearer <oauth access token>` | The `claudeAiOauth.accessToken` from Claude Code credentials | |
| 22 | +| `Content-Type` | `application/json` | | |
| 23 | +| `User-Agent` | see below | | |
| 24 | +| `anthropic-beta` | `oauth-2025-04-20` | sent by one of the CLI's two internal clients, not required | |
| 25 | + |
| 26 | +No query parameters. No request body. |
| 27 | + |
| 28 | +### The CLI itself calls this twice per launch |
| 29 | + |
| 30 | +One `claude` v2.1.201 session was observed issuing **two** usage requests on |
| 31 | +boot, from two distinct internal clients: |
| 32 | + |
| 33 | +``` |
| 34 | +user-agent: claude-cli/2.1.201 (external, cli) + anthropic-beta: oauth-2025-04-20 |
| 35 | +user-agent: claude-code/2.1.201 |
| 36 | +``` |
| 37 | + |
| 38 | +Both received 200 with identical schema. This matters for rate-limit math: |
| 39 | +launching N Claude Code instances produces 2N usage requests from the CLIs |
| 40 | +alone before any statusline fetch happens. The statusline mimics the second |
| 41 | +form (`claude-code/<version>`) and adds at most one request per account per |
| 42 | +TTL window (shared cache + atomic lock, see below). |
| 43 | + |
| 44 | +## Response — 200 |
| 45 | + |
| 46 | +`Content-Type: application/json`. Notable response headers: |
| 47 | +`anthropic-organization-id: <org uuid>` (redacted), `request-id: req_...`. |
| 48 | + |
| 49 | +```json |
| 50 | +{ |
| 51 | + "five_hour": { |
| 52 | + "utilization": 96.0, |
| 53 | + "resets_at": "2026-07-06T10:59:59.800387+00:00", |
| 54 | + "limit_dollars": null, |
| 55 | + "used_dollars": null, |
| 56 | + "remaining_dollars": null |
| 57 | + }, |
| 58 | + "seven_day": { |
| 59 | + "utilization": 65.0, |
| 60 | + "resets_at": "2026-07-08T15:59:59.800406+00:00", |
| 61 | + "limit_dollars": null, |
| 62 | + "used_dollars": null, |
| 63 | + "remaining_dollars": null |
| 64 | + }, |
| 65 | + "limits": [ |
| 66 | + { |
| 67 | + "kind": "session", |
| 68 | + "group": "session", |
| 69 | + "percent": 96, |
| 70 | + "severity": "critical", |
| 71 | + "resets_at": "2026-07-06T10:59:59.800387+00:00", |
| 72 | + "scope": null, |
| 73 | + "is_active": true |
| 74 | + }, |
| 75 | + { |
| 76 | + "kind": "weekly_all", |
| 77 | + "group": "weekly", |
| 78 | + "percent": 65, |
| 79 | + "severity": "normal", |
| 80 | + "resets_at": "2026-07-08T15:59:59.800406+00:00", |
| 81 | + "scope": null, |
| 82 | + "is_active": false |
| 83 | + }, |
| 84 | + { |
| 85 | + "kind": "weekly_scoped", |
| 86 | + "group": "weekly", |
| 87 | + "percent": 83, |
| 88 | + "severity": "warning", |
| 89 | + "resets_at": "2026-07-08T15:59:59.800706+00:00", |
| 90 | + "scope": { |
| 91 | + "model": { "id": null, "display_name": "Fable" }, |
| 92 | + "surface": null |
| 93 | + }, |
| 94 | + "is_active": false |
| 95 | + } |
| 96 | + ], |
| 97 | + "extra_usage": { |
| 98 | + "is_enabled": false, |
| 99 | + "monthly_limit": 20000, |
| 100 | + "used_credits": 0.0, |
| 101 | + "utilization": 0.0, |
| 102 | + "currency": "USD", |
| 103 | + "decimal_places": 2, |
| 104 | + "disabled_reason": "out_of_credits", |
| 105 | + "daily": null, |
| 106 | + "weekly": null |
| 107 | + }, |
| 108 | + "spend": { |
| 109 | + "used": { "amount_minor": 0, "currency": "USD", "exponent": 2 }, |
| 110 | + "limit": { "amount_minor": 20000, "currency": "USD", "exponent": 2 }, |
| 111 | + "percent": 0, |
| 112 | + "severity": "normal", |
| 113 | + "enabled": false, |
| 114 | + "disabled_reason": "out_of_credits", |
| 115 | + "cap": { "money": null, "credits": { "amount_minor": 20000, "exponent": 2 } }, |
| 116 | + "balance": null, |
| 117 | + "auto_reload": null, |
| 118 | + "disclaimer": "Usage credits cover you when you hit your plan limits. [...]", |
| 119 | + "can_purchase_credits": false, |
| 120 | + "can_toggle": false |
| 121 | + }, |
| 122 | + "member_dashboard_available": false, |
| 123 | + |
| 124 | + "seven_day_opus": null, |
| 125 | + "seven_day_sonnet": null, |
| 126 | + "seven_day_oauth_apps": null, |
| 127 | + "seven_day_cowork": null, |
| 128 | + "seven_day_omelette": null, |
| 129 | + "omelette_promotional": null, |
| 130 | + "tangelo": null, |
| 131 | + "iguana_necktie": null, |
| 132 | + "nimbus_quill": null, |
| 133 | + "cinder_cove": null, |
| 134 | + "amber_ladder": null |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +### Field notes |
| 139 | + |
| 140 | +**`five_hour` / `seven_day`** — the two account-wide windows. `utilization` |
| 141 | +is a float percentage; `resets_at` is ISO-8601 with microseconds and offset. |
| 142 | +The `*_dollars` fields have only been observed `null` on subscription plans. |
| 143 | + |
| 144 | +**`limits[]`** — the newer, generic limit contract (this is what the |
| 145 | +statusline parses first): |
| 146 | + |
| 147 | +| Field | Values observed | Meaning | |
| 148 | +|-------|-----------------|---------| |
| 149 | +| `kind` | `session`, `weekly_all`, `weekly_scoped` | which limit | |
| 150 | +| `group` | `session`, `weekly` | window family | |
| 151 | +| `percent` | integer | utilization | |
| 152 | +| `severity` | `normal`, `warning`, `critical` | server-side level | |
| 153 | +| `resets_at` | ISO-8601 | window end | |
| 154 | +| `scope` | `null` or `{model:{id,display_name},surface}` | `weekly_scoped` carries the model, e.g. `display_name: "Fable"`; `id` observed `null` | |
| 155 | +| `is_active` | bool | whether this is the currently binding limit | |
| 156 | + |
| 157 | +A `weekly_scoped` limit shares its `resets_at` with `weekly_all` — it is the |
| 158 | +same 7-day window, scoped to one model. |
| 159 | + |
| 160 | +**Legacy per-model fields** — `seven_day_opus` / `seven_day_sonnet` used to |
| 161 | +carry `{utilization, resets_at}`; since the `limits[]` array appeared they |
| 162 | +arrive `null`. Parsers should prefer `limits[]` and keep the old fields only |
| 163 | +as a fallback for cached data. |
| 164 | + |
| 165 | +**Reserved fields** — `tangelo`, `iguana_necktie`, `omelette_promotional`, |
| 166 | +`nimbus_quill`, `cinder_cove`, `amber_ladder`, `seven_day_oauth_apps`, |
| 167 | +`seven_day_cowork`, `seven_day_omelette`: observed only as `null`. Do not |
| 168 | +depend on them; listed so a future non-null appearance is recognized as a |
| 169 | +contract change. |
| 170 | + |
| 171 | +## Response — 429 (rate limited) |
| 172 | + |
| 173 | +Not present in the proxy capture (the CLI wasn't throttled that run), but |
| 174 | +observed regularly by this statusline's own fetches when several instances |
| 175 | +run: plain 429 with a `Retry-After: <seconds>` header (value `300` observed). |
| 176 | + |
| 177 | +Client obligations, as implemented here: |
| 178 | + |
| 179 | +- Serve the cached response while throttled; never retry inside the |
| 180 | + `Retry-After` window. |
| 181 | +- Escalate the retry gap on consecutive failures (this repo: 120s → 240s → |
| 182 | + 480s → 600s cap, `Retry-After` wins when longer). |
| 183 | +- Coordinate across processes: one shared cache + one atomic lock per |
| 184 | + account dir, so N concurrent statusline renders produce at most one fetch. |
| 185 | + |
| 186 | +## Related endpoints used by this statusline (not in this capture) |
| 187 | + |
| 188 | +| Endpoint | Purpose | |
| 189 | +|----------|---------| |
| 190 | +| `GET /api/oauth/profile` | account display name, org UUID, tier | |
| 191 | +| `GET /api/oauth/organizations/<org_uuid>/prepaid/credits` | prepaid balance for the extra-usage badge (requires `x-organization-uuid` header) | |
0 commit comments