Provider registry and model resolution. Loads provider definitions, merges config/auth/env overrides, and exposes helpers — including the locality checks that enforce closedcode's local-only egress policy — used to instantiate models.
Classes
Members
(static, constant) ConfigProvidersResult
Schema for the config-providers response: the config-defined providers and their default models.
(static, constant) Info
Schema for a resolved provider, including its source, env var names, key, and models.
(static, constant) InitError
Error: the provider SDK could not be constructed (wraps the underlying cause).
(static, constant) ListResult
Schema for the /provider list response: all providers, default model per provider, and connected ids.
(static, constant) Model
Schema for a fully-resolved model (merged from models.dev, config, env, and auth).
(static, constant) ModelNotFoundError
Error: the requested provider or model id was not found (carries fuzzy suggestions).
(static, constant) defaultLayer
The Provider layer with all its service dependencies provided.
(inner, constant) layer
Layer building the Provider service. Resolves the full provider/model database by merging the models.dev snapshot with plugin hooks, config, environment variables, and stored auth — enforcing the local-only policy by dropping any non-local provider — and exposes the lookup/SDK-resolution operations.
Methods
(static) defaultModelIDs(providers) → {Object}
Pick a default model id for each provider — the top of sort's ordering. Providers with no models are skipped (rather than crashing) so they still list.
| Name | Type | Description |
|---|---|---|
providers | Object | Map from provider id to a provider object with a |
Map from provider id to its chosen default model id.
- Type:
- Object
(static) fromModelsDevProvider(provider) → {Object}
Build an internal provider record from a models.dev provider, expanding each model and adding synthetic <id>-<mode> entries for any experimental modes (merging their cost/body/header overrides on top of the base model).
| Name | Type | Description |
|---|---|---|
provider | Object | The models.dev provider record. |
The internal provider object with id, name, env, and models.
- Type:
- Object
(static) isLocalProvider(provider) → {boolean}
Determine whether a provider talks only to local endpoints, checking its base URL and every model's API URL via isLocalURL.
| Name | Type | Description |
|---|---|---|
provider | Object | The provider definition ( |
True when the provider's base URL or any model URL is local.
- Type:
- boolean
(static) isLocalURL(url) → {boolean}
Determine whether a URL points at the local machine or a private network. Treats localhost, loopback, RFC 1918 / link-local IPv4, ULA / loopback / link-local IPv6, and .local / .lan / .internal hostnames as local.
| Name | Type | Description |
|---|---|---|
url | string | The URL to inspect. |
True when the URL host is local or private; false otherwise or when the URL is unparseable.
- Type:
- boolean
(static) parseModel(model) → {Object}
Split a "provider/model" string into branded provider and model ids (the model portion may itself contain slashes, which are rejoined).
| Name | Type | Description |
|---|---|---|
model | string | A "providerID/modelID" string. |
{providerID, modelID} with branded ids.
- Type:
- Object
(static) sort(models) → {Array}
Sort models into a preferred display order: by priority family (qwen/llama/gpt-oss) first, then "latest"-tagged ids, then id descending.
| Name | Type | Description |
|---|---|---|
models | Array | The models to sort. |
The sorted models.
- Type:
- Array
(inner) cost(c) → {Object}
Convert a models.dev cost record into the internal cost shape, defaulting missing fields to 0 and carrying over the optional >200k-context override.
| Name | Type | Description |
|---|---|---|
c | Object | The models.dev cost record (may be undefined). |
The internal cost object {input, output, cache: {read, write}, ...}.
- Type:
- Object
(inner) fromModelsDevModel(provider, model) → {Object}
Build an internal Model from a models.dev provider+model pair, deriving API info, capabilities/modalities, cost, limits, and reasoning-effort variants.
| Name | Type | Description |
|---|---|---|
provider | Object | The models.dev provider record. |
model | Object | The models.dev model record. |
The internal Model object (with variants populated).
- Type:
- Object
(inner) isPrivateIPv4(host) → {boolean}
Determine whether a host string is a private/loopback/link-local IPv4 address (loopback 127/8, RFC 1918 10/8, 172.16/12, 192.168/16, and link-local 169.254/16).
| Name | Type | Description |
|---|---|---|
host | string | The host string to test. |
True for a private/loopback IPv4 address; false otherwise or when not an IPv4 literal.
- Type:
- boolean
(inner) isPrivateIPv6(host) → {boolean}
Determine whether a host string is a loopback/private/link-local IPv6 address (::1 loopback, fc00::/7 unique-local, fe80::/10 link-local).
| Name | Type | Description |
|---|---|---|
host | string | The host string to test. |
True for a loopback/private/link-local IPv6 address; false otherwise.
- Type:
- boolean
(inner) wrapSSE(res, ms, ctl) → {Response}
Wrap a Server-Sent-Events Response so that a stalled stream is aborted if no chunk arrives within ms. Returns the response unchanged for non-positive timeouts, bodyless responses, or non-SSE content types.
| Name | Type | Description |
|---|---|---|
res | Response | The fetch Response to wrap. |
ms | number | The per-chunk read timeout in milliseconds. |
ctl | AbortController | The controller aborted when a read times out. |
The original or a timeout-guarded Response.
- Type:
- Response