Skip to content

Model providers and custom endpoints

Which model an agent runs, and against which endpoint, is a ledger scalar per agent — model, skill_model, provider, and an endpoint: block. agentctl agents set <name> <key> <value> records it; apply renders it.

A pi model mapping can also set the request tier and reasoning effort:

model: { provider: openai, name: gpt-6-luna, service_tier: fast, reasoning_effort: low }

service_tier currently accepts fast and requires a pinned OpenAI model; unset uses OpenAI's default tier. Fast-mode usage costs are tier-adjusted. reasoning_effort accepts Pi's thinking levels (off, minimal, low, medium, high, xhigh, max) and is applied when the session starts; unset preserves Pi's configured default. After changing either field, apply <name> renders the per-agent environment and restarts that agent.

A Pi model_choices: entry may explicitly opt into zero metered API token cost:

model_choices:
  local-model:
    provider: example-provider
    model: example-model
    self_hosted: true

The flag is optional and defaults to false; it does not mean infrastructure is free. It applies only when Pi actually selects that configured provider and model. Pi records an immutable pricing snapshot beside the transcript and starts a new transcript when its pricing identity changes. Legacy transcripts without an identity are not reused for a self-hosted choice. A self-hosted call is refused if the snapshot cannot be persisted and verified. In-session SDK model switches are refused for such sessions.

Rollback/mixed-version warning: older Pi runtimes can delete or replace a tier sidecar when re-acquiring a transcript. Do not run old and new runtimes concurrently against the same transcripts or treat rollback as pricing-safe; preserve snapshots and reconcile usage before any rollback. A legacy tier-only snapshot is retained unchanged, so its pre-upgrade pricing identity is unknown.

Every endpoint override is optional and off by default. Unset means the runtime's own vendor API. Two endpoint shapes exist and they are mutually exclusive — setting one requires clearing the other:

claude pi
endpoint_base_url rendered as ANTHROPIC_BASE_URL rendered as PI_BASE_URL, a base-URL override on a named provider
foundry_resource / foundry_base_url rendered as ANTHROPIC_FOUNDRY_RESOURCE / ANTHROPIC_FOUNDRY_BASE_URL ignored — pi has no foundry provider

Two refusals, both silent misconfigurations otherwise:

  • A pi agent with endpoint.foundry_* set is warned that the field is ignored and the agent stays on its provider's own endpoint. Use endpoint.base_url for a pi gateway.
  • A pi agent with endpoint.base_url but no model.provider is warned that the URL is ignored. A pi base URL overrides a named provider; with none pinned there is nothing to override. Fix with agentctl agents set <name> provider <name>.

For claude, --provider selects anthropic (default) or foundry; choosing foundry means declaring the endpoint with agents set <name> foundry_resource <resource> or foundry_base_url <url>.

Where the credential lives

The endpoint: block is non-secret by construction — the ledger is a plaintext git repo, so no key field exists there and none ever will. The matching credential is a per-agent secret in the sops store, and which var it goes under follows the mode:

mode store the key as (either one)
claude, endpoint_base_url ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN
claude, foundry_resource / foundry_base_url ANTHROPIC_FOUNDRY_API_KEY or ANTHROPIC_FOUNDRY_AUTH_TOKEN (an Entra bearer token)
pi, endpoint_base_url the pinned provider's own var — see below

A pi base URL is an override of a provider. The credential is therefore unchanged from a pi agent with no custom endpoint:

provider var
anthropic ANTHROPIC_API_KEY
openai OPENAI_API_KEY
google / gemini GEMINI_API_KEY
groq GROQ_API_KEY
cerebras CEREBRAS_API_KEY
xai XAI_API_KEY
openrouter OPENROUTER_API_KEY
anything else <NAME>_API_KEY, uppercased
sudo agentctl secret set ANTHROPIC_FOUNDRY_API_KEY --agent <name> --value "$KEY"
printf %s "$KEY" | sudo agentctl secret set ANTHROPIC_FOUNDRY_API_KEY --agent <name>

The second form keeps the key out of argv, which is world-readable on a multi-agent host.

apply renders both halves into separate files:

file holds read by
~/.config/agentctl/agent.env CLAUDE_MODEL, CLAUDE_SKILL_MODEL, ANTHROPIC_BASE_URL, ANTHROPIC_FOUNDRY_* start-agent.sh and cron-run.sh, both under set -a so the vars reach the claude child
/etc/agentctl/env/agent-<name>.env the sops-rendered secrets the unit's EnvironmentFile=
~/.config/agentctl/pi-agent.env PI_PROVIDER, PI_MODEL, PI_BASE_URL, PI_SERVICE_TIER, PI_REASONING_EFFORT, PI_SKILL_MODEL the pi bridge

