/** * rate-limit-headers.ts * * A single, provider-agnostic parser for the rate-limit / quota headers that * upstream LLM providers return on EVERY response (success and 429 alike), so * the runtime can maintain a quota snapshot and warn before a limit is hit * rather than only reacting after a 429. * * Covers the three families seen in the wild: * - Anthropic: `anthropic-ratelimit-{requests,tokens}-{limit,remaining,reset}` * (reset is an ISO-8601 timestamp) plus `anthropic-ratelimit-unified-*`. * - OpenAI / OpenAI-compatible: `x-ratelimit-{limit,remaining,reset}-{requests,tokens}` * (reset is a duration like `1s`, `6m0s`, or `1h2m3s`). * - IETF draft `RateLimit` (`ratelimit-limit`, `ratelimit-remaining`, * `ratelimit-reset`, reset is delta-seconds). * Plus the universal `retry-after` (delta-seconds or an HTTP-date). * * HONESTY IDIOM: a field is populated ONLY when a header actually carried it. * `parseRateLimitHeaders` returns null when NO recognized header was present, so * a caller records a signal only for a genuine observation, never a fabricated * "full quota". The requests dimension is preferred for limit/remaining (the * fan-out assessment reasons over request counts); the tokens dimension is used * only as a fallback when no requests header is present. */ /** A normalized rate-limit observation parsed from one response's headers. */ export interface ParsedRateLimit { /** Observed window limit (requests preferred, else tokens), when a header carried it. */ readonly limit?: number | undefined; /** Observed remaining in the window (requests preferred, else tokens), when a header carried it. */ readonly remaining?: number | undefined; /** Epoch ms the window resets, when a reset header carried it. */ readonly resetAt?: number | undefined; /** Retry-after the provider asked for (ms), when a `retry-after` header carried one. */ readonly retryAfterMs?: number | undefined; } /** A minimal, header-shape-agnostic reader: Headers, a plain record, or an array of pairs. */ export type HeaderSource = Headers | Record | ReadonlyArray; /** Parse an OpenAI-style duration (`1s`, `6m0s`, `1h2m3s`, `500ms`) to milliseconds. */ export declare function parseOpenAiResetDurationMs(value: string | undefined): number | undefined; /** Parse a `retry-after` value (delta-seconds or an HTTP-date) to milliseconds. */ export declare function parseRetryAfterMs(value: string | undefined, now: number): number | undefined; /** * Parse rate-limit headers from a response. Returns null when no recognized * header was present (nothing observed). `now` is injectable for testing. */ export declare function parseRateLimitHeaders(source: HeaderSource, now?: number): ParsedRateLimit | null; //# sourceMappingURL=rate-limit-headers.d.ts.map