Liking cljdoc? Tell your friends :D
Clojure only.

com.blockether.svar.internal.ratelimit

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:

{:reset-at <epoch-ms> ;; soonest effective reset across windows :remaining <long> ;; requests remaining in the primary window :limit <long> ;; primary-window limit :windows {:requests {:reset-at :remaining :limit} :tokens {:reset-at :remaining :limit} :unified {:reset-at :remaining :status}} :raw {<header> <value>}} ;; the rate-limit headers, verbatim

:reset-at 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.

  • OpenAI / Codex (:openai-compatible-*): reset values are RELATIVE Go-style durations (x-ratelimit-reset-requests = "6m0s", "1s", "100ms", "1h2m3s"); reset-at = 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:

  {:reset-at  <epoch-ms>          ;; soonest effective reset across windows
   :remaining <long>              ;; requests remaining in the primary window
   :limit     <long>              ;; primary-window limit
   :windows   {:requests {:reset-at :remaining :limit}
               :tokens   {:reset-at :remaining :limit}
               :unified  {:reset-at :remaining :status}}
   :raw       {<header> <value>}} ;; the rate-limit headers, verbatim

`:reset-at` 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.

- OpenAI / Codex (`:openai-compatible-*`): reset values are RELATIVE
  Go-style durations (`x-ratelimit-reset-requests` = "6m0s",
  "1s", "100ms", "1h2m3s"); reset-at = now + duration.

Returns nil when no rate-limit headers are present (never throws — a
quirky header must not break the LLM call).
raw docstring

parseclj

(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.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close