← Catalog

pi-merge-gateway

Merge Gateway (merge.dev) model provider for the pi coding agent. Live model metadata, one API key for every LLM, and thinking-stream translation for GLM-style models.

Package

Install

Install with PiG

pig install npm:pi-merge-gateway

Install with Pi

pi install npm:pi-merge-gateway
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 0.1.0 (README.md). PiG does not review it.

pi-merge-gateway

Merge Gateway (merge.dev) model provider for the pi coding agent. One API key reaches every LLM behind the Gateway. The provider loads live model metadata and translates thinking streams for GLM-style models.

Why an extension and not models.json?

A plain models.json entry works. Merge documents that setup in their pi guide. It has two gaps:

  1. Thinking stays invisible. Gateway returns model reasoning in a thinking field on chat completions. The OpenAI parser in pi reads only reasoning, reasoning_content, and reasoning_text. The provider bills the reasoning tokens, and pi never displays them. This package installs a fetch shim. It rewrites thinking to reasoning_content on responses, and back to thinking on replayed requests. GLM-style reasoning then streams, displays inside pi, and replays in tool loops.
  2. Metadata goes stale. Context window, max output tokens, pricing, and thinking levels differ per model and per vendor route. This package reads them from GET /v1/models at startup, with a static fallback. The model picker then shows real limits and real cost estimates.

Install

pi install npm:pi-merge-gateway
# git works today; the npm release is pending:
pi install git:github.com/uuraktas/pi-merge-gateway

Setup

Get an API key at gateway.merge.dev/api-keys. Then export it:

export MERGE_GATEWAY_API_KEY="mg_your_key"   # add to ~/.zshrc or ~/.bashrc to persist

Or run /login merge-gateway inside pi, and paste the key.

Models

The default model list contains one entry: zai/glm-5.3-flash. To expose a different set:

export MERGE_GATEWAY_MODELS="anthropic/claude-sonnet-4-6,google/gemini-3.5-flash,zai/glm-5.3-flash"

Model ids come from GET /v1/models or the dashboard. The package fills in context window, max output, input types, pricing, and thinking levels from the Gateway route metadata. If the gateway is unreachable and a model is not in the static snapshot, the package skips that model with a warning.

Thinking levels

When a route advertises reasoning_effort, pi maps its thinking levels onto the route values. GLM 5.3 flash accepts low, high, and max. A route that cannot disable thinking hides the off level, so pi never sends a control the vendor would reject.

How it works

pi ── streamSimple (compat dispatch) ── fetch shim ── api-gateway.merge.dev
                                        │  ▲
              reasoning_content ◄───────┘  └─── thinking (Gateway wire format)

The shim buffers whole lines before it rewrites them. The line buffer keeps a JSON key in one chunk. The shim touches object keys only. Message content stays unchanged.

License

MIT