Skip to main content

Module http

Module http 

Source
Expand description

The shared HTTP transport layer (hoisted from anthropic/ at Task 18): retry policy + backoff, the HttpFailure carrier, Retry-After parsing, client construction, and schema normalization. Per-wire error classification stays wire-local (body shapes and terminal heuristics genuinely differ).

Structs§

HttpFailure
A classified HTTP failure plus the retry-control signals that ride beside the error taxonomy (x-should-retry override — Anthropic-only, other wires always pass false — and Retry-After).
RetryPolicy
Transport-retry knobs (Task-12 plan §3.6; sources: Claude Code 500ms·2ⁿ cap 32s, grok’s 429-cap-2 and 120s Retry-After cap, codex’s ±10% jitter).

Functions§

backoff
Compute the pre-retry sleep for attempt (1-based). Retry-After takes precedence and bypasses the exponential cap (itself capped); otherwise exponential with ±10% jitter.
build_http_client
Build the reqwest client with the wires’ shared timeouts (30s connect, 10min total — non-streaming reasoning turns can run minutes).
normalize_input_schema
Normalize a schemars-derived schema into the input_schema/parameters the APIs accept: our flat Args structs emit no $defs/$ref (generation inlines subschemas at the source), so normalization reduces to stripping the top-level $schema meta-annotation. Shared by every wire.
parse_retry_after
Parse a Retry-After header value: integer delta-seconds only. HTTP-date forms → None (fall back to exp backoff) — grok’s simplification.
run_with_retry
Drive op until success, a terminal classification, or attempt exhaustion. Generic over the success type — the loop only inspects HttpFailure.