Pi

Connect Pi to OpenGateway with a compatible models.json provider, keep your API key in the environment, and choose gateway models from /model or the CLI.

Copy this to your agent
Paste it into any AI agent. It sets up everything and saves it as the opengateway-pi skill.

Set it up by hand#

1. Install Pi#

Install the pi command with the official installer, then confirm it is available:

Bash
curl -fsSL https://pi.dev/install.sh | sh
pi --version

You can also install with npm and Node.js 22.19 or newer:

Bash
npm install -g --ignore-scripts @earendil-works/pi-coding-agent

The former @mariozechner/pi-coding-agent package is deprecated; use the current package or the installer above. See the official Pi quickstart.

2. Get an API key#

OpenGateway → API Keys → Create Key. Export the key in the shell that will start Pi:

Bash
export OPENGATEWAY_API_KEY="YOUR_OPENGATEWAY_API_KEY"

Add the export to ~/.zshrc or ~/.bashrc if you want it in new terminals. Keep the actual key out of models.json and other files that may be committed.

3. Configure the provider#

Pi reads user-level model configuration from ~/.pi/agent/models.json. This directory can be changed with PI_CODING_AGENT_DIR. Add the provider below to that file, merging it with any existing providers entries:

JSON
{
"$schema": "https://pi.dev/schemas/models.schema.json",
"providers": {
"opengateway": {
"name": "OpenGateway",
"baseUrl": "https://apis.opengateway.ai/v1",
"api": "openai-completions",
"apiKey": "$OPENGATEWAY_API_KEY",
"models": [
{
"id": "deepseek/deepseek-v4.1-flash-ultrafast",
"name": "DeepSeek V4.1 Flash UltraFast",
"reasoning": false,
"input": ["text", "image"],
"contextWindow": 1000000,
"maxTokens": 16384
},
{
"id": "z-ai/glm-5.3-flash-ultrafast",
"name": "GLM 5.3 Flash UltraFast",
"reasoning": false,
"input": ["text", "image"],
"contextWindow": 1000000,
"maxTokens": 131072
}
]
}
}
}

Pi's openai-completions API type sends requests to OpenAI Chat Completions, which OpenGateway serves for both listed models. The base URL therefore ends in /v1. This guide uses the universal chat_completions endpoint; if you instead configure anthropic-messages, use the host root without /v1 and choose a catalog model whose endpoints include messages. Pi expands $OPENGATEWAY_API_KEY (or ${OPENGATEWAY_API_KEY}) from the environment; this differs from OpenCode's {env:NAME} syntax. maxTokens is Pi's configured output cap: 16,384 is Pi's documented default for DeepSeek, not a claim about its server-side maximum; 131,072 is the configured maximum for GLM. reasoning: false avoids enabling Pi's optional reasoning controls in this example; input declares the models' text and image input. For field details, see Pi's models guide and models configuration reference.

4. Select and verify#

Start Pi in the project directory. In the TUI, run /model and choose a model under OpenGateway. To send a one-off prompt from the command line:

Bash
pi --provider opengateway --model deepseek/deepseek-v4.1-flash-ultrafast --print "Reply with OK"

A response confirms the connection. Use /model to switch models; Pi reloads models.json when the picker opens. Press Ctrl+S in the model picker to save the selection as the default for new sessions.

Models#

The recommended model is deepseek/deepseek-v4.1-flash-ultrafast; z-ai/glm-5.3-flash-ultrafast is a lower-priced alternative. To add another model, check the public model catalog for an active entry whose endpoints include chat_completions, then use the exact model ID and context_window. See /models for current pricing.

UltraFast has a per-key, per-model concurrency cap. Exceeding it returns 429 with code concurrency_limit_exceeded and a Retry-After header; reduce in-flight requests or contact support to request a higher limit. For deepseek/deepseek-v4.1-flash-ultrafast and z-ai/glm-5.3-flash-ultrafast, a request with more than 256K total input tokens has double the input price for the whole request; cache reads and output tokens are not surcharged. See UltraFast for details.

Troubleshooting#

  • 401 Unauthorized: Ensure the shell that launched Pi has OPENGATEWAY_API_KEY exported and that apiKey in models.json is $OPENGATEWAY_API_KEY. Restart Pi after changing the environment.
  • Provider or model missing: Check that the JSON is valid, the provider ID is opengateway, and the model ID is exact. Opening /model reloads models.json.
  • 429 concurrency limit: Wait for Retry-After and reduce simultaneous requests to the same UltraFast model, or contact support to request a higher per-key limit.
  • Incompatible model request: Confirm the model's catalog entry lists chat_completions; configure api as openai-completions and keep the base URL ending in /v1.
Pi — OpenGateway