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
/modelspayloads (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
Ton 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 bymax_bytes + chunk_size.