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.

Packages

Package details

extension

Install pi-merge-gateway from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-merge-gateway
Package
pi-merge-gateway
Version
0.1.0
Published
Sep 6, 2026
Downloads
150/mo · 14/wk
Author
uuraktas
License
MIT
Types
extension
Size
15.2 KB
Dependencies
0 dependencies · 0 peers
Pi manifest JSON
{
  "extensions": [
    "./index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

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