Overview
defineModel creates a model configuration that can be referenced by prompts and agents. Models use provider factory functions imported from provider packages for typed configuration.
Type Definition
Parameters
string
required
Unique identifier for this model configuration. Used to reference the model in prompts and agents.Best Practice: Name models by use case, not by model ID:
heavy-thinking- Complex reasoning tasksfast-response- Quick, simple responsescode-generation- Code-focused tasks
ProviderFactory
required
Provider factory function imported from a provider package.User-defined providers are also provider factories. Put them in See defineProvider for custom endpoints, API keys, icons, and model discovery overrides.
The provider determines which
providerOptions are available. TypeScript provides autocompletion based on the provider’s schema.agents/providers/ with defineProvider, then import them as a default import:string
required
The specific model identifier sent to the provider API.OpenAI examples:
gpt-4ogpt-4o-minio1-mini
llama3.1-8bqwen-3-235b-a22b-instruct-2507gpt-oss-120b
@cf/meta/llama-3.1-8b-instruct@cf/openai/gpt-oss-120b@cf/qwen/qwen3-30b-a3b-fp8
provider/model-nameanthropic/claude-sonnet-4google/gemini-2.0-flash-expmeta-llama/llama-3.3-70b-instruct
gemini-2.5-progemini-2.5-flashimagen-4.0-generate-001
llama-3.1-8b-instantopenai/gpt-oss-120bqwen/qwen3-32b
zai-org/glm-5.2deepseek/deepseek-v3.2moonshotai/kimi-k2.7-code
grok-4-0709grok-code-fast-1grok-imagine-image
number
Price per 1 million input tokens in USD. Typically required for direct providers like OpenAI and Cerebras.OpenRouter models fetch pricing automatically from the API.
number
Price per 1 million output tokens in USD. Typically required for direct providers like OpenAI and Cerebras.
number
Price per 1 million cached tokens in USD (if provider supports caching).
string[]
Array of model names to try if the primary model fails. Must reference other models defined with
defineModel.Fallbacks are tried for:- Network errors
- Rate limits (429)
- Server errors (5xx)
- Authentication errors (401)
string[]
OpenRouter only. Only use specific providers for this model.
ModelCapabilities
Model capability flags for framework behavior. See Capabilities section.
InferProviderOptions<P>
Provider-specific options. Type is inferred from the provider’s schema.See Provider Options section for available options per provider.
string[]
Enable built-in provider tools by provider-defined name. Available tools depend on the provider and model.Provider packages translate these names into their native request format and
execute them through the provider API. AgentBuilder discovers and selects the
tools, but does not execute provider tools locally.
Provider Options
OpenAI
OpenRouter
Cerebras
Cloudflare Workers AI
Capabilities
Return Value
Returns the sameModelDefinition object passed in, enabling the build system to register it.
Examples
OpenAI Model
OpenRouter Model
OpenRouter models automatically fetch pricing from the OpenRouter API. You do not need to specify
inputPrice or outputPrice.With Fallbacks
With Provider Tools
Reasoning Model
File Location
Models are auto-discovered fromagents/models/:
- Use snake_case for file names
- One model per file
- Default export required
Generated Types
After running the build,StandardAgents.Models type is generated:
Runtime Validation
defineModel performs runtime validation:
nameis required and must be a non-empty stringprovidermust be a valid ProviderFactory functionmodelis required- Pricing values must be non-negative if provided
providerOptionsare validated against the provider’s schema