npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pi-anyrouter

v0.3.2

Published

Unofficial pi provider extension for AnyRouter Claude Code and Codex Responses Lite routes

Readme

pi-anyrouter

A pi provider extension that adapts requests to the client-specific shapes accepted by AnyRouter.

It currently supports both Claude Code / Claude Agent SDK requests and Codex Responses Lite requests. It does not require a separate local relay process.

Status

Confirmed working with provider anyrouter using Claude and Codex model routes:

pi --model anyrouter/claude-opus-4-8 --no-session --no-tools -p "Reply with exactly OK"
pi --model anyrouter/gpt-5.6-sol --no-session --no-tools -p "Reply with exactly OK"

Expected output:

OK

What this package fixes

Some AnyRouter Claude endpoints, especially claude-opus-4-6, reject older or more generic Claude-style requests with errors like:

{"error":{"type":"new_api_error","message":"invalid claude code request (...)"},"type":"error"}

This package selects an adapter by model family:

  • Claude models use POST /v1/messages?beta=true with Claude Code headers, system blocks, metadata, and Anthropic SSE conversion.
  • Codex models use POST /v1/responses with the Codex Responses Lite headers/body shape and OpenAI Responses SSE conversion.

Features

  • Registers provider: anyrouter
  • Supports Claude Code and Codex Responses Lite request validation
  • No local relay/proxy required
  • Converts tool names to Claude Code naming
  • Supports reasoning via thinking + output_config
  • Built-in request/response debug dump
  • Retries transient upstream failures like HTTP 520/502/503/504 automatically
  • Packaged so it can be shared as a pi package

Install

Option A: local development checkout

Clone into a normal directory:

git clone https://github.com/xifan2333/pi-anyrouter.git
cd pi-anyrouter

Install as a pi package from the local path:

pi install .

Or install directly from a path later:

pi install /absolute/path/to/pi-anyrouter

Option B: direct git install

Once pushed to GitHub, install with:

pi install git:github.com/xifan2333/pi-anyrouter

Or pin a ref/tag:

pi install git:github.com/xifan2333/pi-anyrouter@<tag>

Option C: manual extension placement

If you only want the extension file layout, place it at either:

  • ~/.pi/agent/extensions/anyrouter/index.ts
  • .pi/extensions/anyrouter/index.ts

Then reload pi:

/reload

Config

Create:

  • ~/.pi/agent/anyrouter.json

Example:

{
  "baseUrl": "https://anyrouter.top",
  "apiKey": "YOUR_ANYROUTER_KEY_OR_ENV_NAME",
  "models": [
    {
      "id": "claude-opus-4-8",
      "name": "Claude Opus 4.8",
      "reasoning": true,
      "input": ["text"],
      "cost": {
        "input": 0,
        "output": 0,
        "cacheRead": 0,
        "cacheWrite": 0
      },
      "contextWindow": 200000,
      "maxTokens": 32000
    }
  ]
}

You can also override config values with environment variables:

  • PI_ANYROUTER_CC_CONFIG
  • PI_ANYROUTER_CC_BASE_URL
  • PI_ANYROUTER_CC_API_KEY
  • PI_ANYROUTER_CC_MAX_RETRIES (default: 10)
  • PI_ANYROUTER_CC_STREAM_MODE (default: force)

Notes:

  • apiKey can be a literal key or an environment variable name.
  • shell-command values like "!command" are intentionally not supported.
  • this package reads ~/.pi/agent/anyrouter.json by default rather than models.json.
  • PI_ANYROUTER_CC_STREAM_MODE=auto tries real SSE streaming first and falls back to the old non-stream JSON path if streaming fails before any content arrives.
  • PI_ANYROUTER_CC_STREAM_MODE=force uses SSE only; PI_ANYROUTER_CC_STREAM_MODE=off disables SSE.

Use

After installation/configuration:

/reload
/model

Choose a configured model, for example:

  • anyrouter / claude-opus-4-8
  • anyrouter / gpt-5.6-sol

Or run directly:

pi --model anyrouter/gpt-5.6-sol

Debugging

Enable request/response dumps:

PI_ANYROUTER_CC_DEBUG=1 pi --model anyrouter/gpt-5.6-sol -p "Reply with exactly OK"

Optional custom debug directory:

PI_ANYROUTER_CC_DEBUG=1 \
PI_ANYROUTER_CC_DEBUG_DIR=/tmp/anyrouter-cc-debug \
pi --model anyrouter/gpt-5.6-sol -p "Reply with exactly OK"

Default debug output directory:

  • .pi/anyrouter-cc-debug/

If AnyRouter intermittently returns HTTP 520 / Origin Error, this package retries transient upstream failures automatically with exponential backoff. You can tune the retry count with PI_ANYROUTER_CC_MAX_RETRIES.

The runtime uses SSE by default (PI_ANYROUTER_CC_STREAM_MODE=force). For troubleshooting, you can force old behavior with:

PI_ANYROUTER_CC_STREAM_MODE=off pi --model anyrouter/claude-opus-4-8 -p "Reply with exactly OK"

Share as a pi package

This repo is already structured as a pi package through package.json:

{
  "keywords": ["pi-package"],
  "pi": {
    "extensions": ["./index.ts"]
  }
}

That means users can install it with:

pi install git:github.com/xifan2333/pi-anyrouter

Publish checklist

Publish to GitHub

git init
git add .
git commit -m "feat: add AnyRouter Claude and Codex adapters"
git branch -M main
git remote add origin [email protected]:xifan2333/pi-anyrouter.git
git push -u origin main

Optional npm publish

If you want npm distribution too:

npm publish

Then users can install with:

pi install npm:pi-anyrouter

Important behavior

This package implements the Claude Code / Claude Agent SDK and Codex Responses Lite request shapes currently accepted by AnyRouter.

If AnyRouter changes its validation again, enable debug dumps and compare the request shape against fresh official client captures.

Credits

Based on pi-anyrouter-cc by zhenliangzhang, licensed under the MIT License.

This is an unofficial community project and is not affiliated with Anthropic, OpenAI, or AnyRouter.

License

MIT. See LICENSE for the original and modification copyright notices.