Nothing in the endpoint block is written by hand. apply reconciles rather than upserts. Clearing endpoint_base_url removes ANTHROPIC_BASE_URL on the next apply, so a decommissioned gateway stops taking traffic.

Azure AI Foundry, end to end

Foundry is claude-only. Three commands on an existing agent:

sudo agentctl secret set ANTHROPIC_FOUNDRY_API_KEY --agent ada --value "$FOUNDRY_KEY"
sudo agentctl agents set ada foundry_resource my-foundry-resource
sudo agentctl apply ada

foundry_base_url "$URL" is the alternative spelling — the full endpoint URL Azure shows for the resource, instead of the resource name. Set one, not both.

At add time the key can ride along, and only the key:

sudo agentctl agents add ada --runtime claude --user-email ada@example.com \
  --api-key "$FOUNDRY_KEY" --provider foundry

--provider foundry chooses which var the key is stored under and nothing else. It declares no endpoint, so agents add prints the agents set command still owed — a Foundry key with no endpoint starts an agent that fails every turn. On a claude agent the flag takes anthropic (the default) or foundry; any other value warns and the key is stored as ANTHROPIC_API_KEY.

Model ids pass through untranslated. agentctl hands the model scalar to claude --model verbatim and performs no deployment-name mapping. Resolving that id to a deployment is the Foundry client's job, not agentctl's. If a deployment is named differently from the model id, the model scalar is where that name goes.

--provider the flag and provider the ledger scalar are different things. The flag is consumed at add time to pick a key var. The scalar is a pi concept. On a claude agent set to anything but anthropic, agents validate warns that it is ignored — claude speaks only Anthropic.

A custom base URL

claude, against a self-hosted or corporate Anthropic-compatible gateway:

sudo agentctl secret set ANTHROPIC_API_KEY --agent ada --value "$GATEWAY_KEY"
sudo agentctl agents set ada endpoint_base_url https://gateway.corp.example/anthropic
sudo agentctl apply ada

pi, where the provider must be pinned first — the base URL overrides a named provider:

sudo agentctl agents set bo provider openai
sudo agentctl agents set bo model <model-id>
sudo agentctl secret set OPENAI_API_KEY --agent bo --value "$KEY"
sudo agentctl agents set bo endpoint_base_url https://gateway.corp.example/v1
sudo agentctl apply bo

PI_BASE_URL is narrower than the claude equivalent: it layers a base-URL override over the built-in provider. The model catalog, the per-model costs, the api implementation and the provider's own env-var auth all stay as pi ships them; only the URL moves. It declares no new provider, which is why one has to be named.

Switching modes goes through an explicit clear. agents set refuses a second endpoint key while another is declared:

sudo agentctl agents set ada endpoint_base_url ""
sudo agentctl agents set ada foundry_resource my-foundry-resource

agents set also refuses a base URL with no http:// or https:// scheme. A bare host reaches the runtime as an unusable URL and fails at the first turn.

A subscription instead of a metered key (pi)

A pi agent can run on a Claude Pro/Max or ChatGPT/Codex subscription rather than a metered API key. The credential is not a ledger field and not a secret-store entry: it is an OAuth credential, one slot per provider id, written into the agent's own ~/.pi/agent/auth.json by agentctl login — see Logging an agent in. What the ledger still has to carry is the model_choices: entry the agent's model scalar points at.

In the cockpit's Connections panel these two cards are labeled Claude Subscription and OpenAI Subscription — short product names rather than the providers' own longer marketing strings, so the panel reads as "the subscription option for this provider," not two unrelated things.

Which providers accept which credential:

provider id pi's name for it API key subscription OAuth connect it with
anthropic Anthropic ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_OAUTH_TOKEN yes — Claude Pro/Max, same slot as the key login pi-anthropic
openai-codex OpenAI Codex none — the provider declares no API-key auth at all the only way in login pi-openai-codex

The login page is the authoritative list of provider keys agentctl login takes; the column above says which credential slot each one fills.

