Skip to main content

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 tasks
  • fast-response - Quick, simple responses
  • code-generation - Code-focused tasks
ProviderFactory
required
Provider factory function imported from a provider package.
The provider determines which providerOptions are available. TypeScript provides autocompletion based on the provider’s schema.
User-defined providers are also provider factories. Put them in agents/providers/ with defineProvider, then import them as a default import:
See defineProvider for custom endpoints, API keys, icons, and model discovery overrides.
string
required
The specific model identifier sent to the provider API.OpenAI examples:
  • gpt-4o
  • gpt-4o-mini
  • o1-mini
Cerebras examples:
  • llama3.1-8b
  • qwen-3-235b-a22b-instruct-2507
  • gpt-oss-120b
Cloudflare Workers AI examples:
  • @cf/meta/llama-3.1-8b-instruct
  • @cf/openai/gpt-oss-120b
  • @cf/qwen/qwen3-30b-a3b-fp8
OpenRouter format: provider/model-name
  • anthropic/claude-sonnet-4
  • google/gemini-2.0-flash-exp
  • meta-llama/llama-3.3-70b-instruct
Google examples:
  • gemini-2.5-pro
  • gemini-2.5-flash
  • imagen-4.0-generate-001
Groq examples:
  • llama-3.1-8b-instant
  • openai/gpt-oss-120b
  • qwen/qwen3-32b
Novita AI examples:
  • zai-org/glm-5.2
  • deepseek/deepseek-v3.2
  • moonshotai/kimi-k2.7-code
xAI examples:
  • grok-4-0709
  • grok-code-fast-1
  • grok-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 same ModelDefinition 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 from agents/models/:
Requirements:
  • Use snake_case for file names
  • One model per file
  • Default export required

Generated Types

After running the build, StandardAgents.Models type is generated:
This enables type-safe model references in prompts.

Runtime Validation

defineModel performs runtime validation:
  • name is required and must be a non-empty string
  • provider must be a valid ProviderFactory function
  • model is required
  • Pricing values must be non-negative if provided
  • providerOptions are validated against the provider’s schema