Choose and change models
The model is ai.model in each agent’s YAML, as <provider>/<model_id>.
You need: a recipe (Define agents) and, for your own key,
a CLI login (the member role is enough).
1. Set the model in the recipe
name: agent
ai:
model: anthropic/<model>
thinking_level: medium # off | minimal | low | medium | high | xhigh | max2. Choose whose key pays
name: support-agent
path: .
runtime:
llm_mode: byokllm_mode | Key | Providers |
|---|---|---|
managed (default) | Introspection’s, through its model gateway | Anthropic, OpenAI, Gemini, OpenRouter |
byok | Your own model keys | Any provider Pi supports, matched by host |
The mode applies from the next version built after you merge.
byok covers the agent’s calls and live judges; a judge calls the provider in
its llm block, so bind an llm endpoint for that host too. Observation
extraction always uses Introspection’s gateway; contact us to turn it off.
3. Add your key (byok only)
Store the key as a credential, then add an llm endpoint for the provider’s
host. The provider prefix in ai.model picks the host.
introspection bindings credentials create --name ANTHROPIC_API_KEY --from-env ANTHROPIC_API_KEY -r support-agent
introspection bindings endpoints create --kind llm --name anthropic \
--endpoint-url https://api.anthropic.com \
--header 'x-api-key=${ANTHROPIC_API_KEY}' -r support-agent| Provider | Host | Header |
|---|---|---|
| Anthropic | api.anthropic.com | x-api-key: <key> (no prefix) |
| OpenAI | api.openai.com | Authorization: Bearer <key> |
Tune requests and caching
The ai block passes through to pi-ai, the model library under the
Pi runtime; the runtime runs pi 1.1, so use the
options pi-ai 1.1 accepts. ai.options takes pi-ai’s request
options in snake_case: each top-level key becomes pi-ai’s camelCase option
(cache_retention becomes cacheRetention) and its value is passed unchanged,
so a pi-ai option works without waiting for a Recipes release.
ai.providers carries provider-specific settings.
name: agent
ai:
model: anthropic/<model>
thinking_level: medium
options:
cache_retention: long # none | short (5 min) | long (1 h)
max_tokens: 8192
temperature: 0.2
timeout_ms: 120000| Setting | Effect |
|---|---|
options.cache_retention | Claude prompt caching: none turns it off, short keeps the cache for 5 minutes, long for 1 hour. Unset, the runtime uses long for Claude models, on Anthropic and on Bedrock; pi-ai’s own default is short. Other providers map the value to their own retention (OpenAI’s long is 24 hours). |
Other options keys | pi-ai 1.1 request options with plain values: max_tokens, temperature, timeout_ms, max_retries and max_retry_delay_ms. |
providers.anthropic | betas, added to the anthropic-beta header, and context_management, added to the request body. Both go to Anthropic unchecked: use full beta identifiers such as context-1m-2025-08-07, and send context_management with its own beta and a nonempty edits list, or Anthropic answers 400. |
providers.openrouter.routing | Forwarded unchanged as OpenRouter’s provider routing. |
providers.vercel_ai_gateway.routing | Sent as providerOptions.gateway on Vercel AI Gateway requests; byok is refused. |
The runtime owns credentials and transport, so an agent file that sets any of
these fails: api_key, bearer_token, headers, env, fetch, signal,
session_id, region, project, location, the azure_* keys, or
reasoning (use thinking_level). Option keys must be snake_case.
An agent with from: merges options and providers by key over its base,
until it declares its own ai.model: then its ai block starts fresh.
Run another model for one task
metadata.model and metadata.thinking_level override the recipe for that
task’s main agent. Subagents keep their own model.
introspection tasks create -r support-agent -e staging --prompt "Summarize ticket 42" \
--metadata '{"model":"anthropic/<other-model>","thinking_level":"high"}'Run another model in staging
| Goal | Do |
|---|---|
| Staging runs a branch with a new model | Change ai.model on a branch, open a pull request, and pin staging to it (Test before production). |
| Callers choose a cheaper agent | Add a variant agent with its own ai.model and start tasks with --agent agent-fast (Define agents). |
| Compare models on live traffic | An experiment whose arm overrides the agent. |
Verify
introspection tasks create -r support-agent -e staging --prompt "Say hello"
introspection conversations get <task-id>Expect the new model on the conversation’s model calls, also shown in Conversations.
Or ask your agent: “Switch support-agent to my own Anthropic key.”
Limits
| Not supported | Do this instead |
|---|---|
| A per-environment model setting | A branch pinned to staging, or a variant agent. |
| Spend or budget caps | Pick a smaller model and watch cost in Metrics. |
A provider the gateway doesn’t serve, on managed | Switch to byok. |
byok_no_endpoints | Add an llm endpoint in scope for the runtime and environment. |
| 401 from Anthropic | The header is x-api-key, with no Bearer prefix. |