Expand description
OpenCode API catalog module.
This module handles fetching, caching, and querying the OpenCode model catalog
from https://models.dev/api.json. The catalog contains available providers and models
that OpenCode supports, enabling dynamic agent configuration.
§Module Structure
types- API catalog data structurescache- File-based caching with TTLfetch- HTTP fetching logic
§Dependency Injection
The CatalogLoader trait enables dependency injection for testing.
Production code uses RealCatalogLoader which fetches from the network,
while tests can provide mock implementations.
Structs§
- ApiCatalog
OpenCodeAPI catalog containing all available providers and models.- Model
- A model available from a provider.
- Provider
- A provider supported by
OpenCode. - Real
Catalog Fetcher - Production implementation of
CatalogHttpClientthat fetches from the network. - Real
Catalog Loader - Production implementation of
CatalogLoaderthat fetches from the network.
Enums§
- Cache
Error - Errors that can occur when loading the API catalog.
- Cache
Warning - Warnings that can occur during catalog loading.
Constants§
- API_URL
OpenCodeAPI endpoint for model catalog.- CACHE_
TTL_ ENV_ VAR - Environment variable for customizing cache TTL.
- DEFAULT_
CACHE_ TTL_ SECONDS - Default cache TTL in seconds (24 hours).
Traits§
- Catalog
Http Client - Trait for fetching the
OpenCodeAPI catalog. - Catalog
Loader - Trait for loading the
OpenCodeAPI catalog.
Functions§
- load_
api_ catalog - Load the API catalog from cache or fetch if expired.