Connect Pi to AI Gateway
How to configure Pi's provider file to use an AI Gateway project model.
This guide explains how to add an AI Gateway project model to Pi’s provider configuration.
Before you start
Section titled “Before you start”- Install Pi.
- Issue a Gateway Key from the Gateway Keys menu of the project you want to use. See Issue a Gateway Key.
- Check that the model appears in the Models menu of the same project.
A Gateway Key is a secret. Do not put the key value directly in source control or a shared configuration file.
1. Set the Gateway Key
Section titled “1. Set the Gateway Key”Set the key as an environment variable in the shell where you run Pi:
export AI_GATEWAY_API_KEY='<your Gateway Key>'To keep this setting in new terminals, configure it in your shell profile or secret manager.
2. Configure Pi
Section titled “2. Configure Pi”In AI Gateway, open the project you want to use, then open Models in the top menu. In the row of the model you want, select the gear icon in the Installation column and check the Gateway base URL and model ID.
Add or merge the Gateway provider in ~/.pi/agent/models.json. The exact API value depends on the model’s provider type: use openai-responses for Codex provider models and openai-completions for other OpenAI-compatible models.
{ "providers": { "ai-gateway": { "baseUrl": "https://<gateway-host>/v1/", "api": "openai-completions", "apiKey": "$AI_GATEWAY_API_KEY", "models": [ { "id": "<provider-name>/<model-id>" } ] } }}If the file already exists, keep existing providers and merge the Gateway entry instead of overwriting the whole file.
3. Check the connection
Section titled “3. Check the connection”Restart Pi so it reads the updated provider file. Select the configured model and send a short request. If a response arrives, the connection works.
If the model does not appear
Section titled “If the model does not appear”- Confirm that
baseUrlends at the Gateway/v1/path shown in the setup dialog. - Confirm that
apiKeyrefers to theAI_GATEWAY_API_KEYenvironment variable. - Confirm that the model ID exactly matches the provider/model value shown in the setup dialog.
- Confirm that the model is allowed in that project’s Models menu.