Skip to Content
Platform
How-toChoose models

Choose and change models

The recipe picks the model; the runtime decides whose key pays for it.

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

agents/agent.yaml
name: agent ai: model: anthropic/<model> thinking_level: medium # off | minimal | low | medium | high | xhigh | max

2. Choose whose key pays

.introspection/support-agent.yaml
name: support-agent path: . runtime: llm_mode: byok
llm_modeKeyProviders
managed (default)Introspection’s, through its model gatewayAnthropic, OpenAI, Gemini, OpenRouter
byokYour own model keysAny 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
ProviderHostHeader
Anthropicapi.anthropic.comx-api-key: <key> (no prefix)
OpenAIapi.openai.comAuthorization: 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.

agents/agent.yaml
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
SettingEffect
options.cache_retentionClaude 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 keyspi-ai 1.1 request options with plain values: max_tokens, temperature, timeout_ms, max_retries and max_retry_delay_ms.
providers.anthropicbetas, 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.routingForwarded unchanged as OpenRouter’s provider routing.
providers.vercel_ai_gateway.routingSent 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

GoalDo
Staging runs a branch with a new modelChange ai.model on a branch, open a pull request, and pin staging to it (Test before production).
Callers choose a cheaper agentAdd a variant agent with its own ai.model and start tasks with --agent agent-fast (Define agents).
Compare models on live trafficAn 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 supportedDo this instead
A per-environment model settingA branch pinned to staging, or a variant agent.
Spend or budget capsPick a smaller model and watch cost in Metrics.
A provider the gateway doesn’t serve, on managedSwitch to byok.
byok_no_endpointsAdd an llm endpoint in scope for the runtime and environment.
401 from AnthropicThe header is x-api-key, with no Bearer prefix.
Last updated on