Skip to main content

Module opencode_api

Module opencode_api 

Source
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 structures
  • [cache] - File-based caching with TTL
  • [fetch] - 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
OpenCode API catalog containing all available providers and models.
Model
A model available from a provider.
Provider
A provider supported by OpenCode.
RealCatalogLoader
Production implementation of CatalogLoader that fetches from the network.

Enums§

CacheError
Errors that can occur when loading the API catalog.

Constants§

API_URL
OpenCode API 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§

CatalogLoader
Trait for loading the OpenCode API catalog.

Functions§

load_api_catalog
Load the API catalog from cache or fetch if expired.