> ## Documentation Index
> Fetch the complete documentation index at: https://ngrok.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Use the Pi Coding Agent with the AI Gateway

> Connect the Pi terminal coding agent to the ngrok AI Gateway to reach any model in the catalog, or a model you run yourself.

[Pi](https://pi.dev) is a terminal coding agent.
It reaches the AI Gateway as a custom provider in its models file, so one access key covers every model you list there.

## What you'll need

* [Pi](https://pi.dev) installed.
* An [access key](https://ngrok.com/docs/ai-gateway/concepts/access-keys.md) from [app.ngrok.ai](https://app.ngrok.ai).

## Add the gateway as a provider

Export your access key so Pi can read it:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"}}
export NGROK_AI_GATEWAY_KEY="ng-xxxxx-g1-xxxxx"
```

Add the gateway as a provider in `~/.pi/agent/models.json`:

```json theme={"theme":{"light":"css-variables","dark":"css-variables"}}
{
  "providers": {
    "ngrok": {
      "baseUrl": "https://gateway.ngrok.ai/v1",
      "apiKey": "$NGROK_AI_GATEWAY_KEY",
      "api": "openai-completions",
      "models": [
        { "id": "gpt-5.5" },
        { "id": "claude-sonnet-5-5" }
      ]
    }
  }
}
```

`id` is the model name Pi sends to the gateway: a model ID from the [model catalog](https://ngrok.com/docs/ai-gateway/reference/model-catalog.md), or `provider:model` to pin a provider.
It's the only field a model entry needs, though you can add `name`, `contextWindow`, and `maxTokens` to label it and track context accurately.

## Test the connection

Send a single prompt from the command line:

```bash theme={"theme":{"light":"css-variables","dark":"css-variables"}}
pi --provider ngrok --model "gpt-5.5" -p "Explain what a hash map is in two sentences."
```

In an interactive session, run `/model` and pick one of the **ngrok** models instead.

Confirm the request in AI Gateway [observability](https://ngrok.com/docs/ai-gateway/observability.md) in [app.ngrok.ai](https://app.ngrok.ai).

## Use a model you run yourself

To reach a model on your own machine, register it as a [custom provider](https://ngrok.com/docs/ai-gateway/concepts/custom-providers.md), then add its `provider:model` name to `models`, such as `ollama:llama3.2`.
See [Use a model you run yourself](https://ngrok.com/docs/ai-gateway/guides/use-a-model-you-run-yourself.md) for the full setup.

## Next steps

* [Restrict providers and models](https://ngrok.com/docs/ai-gateway/guides/restrict-providers-and-models.md): Scope what an access key can call
* [Configure fallback models](https://ngrok.com/docs/ai-gateway/guides/configure-fallback-models.md): Try another model when the first one fails
* [Observability](https://ngrok.com/docs/ai-gateway/observability.md): See which model served each request


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.