Overview
ThedefineModel function creates LLM model configurations that specify provider, model ID, fallback models, and pricing for Standard Agents.
Configuration Options
Unique identifier for this model configuration. Used to reference the model in prompts. Use snake_case or kebab-case.
LLM provider for API requests.
| Provider | Value | API Key Environment Variable |
|---|---|---|
| OpenAI | 'openai' | OPENAI_API_KEY |
| Anthropic | 'anthropic' | ANTHROPIC_API_KEY |
| OpenRouter | 'openrouter' | OPENROUTER_API_KEY |
'google' | GOOGLE_API_KEY |
The actual model ID sent to the provider API. Format varies by provider.Examples by provider:
| Provider | Example Model IDs |
|---|---|
| OpenAI | 'gpt-4o', 'gpt-4-turbo', 'gpt-3.5-turbo', 'o1-mini' |
| Anthropic | 'claude-3-opus-20240229', 'claude-3-sonnet-20240229', 'claude-3-haiku-20240307' |
| OpenRouter | 'openai/gpt-4o', 'anthropic/claude-3-opus', 'google/gemini-pro' |
'gemini-1.5-pro', 'gemini-1.5-flash', 'gemini-pro' |
Array of model names to try if this model fails. Fallbacks are tried in order after the primary model fails (2 attempts each).Fallback behavior:
- Primary model tried 2 times
- First fallback tried 2 times
- Second fallback tried 2 times
- Continue until success or all fallbacks exhausted
Provider prefixes for OpenRouter routing. Only applicable when provider is This tells OpenRouter to prefer specific providers when routing requests.
'openrouter'.Cost per 1 million input tokens in USD. Used for cost tracking.
Cost per 1 million output tokens in USD. Used for cost tracking.
Cost per 1 million cached tokens in USD. Reduced pricing for prompt caching features (Anthropic, OpenAI).
Provider-Specific Examples
OpenAI Models
- GPT-4o
- GPT-4o Mini
- o1-mini
agents/models/gpt_4o.ts
Anthropic Models
- Claude 4 Sonnet
- Claude 3 Opus
- Claude 3 Haiku
agents/models/claude_sonnet.ts
Google Models
- Gemini 1.5 Pro
- Gemini 1.5 Flash
agents/models/gemini_pro.ts
OpenRouter Models
agents/models/openrouter_claude.ts
Fallback Configurations
Basic Fallback
Multi-Provider Resilience
Cost-Tiered Fallbacks
Complete Examples
Production Configuration
agents/models/production.ts
Budget Configuration
agents/models/budget.ts
High-Performance Configuration
agents/models/high_performance.ts
Type Definitions
ModelDefinition
ModelProvider
Generated Types
After defining models, Standard Agents generates theStandardAgents.Models type:
Best Practices
Use Descriptive Names
Use Descriptive Names
Configure Fallbacks for Production
Configure Fallbacks for Production
Always configure fallbacks for production deployments:
Set Pricing for Cost Tracking
Set Pricing for Cost Tracking
Configure pricing to monitor costs:
Match Provider Format
Match Provider Format
Match the model ID format to the provider:
Organize by Purpose
Organize by Purpose
Structure your models directory by use case:
Environment Configuration
Development
.dev.vars
Cloudflare Workers
Add towrangler.jsonc for development:
wrangler.jsonc
File Structure
- Use snake_case for file names:
gpt_4o.ts,claude_sonnet.ts - One model per file
- Default export required
- File placed in
agents/models/directory