Provider rate-limit header parsing — single source of truth for the
:rate-limit map surfaced on ask! / ask-code! results.
Providers send their quota-reset clock on EVERY response (success or 429) via headers; svar used to throw those headers away, so status renderers (vis footer, CLI) had no reset date to show. This ns parses the per-provider header families into ONE canonical shape:
{:resets-at-ms <epoch-ms> ;; soonest effective reset across windows :remaining <long> ;; requests remaining in the primary window :limit <long> ;; primary-window limit :windows {:requests {:resets-at-ms :remaining :limit} :tokens {:resets-at-ms :remaining :limit} :unified {:resets-at-ms :remaining :status}} :raw {<header> <value>}} ;; the rate-limit headers, verbatim
:resets-at-ms is the caller-facing 'effective date of reset' (epoch
millis, UTC). Two provider dialects:
Anthropic (:anthropic — Claude API + coding-plan OAuth): reset
values are ABSOLUTE — either unix epoch seconds
(anthropic-ratelimit-unified-reset) or RFC-3339 timestamps
(anthropic-ratelimit-{requests,tokens}-reset). The coding plan's
5h/weekly window rides on the -unified- family. CAVEAT: the
Claude coding-plan OAuth proxy (sk-ant-oat* tokens) does NOT
forward the anthropic-ratelimit-* headers, so parse returns
nil there. For the coding plan callers must prefer the OAuth
usage endpoint (/api/oauth/usage) as the source of truth and
treat this header parse as best-effort fallback only.
OpenAI / Codex (:openai-compatible-*): reset values are RELATIVE
Go-style durations (x-ratelimit-reset-requests = "6m0s",
"1s", "100ms", "1h2m3s"); resets-at-ms = now + duration.
Returns nil when no rate-limit headers are present (never throws — a quirky header must not break the LLM call).
Provider rate-limit header parsing — single source of truth for the
`:rate-limit` map surfaced on `ask!` / `ask-code!` results.
Providers send their quota-reset clock on EVERY response (success or
429) via headers; svar used to throw those headers away, so status
renderers (vis footer, CLI) had no reset date to show. This ns parses
the per-provider header families into ONE canonical shape:
{:resets-at-ms <epoch-ms> ;; soonest effective reset across windows
:remaining <long> ;; requests remaining in the primary window
:limit <long> ;; primary-window limit
:windows {:requests {:resets-at-ms :remaining :limit}
:tokens {:resets-at-ms :remaining :limit}
:unified {:resets-at-ms :remaining :status}}
:raw {<header> <value>}} ;; the rate-limit headers, verbatim
`:resets-at-ms` is the caller-facing 'effective date of reset' (epoch
millis, UTC). Two provider dialects:
- Anthropic (`:anthropic` — Claude API + coding-plan OAuth): reset
values are ABSOLUTE — either unix epoch seconds
(`anthropic-ratelimit-unified-reset`) or RFC-3339 timestamps
(`anthropic-ratelimit-{requests,tokens}-reset`). The coding plan's
5h/weekly window rides on the `-unified-` family. CAVEAT: the
Claude *coding-plan* OAuth proxy (sk-ant-oat* tokens) does NOT
forward the `anthropic-ratelimit-*` headers, so `parse` returns
nil there. For the coding plan callers must prefer the OAuth
usage endpoint (`/api/oauth/usage`) as the source of truth and
treat this header parse as best-effort fallback only.
- OpenAI / Codex (`:openai-compatible-*`): reset values are RELATIVE
Go-style durations (`x-ratelimit-reset-requests` = "6m0s",
"1s", "100ms", "1h2m3s"); resets-at-ms = now + duration.
Returns nil when no rate-limit headers are present (never throws — a
quirky header must not break the LLM call).(parse api-style headers)(parse api-style headers now-ms)Parse provider rate-limit headers into the canonical :rate-limit
map (see ns docstring). api-style selects the header dialect;
headers is the response header map. now-ms (optional) anchors
OpenAI relative durations — defaults to System/currentTimeMillis.
Returns nil when no rate-limit headers are present.
Parse provider rate-limit headers into the canonical `:rate-limit` map (see ns docstring). `api-style` selects the header dialect; `headers` is the response header map. `now-ms` (optional) anchors OpenAI relative durations — defaults to `System/currentTimeMillis`. Returns nil when no rate-limit headers are present.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |