Overview
defineProvider creates a named provider factory from a base provider. Use it when an API is compatible with an existing provider package but needs its own endpoint, key, icon, model list, pricing, or request behavior.
Provider files live in agents/providers/ and must default-export defineProvider(...).
agents/providers/darkbloom.ts
agents/models/darkbloom_chat.ts
Type Definition
Configuration
Provider config describes values passed to the base provider factory. It is for connection-level values such as keys, endpoints, regions, account IDs, and timeouts. Per-model request options still belong inproviderOptions on defineModel.
Value Sources
| Helper | Description |
|---|---|
providerEnv(name, options) | Reads a value from an environment variable, with optional default, required, valueType, and description metadata |
providerValue(value) | Uses a literal constant value |
providerConst(value) | Alias for providerValue(value) |
defaultEnv is used. For example, an OpenAI-based provider that only overrides baseUrl still requires OPENAI_API_KEY.
Overrides
Theoverrides object can replace or compose with provider behavior. Each method receives a context object and next(), where next() calls the base provider’s implementation.
next() when the override should extend the base provider. Omit next() when it should fully replace the base behavior.
Overrideable methods include generate, stream, supportsModel, getModels, getModelsPage, getModelCapabilities, getTools, getIcon, inspectRequest, and getResponseMetadata.
supportsModel and getIcon are synchronous because the provider interface expects synchronous results for those methods. Use getModels or getModelsPage for asynchronous discovery.Model Discovery Metadata
getModels and getModelsPage return ProviderModelInfo entries. Providers
may include optional pricing metadata when their catalog exposes it:
inputPrice, outputPrice, and cachedPrice use the same units as
defineModel: USD per 1M tokens. When present, AgentBuilder can copy those
values into generated model definitions so request logs can calculate cost from
token usage when the upstream response does not report a dollar cost.