ExAthena.ModelDiscovery (ExAthena v0.15.0)

Copy Markdown View Source

Generic HTTP-based model listing backed by an ETS TTL cache.

Reads the model_discovery block from a ProviderSpec and fetches the list of available model IDs from the provider's API endpoint. Results are cached in an ETS table for ttl_seconds (default: 300) before re-fetching.

model_discovery block

{
  "url": "https://openrouter.ai/api/v1/models",
  "path": "data.id",
  "headers": {"Authorization": "Bearer sk-or-..."},
  "ttl_seconds": 300
}
FieldRequiredDescription
urlyesHTTP GET endpoint that returns model metadata
pathnoDot-delimited path into the JSON response to extract IDs (default: "data.id")
headersnoAdditional request headers (e.g. auth)
ttl_secondsnoCache lifetime in seconds (default: 300)

Path extraction

path is a dot-delimited string. Traversal descends through map keys; when a list is encountered the remaining path is applied to each element and results are flattened. Examples:

  • "data.id" — extracts resp["data"][*]["id"]
  • "id" — extracts resp[*]["id"] when the root is a list
  • "" — returns root list elements (when they are strings)

Summary

Functions

Returns a specification to start this module under a supervisor.

Return the list of available model IDs for the provider described by spec.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

list_models(spec)

@spec list_models(ExAthena.ProviderSpec.t()) :: {:ok, [String.t()]} | {:error, term()}

Return the list of available model IDs for the provider described by spec.

Returns {:ok, [String.t()]} from the ETS cache when a fresh entry exists, or fetches from the provider's model_discovery.url and caches the result.

Returns {:error, :no_model_discovery} when spec.model_discovery is nil.