Skip to content
AI GatewayAI Gateway Manual

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.

  • 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.

Set the key as an environment variable in the shell where you run Pi:

Terminal window
export AI_GATEWAY_API_KEY='<your Gateway Key>'

To keep this setting in new terminals, configure it in your shell profile or secret manager.

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.

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.

  1. Confirm that baseUrl ends at the Gateway /v1/ path shown in the setup dialog.
  2. Confirm that apiKey refers to the AI_GATEWAY_API_KEY environment variable.
  3. Confirm that the model ID exactly matches the provider/model value shown in the setup dialog.
  4. Confirm that the model is allowed in that project’s Models menu.