★ There is no pi-openai (plain ChatGPT-subscription, Responses-API) key — removed 2026-11-19. It shared pi-ai's openai provider id with the metered path above, so connecting it could silently replace a working metered credential, and its underlying "Sign in with ChatGPT" grant needs a separate org-admin-enabled plan-usage permission that most ChatGPT Business/Enterprise accounts don't have toggled on. openai-codex has its own provider id, can never collide with anything, and Codex access is bundled directly into ChatGPT Plus/Pro/Business/Enterprise with no extra admin step — which is why it is the only OpenAI subscription route offered.

The two keys map onto two different cockpit connect flows, and which one a card uses is the server's call (code_flow on the card, plus the presence of userCode on the start response): pi-anthropic finishes with a code — the "code#state" Anthropic's own callback page shows — that the owner pastes back into the cockpit; pi-openai-codex is RFC 8628 device-code, so the cockpit SHOWS a short code the owner types into OpenAI's page and collects nothing, while the cockpit's status poll both checks and advances the exchange server-side.

A stored credential owns its provider id exclusively. Ambient environment variables are consulted only when nothing is stored, and a failed OAuth refresh raises rather than falling back to a key. So connecting a subscription on anthropic takes over the slot a metered key was using; openai-codex is a separate slot and can never collide with an existing openai configuration.

model_choices: is hand-authored

No catalog ships with the package and nothing seeds one. Entries are written by hand in /opt/agentctl/agents.yaml and landed with agentctl apply; the only code that ever writes the block is the one-time apply migration that folds each pi agent's legacy per-agent provider/model/service_tier/reasoning_effort/endpoint.base_url pin into it. A fleet that has never used the feature has no model_choices: line at all.

The entry shape: no api_key_env, no base_url

A subscription entry names a provider and a model and nothing else:

field a subscription entry
provider anthropic, openai-codex or openai
model one of the shipped ids below
base_url omit
api_key_env omit
capabilities omit — an absent list means chat
service_tier omit unless provider: openai; the runtime drops the field for every other provider and bills standard
reasoning_effort optional (off, minimal, low, medium, high, xhigh, max)
self_hosted omit — see the pricing note below

Both omissions are load-bearing. The bridge registers a custom endpoint only when a base URL or an api-key variable is set; with neither, it registers nothing and the provider keeps its own auth ladder — OAuth included — along with its shipped model catalog, costs and API implementation. Naming an api_key_env points the entry back at a metered key, which is the thing being avoided, and on openai-codex it names auth the provider does not have.

Catalog ids

Ids are free-form strings, but the scheme the migration derives is provider-model[-model_template][-service_tier][-reasoning_effort][-api_key_env], lowercased with every run of non-alphanumeric characters collapsed to a single -. Writing ids that way keeps a later apply from minting a near-duplicate entry beside yours. Note what the collapse does to a dotted model id: gpt-5.6-luna under openai-codex is openai-codex-gpt-5-6-luna.

Paste-ready, against the model ids pi 1.4.0 actually ships:

model_choices:
  anthropic-claude-opus-5:
    provider: "anthropic"
    model: "claude-opus-5"
  anthropic-claude-sonnet-5:
    provider: "anthropic"
    model: "claude-sonnet-5"
  openai-codex-gpt-6-luna:
    provider: "openai-codex"
    model: "gpt-6-luna"
  openai-codex-gpt-6-sol:
    provider: "openai-codex"
    model: "gpt-6-sol"

Then point an agent at one and apply:

sudo agentctl agents set bo model anthropic-claude-opus-5
sudo agentctl apply bo

apply renders the whole catalog to ~/.pi/agent/model-choices.json and writes the entry's id — not the model name — as PI_MODEL in ~/.config/agentctl/pi-agent.env. An agent on a catalog id has no provider scalar, so PI_PROVIDER is absent by design; the provider comes from the entry.

The shipped model ids

Pinned in runtime/pi/bridge/package.json at pi 1.4.0. Chat models only; dated pins (claude-opus-4-5-20251101) and the (latest) aliases are omitted here but are equally valid model: values.

provider model ids
anthropic claude-opus-5-5, claude-opus-5, claude-opus-4-8, claude-opus-4-7, claude-opus-4-6, claude-opus-4-5, claude-sonnet-5-5, claude-sonnet-5, claude-sonnet-4-6, claude-sonnet-4-5, claude-haiku-5-5, claude-haiku-4-5, claude-fable-5-1, claude-fable-5
openai-codex gpt-6.1-sol, gpt-6-sol, gpt-6-luna, gpt-6-astra, gpt-5.6-terra, gpt-5.6-sol, gpt-5.6-luna

