@bismawy/pi-agentrouter

AgentRouter provider for pi — routes to GPT-6 Astra, GPT-5.6 Sol, Claude Opus 4.8, Claude Opus 5, DeepSeek V4 Flash, and GLM 5.3

Packages

Package details

extension

Install @bismawy/pi-agentrouter from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@bismawy/pi-agentrouter
Package
@bismawy/pi-agentrouter
Version
1.4.2
Published
Sep 12, 2026
Downloads
1,453/mo · 133/wk
Author
bismawy
License
MIT
Types
extension
Size
53.4 KB
Dependencies
0 dependencies · 1 peer
Pi manifest JSON
{
  "extensions": [
    "./index.ts"
  ],
  "image": "https://raw.githubusercontent.com/bismawy/pi-agentrouter/main/assets/screenshot.webp"
}

Security note

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

README

pi-agentrouter

Unified AgentRouter provider for the pi coding agent — routes GPT-6 Astra, GPT-5.6 Sol, Claude Opus 4.8 / 5, DeepSeek V4 Flash, and GLM 5.3 under a single agentrouter/ namespace with WAF auto-recovery and payload sanitization.

pi package · npm · Issues

npm license

What it does

  • Per-model protocol routing: GPT-6 Astra uses OpenAI Responses, Claude models use Anthropic Messages, and the rest use OpenAI Completions — all under one agentrouter/ provider.
  • WAF header & language guard: forces Pi's canonical system header to byte 0 (prevents 400 content-blocked when custom instructions precede it) and applies language framing on user turns.
  • Self-healing WAF redaction: when AgentRouter's content filter false-positives on multilingual histories, older turns are redacted in two stages and the turn is marked retryable — the latest request is preserved without user disruption.
  • Payload sanitization: strips ANSI escape codes, null bytes, control characters, and orphan Unicode surrogates before dispatch.
  • Prompt cache affinity: injects sendSessionAffinityHeaders: true by default to maximize server-side cache hits.

Registered models

Model Context Input Protocol Thinking
agentrouter/gpt-6-astra 272k* text, image OpenAI Responses lowxhigh
agentrouter/gpt-5.6-sol 272k text, image OpenAI Completions lowxhigh
agentrouter/claude-opus-5 200k text, image Anthropic Messages lowxhigh
agentrouter/claude-opus-4-8 200k text, image Anthropic Messages lowxhigh
agentrouter/deepseek-v4-flash 131k text OpenAI Completions lowxhigh
agentrouter/glm-5.3 131k text OpenAI Completions lowxhigh

*Astra currently reuses Sol's configured 272,000-token context and 16,384-token output limits; these are local defaults, not confirmed AgentRouter limits. Responses API is required for function tools with reasoning enabled. Existing models keep their original protocols.

Install

pi install npm:@bismawy/pi-agentrouter

Then supply your AgentRouter API key one of three ways:

  • /login agentrouter in a Pi session
  • export AGENTROUTER_API_KEY="your-api-key"
  • providers.agentrouter.apiKey in ~/.pi/agent/models.json

No account yet? Register via AgentRouter (referral) for a $50 bonus.

Pick any model with /model (e.g. agentrouter/gpt-5.6-sol).

How it works

  1. The extension forces Pi's system prompt header to the very start of the payload.
  2. On a content-blocked / sensitive-words error, it marks the error retryable so Pi restarts the turn automatically.
  3. Stage 1 redacts older user turns ([Message withheld by local policy]); Stage 2 escalates to assistant turns if needed, keeping tool pairs intact.
  4. Redaction depth resets on new conversations or compaction.

Text-only models (deepseek-v4-flash, glm-5.3) are declared input: ["text"] so image payloads from earlier turns don't produce AgentRouter 400 errors.

Development

Run the regression check against the actual registered extension hooks (no API key or network required):

bun ./check-framing.ts
# Or Node.js 22.18+:
npm test

Covers Responses text/image framing, empty content, function-call/result pairing, reasoning items, sticky WAF redaction, and Chat Completions/Anthropic compatibility.

License

Distributed under the MIT license.

Developer

Developed and maintained by Bisma.