Pi

Add Merge Gateway as a provider in Pi to use any model with a single API key

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:

    $export MERGE_GATEWAY_API_KEY="mg_your_key"
  • Decide which models fit your workflow. Gateway model names take the form provider/model, for example anthropic/claude-sonnet-4-6 for heavy coding or google/gemini-3.5-flash for fast, low-cost edits. Browse the full catalog with GET /v1/models or 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.

1

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:

1{
2 "providers": {
3 "merge-gateway": {
4 "name": "Merge Gateway",
5 "baseUrl": "https://api-gateway.merge.dev/v1/openai",
6 "api": "openai-completions",
7 "apiKey": "$MERGE_GATEWAY_API_KEY",
8 "compat": { "supportsReasoningEffort": false },
9 "models": [
10 {
11 "id": "anthropic/claude-sonnet-4-6",
12 "name": "Claude Sonnet 4.6",
13 "reasoning": true,
14 "input": ["text", "image"],
15 "contextWindow": 1000000,
16 "maxTokens": 64000
17 },
18 {
19 "id": "google/gemini-3.5-flash",
20 "name": "Gemini 3.5 Flash",
21 "reasoning": true,
22 "input": ["text", "image"],
23 "contextWindow": 1048576,
24 "maxTokens": 65536
25 }
26 ]
27 }
28 }
29}

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.

2

Pick a model

Run pi in your project, then /model, type merge to filter, and select a Merge Gateway model.

3

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

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.

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.

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.

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.

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.

Any model Gateway supports. Use GET /v1/models to list them, or open the Gateway dashboard and copy the model identifier.

Next steps