Pi
Pi is a minimal, extensible terminal coding agent. Add Merge Gateway as a provider and Pi can use every model Gateway supports through a single API key, with routing policies, cost governance, and full request observability in the Gateway dashboard.
Before you start
-
Install Pi (needs Node 20 or newer):
npm install -g --ignore-scripts @earendil-works/pi-coding-agent -
Grab an API key from gateway.merge.dev/settings/api-keys and export it:
-
Decide which models fit your workflow. Gateway model names take the form
provider/model, for exampleanthropic/claude-sonnet-4-6for heavy coding orgoogle/gemini-3.5-flashfor fast, low-cost edits. Browse the full catalog withGET /v1/modelsor in the dashboard.
Configure Pi
Pi reads custom providers from ~/.pi/agent/models.json. Add a merge-gateway provider that points at Gateway’s OpenAI-compatible endpoint and lists the models you want in the picker.
Add the provider
Create or edit ~/.pi/agent/models.json. Each object under models is a Gateway provider/model name, so you choose exactly which models appear:
apiKey uses Pi’s $VAR syntax, so it picks up the MERGE_GATEWAY_API_KEY you exported. The file reloads each time you open the model picker, so you can add or remove models without restarting.
Pick a model
Run pi in your project, then /model, type merge to filter, and select a Merge Gateway model.
Send a test message
Ask Pi to make a small code change. Streaming, tool calls, and file edits all work, and the request shows up in your Gateway dashboard within a few seconds.
Caveats
Choosing which models to expose
You control the list. Each object in models is a Gateway provider/model name from GET /v1/models. The example sets contextWindow, maxTokens, and input so Pi reports the real limits and vision support. Without them Pi falls back to its defaults (128K context, 16K output, text only), which understates most models. Add cost (input and output per million tokens) if you want Pi to show spend estimates. Look these values up per model with GET /v1/models.
Reasoning models
Gateway forwards reasoning_effort to the upstream vendor, and some vendors reject it. The compat.supportsReasoningEffort: false above stops Pi from sending it, which is the safe default. Mark a model "reasoning": true so Pi shows it as reasoning-capable in the picker.
Let Gateway choose the model
Instead of hard-picking a model, attach a routing policy to your API key and let Gateway select the vendor and model per request based on your rules (cost, performance, or prompt complexity). Useful when you want cheap models for simple edits and stronger models for hard problems without switching by hand.
Persisting the configuration
The export MERGE_GATEWAY_API_KEY=... above lives in your shell, so it applies only to that terminal. To persist it, add the same line to your shell profile (~/.zshrc, ~/.bashrc, or ~/.config/fish/config.fish). The models.json provider persists on its own.
Tool calling
Pi is agentic and relies on tool calls to read and edit files. Tool calling works through Gateway for any model whose capabilities.supports_tool_calling is true on the chosen vendor route. See Tool calling.
Which models can I use?
Any model Gateway supports. Use GET /v1/models to list them, or open the Gateway dashboard and copy the model identifier.