~/.pi/agent/models.json, so you add the gateway once and every model behind it shows up in Pi’s model picker.
What is Pi?
Pi is a minimal, extensible coding agent that runs in your terminal. It reads and edits files, runs shell commands, and can be extended with TypeScript extensions, skills, and prompt templates. Pi talks to models through three wire protocols (OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages), and the TrueFoundry AI Gateway serves all three, so you can route any model in your gateway through Pi.Prerequisites
- A TrueFoundry account with at least one model provider configured. See the Gateway quick start.
- A TrueFoundry API key. See Authentication.
-
Node.js 22.19 or later, and Pi installed:
Add TrueFoundry as a provider
1
Get your gateway base URL and model IDs
Open the AI Gateway playground and copy the base URL and model IDs from the unified code snippet. Model IDs use the 
provider-account/model format, for example openai-main/gpt-4o. See how to find the gateway base URL.
2
Export your API key
Pi resolves the key from an environment variable at request time, so the key never sits in the config file. Add this to your shell profile:
3
Create models.json
Create The provider-level
~/.pi/agent/models.json with a truefoundry provider. Replace {GATEWAY_BASE_URL} with your gateway base URL and the model IDs with your own:~/.pi/agent/models.json
api is the default for every model, and a model can override it. Pi appends the right path to baseUrl for each protocol (/chat/completions, /responses, or /messages), so set baseUrl to the gateway root, not to a full endpoint.4
Check that Pi sees the models
TRUEFOUNDRY_API_KEY isn’t set in the current shell. Pi hides models whose API key it can’t resolve.Provider fields
Use Pi with the gateway
Start an interactive session on a TrueFoundry model:--provider explicitly. Pi accepts provider/id in --model, and gateway model IDs already contain a slash, so without --provider Pi can read openai-main as the provider name.
Inside a session, run /model to switch between models. Opening /model reloads models.json, so edits apply without a restart.
Run a single prompt non-interactively:
application: pi metadata from the X-TFY-METADATA header.
Connect MCP Gateway servers
Pi supports remote MCP servers over Streamable HTTP. Point it at a server registered on the MCP Gateway and its tool calls get the gateway’s access control, guardrails, and audit logs. Copy the server URL from the How To Use tab on the server’s page in TrueFoundry. It has the form{GATEWAY_BASE_URL}/<tenant>/mcp/<server>/server.
- Sign in with TrueFoundry
- API key
Add the server without credentials, then sign in through the browser:Pi stores the tokens in
~/.pi/agent/mcp-auth.json and refreshes them when they expire. Run pi mcp logout github to delete them.connected and the number of tools it exposes. A server that needs OAuth shows needs sign-in until you run pi mcp login.
Add -l to pi mcp add to write the server to .pi/mcp.json in the current project instead of the global file. Inside a session, run /mcp to see server status.