Expand description
Remote provider preset catalog — download, cache, and merge with the
bundled + providers.d preset sources.
§Design
The bundled providers.toml is the compile-time fallback. A JSON cache
file at <user_data_dir>/providers_cache.json (written by
recursive providers update) holds presets fetched from an upstream
catalog URL. When the kernel resolves the effective preset list (see
crate::providers::all_presets_effective), cached presets override
bundled entries with the same id (so stale bundled pricing gets
refreshed upstream), while bundled presets absent from the cache are
kept as-is. User overrides from providers.d/ are layered on top by
crate::providers::all_presets_effective.
§Cache file format
{
"schema_version": 1,
"updated_at": "2026-06-06T00:00:00Z",
"source_url": "https://...",
"providers": [ ... ]
}The providers array uses the same structure as ProviderPreset plus
the same optional fields (anthropic_api_base, pricing, etc.).
§Network policy
The only network touch is fetch_and_save, invoked explicitly by
recursive providers update (and, if enabled, the best-effort
spawn_background_refresh). Preset lookup never hits the network —
load_cache reads a local JSON file. URLs are validated by
validate_providers_url which mirrors the SSRF guard in
tools::web_fetch (scheme + loopback/private/metadata blocking).
Structs§
- Providers
Cache - On-disk cache envelope.
Constants§
- CACHE_
TTL - How old the cache can be before
needs_updatereturns true. - DEFAULT_
PROVIDERS_ URL - Default upstream catalog. Users can override via the
RECURSIVE_PROVIDERS_URLenv var orrecursive providers update --url. The repojeffkit/recursive-providerspublishesproviders.jsonhere. - PROVIDERS_
URL_ ENV - Env var override for the upstream URL.
Functions§
- cache_
path - Return path to the cache file:
<user_data_dir>/providers_cache.json. - configured_
url - Return the configured upstream URL:
RECURSIVE_PROVIDERS_URLif set, otherwiseDEFAULT_PROVIDERS_URL. - fetch_
and_ save - Download the providers JSON from
url, parse it, write to the cache file, and return the parsedProvidersCache. The URL is validated byvalidate_providers_urlbefore any request is made. - load_
cache - Load the cache from disk. Returns
Noneif the file is absent or unreadable — callers fall back to bundled presets in that case. - merge_
over_ bundled - Merge cached presets over bundled ones. For each preset in
cache, the cached copy wins (placed first); bundled presets whoseidis absent from the cache are appended afterwards. Used bycrate::providers::all_presets_effective. - needs_
update - True if the cache is absent or older than
CACHE_TTL. - spawn_
background_ refresh - Spawn a best-effort background task that silently refreshes the cache if
it is stale. Errors are logged at
debuglevel and never surface to the caller. Returns immediately; the refresh happens concurrently. No-op if the cache is fresh. - validate_
providers_ url - Validate an upstream catalog URL. Mirrors the SSRF guard in
tools::web_fetch: requires anhttp(s)scheme and rejects loopback / private / link-local / cloud-metadata hosts so a misconfiguredRECURSIVE_PROVIDERS_URLcannot be turned into an internal-network probe.