A model id the catalog does not know fails at the first turn, not at apply. Read the shipped list rather than a release note: providers/data/anthropic.json and openai-codex.json under the bridge's @earendil-works/pi-ai are the authority, and they move with the pinned version.

gpt-6-luna under two providers is not a duplicate

Every one of openai-codex's seven model ids also exists under plain openai — the Codex set is a strict subset. The model name says nothing about which account pays:

catalog id provider credential who bills
openai-gpt-6-luna openai OPENAI_API_KEY, or a ChatGPT credential on that same slot per token, against the OpenAI API account
openai-codex-gpt-6-luna openai-codex ChatGPT Plus/Pro OAuth only the subscription

Two entries that differ only in the provider half of the id are therefore two different billing routes to the same model, and both are legitimate in one catalog. Keep the provider in the id; an id of bare gpt-6-luna makes the distinction invisible at every point it matters — the picker, PI_MODEL, and the usage rollup.

What a subscription entry does not change

Quoted cost The model picker and the usage rollup price from the model family, so a subscription entry still displays a metered per-1M rate that the subscription does not bill per token. self_hosted: true is the only field that zeroes it, and it is not cosmetic: it also turns on the pricing-snapshot guards (in-session model switches refused, a persisted and verified snapshot required per transcript). Set it deliberately or not at all.
agents validate A pi agent on a catalog id has an empty provider scalar, so the key check falls through to its default and warns provider-key: no GROQ_API_KEY in the store — agent is NEEDS-LOGIN until a key is set or OAuth self-login completes. On a subscription agent that warning is expected; it is a warning, never an error.
Decision models A decision-capable entry (capabilities: [decision]) cannot be subscription-backed. Validation requires both a credential-free HTTPS base_url and an api_key_env, which is the opposite of the shape above. See Optional permission decisions.

Which model runs where

The scalars do not override each other — they name different lanes, each resolved independently:

lane claude pi
main session model → CLAUDE_MODEL, default sonnet model → PI_MODEL, honoured only with provider also set; otherwise the bridge auto-discovers
turn-review skilling hook skill_model → CLAUDE_SKILL_MODEL, default claude-haiku-4-5 skill_model → PI_SKILL_MODEL; empty falls back to PI_MODEL
subagents each subagent's own model: frontmatter — coding and deep-work pin opus —
crons by skill, CLAUDE_CRON_MODEL overriding per unit — see Crons the headless pi runner, on PI_PROVIDER + PI_MODEL

The two claude defaults are back-filled into the ledger on apply. agents list therefore shows what an agent actually runs on, and a changed default reaches agents that already exist. pi gets neither default.

model and skill_model are ledger-only until an apply. agents set writes and commits the scalar, then names the apply you owe it. apply re-renders the env file and bounces the agent, because the ledger entry and the secret digest are both in the agent's fingerprint.

What a wrong endpoint looks like

Neither runtime treats a bad endpoint as a startup failure. The agent starts clean and every turn fails on auth or connection, which from the cockpit looks the same as the model being down. Read the earlier gates rather than wait for a turn:

gate what it says
agents set refuses the second endpoint key (the endpoint modes are alternatives; clear it first), and a base URL with no scheme
agents validate <name> pi: provider-key when the store holds no key for the pinned provider, provider when a model is pinned without one. claude: provider when the scalar is anything but anthropic (compared case-insensitively, so Anthropic passes)
apply <name> declares a custom endpoint but the store holds neither <KEY> nor <TOKEN> — every turn will fail auth (agentctl secret set <KEY> --agent <name>). The pair named follows the mode: ANTHROPIC_FOUNDRY_API_KEY/ANTHROPIC_FOUNDRY_AUTH_TOKEN for foundry, ANTHROPIC_API_KEY/ANTHROPIC_AUTH_TOKEN for a plain base URL. Plus the two pi refusals above
runtime agentctl agents logs <name> — the unit journal, via agentd

The apply-time credential check reads the secret store only for an agent that declares an endpoint.

A turn that reaches the default vendor endpoint instead of the declared one succeeds, and therefore appears in no log as a problem — it simply bills the vendor account. Confirm the vars the agent process actually received rather than the ones the ledger declares:

# the rendered endpoint block
sudo grep -E 'BASE_URL|FOUNDRY|PI_PROVIDER|PI_MODEL' /home/<name>/.config/agentctl/*.env
# and the keys the unit sources (values masked without --reveal)
sudo agentctl agents env <name>