What are Models?
Models in Standard Agents define the LLM configurations that your agents and prompts use for AI responses. Each model configuration specifies which provider to use, the specific model ID, fallback models for resilience, and pricing for cost tracking.Quick Example
agents/models/heavy_thinking.ts
agents/prompts/my_prompt.ts
Naming Models
This approach provides several benefits:- Swap models easily - Change the underlying model without updating prompts
- Clear intent - Team members understand what each model is for
- Environment flexibility - Use different models in dev vs production
heavy-thinking- Complex reasoning tasksfast-response- Quick, simple responsescode-generation- Code-focused taskseval- Evaluation and scoringbudget- Cost-conscious general usecreative-writing- Creative content generation
gpt-4o- Ties the name to a specific modelclaude-sonnet- Same issue, hard to swap latermodel-1- No indication of purpose
Model Providers
Standard Agents supports two model providers: OpenAI (direct) and OpenRouter (access to multiple providers).OpenAI
OPENAI_API_KEY environment variable
OpenRouter
OpenRouter provides access to models from multiple providers (OpenAI, Anthropic, Google, Meta, etc.) through a single API:No pricing required: OpenRouter models automatically fetch pricing data from the OpenRouter API at runtime. You do not need to specify
inputPrice or outputPrice for OpenRouter models.provider/model-name
Example models:
openai/gpt-4oanthropic/claude-sonnet-4google/gemini-2.0-flash-expmeta-llama/llama-3.3-70b-instruct
OPENROUTER_API_KEY environment variable
Fallback Models
Fallback models provide resilience when the primary model is unavailable or fails. The system automatically retries with fallback models for:- Network errors
- Rate limits (429)
- Server errors (5xx)
- Authentication errors (401)
defineModel by their name:
Retry Sequence
When a request fails:- Primary model (attempt 1) → Failed? Retry…
- Primary model (attempt 2) → Failed? Try fallback…
- Fallback 1 (attempt 1) → Failed? Retry…
- Fallback 1 (attempt 2) → Failed? Try next fallback…
- Fallback 2 (attempt 1) → Failed? Retry…
- Fallback 2 (attempt 2) → Failed? Throw error
Pricing Configuration
Configure pricing to track token costs across your application:Current Pricing Examples
| Model | Input Price | Output Price |
|---|---|---|
| GPT-4o | $2.50 | $10.00 |
| GPT-4o-mini | $0.15 | $0.60 |
| o1-mini | $1.10 | $4.40 |
Prices shown may change. Check provider websites for current pricing. OpenRouter models fetch pricing automatically.
Type Safety
After defining models, Standard Agents generates theStandardAgents.Models type:
Common Patterns
Cost-Optimized Chain
Use cheaper models with expensive fallbacks:Multi-Provider Resilience
Fallbacks across providers for maximum uptime:Environment Setup
Configure provider API keys as environment variables:.dev.vars
wrangler.jsonc:
wrangler.jsonc
File Organization
Models are auto-discovered from theagents/models/ directory:
- Use snake_case for file names:
heavy_thinking.ts,fast_response.ts - One model per file
- Default export required