model
constmodel:object
Type Declaration
Section titled “Type Declaration”retry: (
config?) =>Middleware=modelRetry
Exponential backoff retry for transient LLM failures.
Creates a model.retry() middleware that wraps LLM calls with exponential backoff.
On transient failures (rate limits, network errors, retryable model errors),
retries up to maxRetries times with exponential backoff starting at
initialDelayMs (doubling each attempt). Non-retryable errors propagate
immediately without retry.
Uses the same retry classification as the core withRetry() utility:
RateLimitError and NetworkError are retryable, AuthenticationError
and ContentFilterError are not.
Parameters
Section titled “Parameters”config?
Section titled “config?”Retry configuration. Defaults to 2 retries with 1000ms initial delay.
Returns
Section titled “Returns”Middleware that retries failed model calls with exponential backoff
Example
Section titled “Example”// Default: 2 retries, 1s initial delayagent.use(model.retry())
// Custom: 3 retries, 500ms initial delayagent.use(model.retry({ maxRetries: 3, initialDelayMs: 500 }))router
Section titled “router”router: (
config) =>Middleware=modelRouter
Route model calls by complexity.
Creates a model.router() middleware that routes model calls by complexity.
Classifies each model call as simple, medium, or complex, then overrides the model to the configured route target. Saves 60-90% on LLM costs for mixed-complexity workloads.
Parameters
Section titled “Parameters”config
Section titled “config”Routes mapping and optional custom classifier
Returns
Section titled “Returns”Middleware that routes model calls by complexity
Example
Section titled “Example”agent.use(model.router({ routes: { simple: "anthropic/claude-haiku-4-5", medium: "anthropic/claude-sonnet-4-6", complex: "anthropic/claude-opus-4-6", },}))