@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
Package details
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
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-blockedwhen 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: trueby default to maximize server-side cache hits.
Registered models
| Model | Context | Input | Protocol | Thinking |
|---|---|---|---|---|
agentrouter/gpt-6-astra |
272k* | text, image | OpenAI Responses | low – xhigh |
agentrouter/gpt-5.6-sol |
272k | text, image | OpenAI Completions | low – xhigh |
agentrouter/claude-opus-5 |
200k | text, image | Anthropic Messages | low – xhigh |
agentrouter/claude-opus-4-8 |
200k | text, image | Anthropic Messages | low – xhigh |
agentrouter/deepseek-v4-flash |
131k | text | OpenAI Completions | low – xhigh |
agentrouter/glm-5.3 |
131k | text | OpenAI Completions | low – xhigh |
*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 agentrouterin a Pi sessionexport AGENTROUTER_API_KEY="your-api-key"providers.agentrouter.apiKeyin~/.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
- The extension forces Pi's system prompt header to the very start of the payload.
- On a
content-blocked/ sensitive-words error, it marks the error retryable so Pi restarts the turn automatically. - Stage 1 redacts older user turns (
[Message withheld by local policy]); Stage 2 escalates to assistant turns if needed, keeping tool pairs intact. - 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.
