Skip to main content

Module body_cap

Module body_cap 

Source
Expand description

Bounded HTTP body readers — cap peak memory for provider /models (and similar) calls so that a runaway multi-megabyte response cannot OOM the process during startup/registration.

Constants§

PROVIDER_METADATA_BODY_CAP
Default cap for provider catalog / metadata responses. Large enough for realistic /models payloads (OpenRouter currently ~0.5 MiB), small enough that an unbounded or hostile response cannot blow the process stack.

Functions§

json_capped
Convenience: fetch JSON with a hard body cap. Returns T on success, or an error if the cap is exceeded / parsing fails.
read_body_capped
Read an HTTP response body into memory, failing if it exceeds max_bytes. Streams chunks so the peak allocation is bounded by max_bytes + chunk_size.