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-sub2api

v0.1.0

Published

Pi extension for a sub2api gateway: dynamic model registration and a /usage command for balance and cost.

Downloads

124

Readme

pi-sub2api

A pi extension for a sub2api gateway.

  • Fetches the model list from the gateway at startup and registers it as the sub2api provider.
  • Adds a /usage command showing balance and today/total cost.

Install

pi install npm:pi-sub2api

Or try it for a single run without installing:

pi -e npm:pi-sub2api

Configure

All configuration lives in ~/.pi/agent/auth.json under the provider name sub2api. No shell environment variables are needed.

{
  "sub2api": {
    "type": "api_key",
    "key": "sk-...",
    "env": { "SUB2API_BASE_URL": "https://your-sub2api-host" }
  }
}
chmod 600 ~/.pi/agent/auth.json
  • key — an API key generated in the sub2api dashboard.
  • env.SUB2API_BASE_URL — the gateway base URL, without a trailing /v1. Defaults to http://localhost:8080.

pi resolves the key from auth.json["sub2api"] for inference; the extension reads the same entry for its own /v1/models and /v1/usage calls. SUB2API_KEY / SUB2API_BASE_URL environment variables are used as a fallback if the auth.json entry is absent.

Use

pi --list-models                                  # models appear under the sub2api provider
pi --provider sub2api --model gpt-5.5

In an interactive session, /usage prints balance and cost:

sub2api usage
  balance  -67.01 USD
  today    $0.27 · 9 req · 57,826 tok
  total    $184.21 · 5,965 req · 105,534,943 tok
  top models (by cost)
    gpt-5.5  $0.27 · 52,300 tok · 4 req

Notes

  • API type: the provider is registered with openai-completions. openai-responses and openai-codex-responses did not work against this gateway.
  • Cost: pi's per-token cost is set to 0, because sub2api's /v1/models returns no pricing. Cost comes from the gateway's own accounting via /usage, not from pi's estimate.
  • Model list: embedding and image-generation models are filtered out; only chat-capable models are registered.
  • Thinking levels: reasoning models expose off/low/medium/high/xhigh. minimal is marked unsupported because the upstream rejects reasoning_effort: "minimal".
  • Model metadata: contextWindow and maxTokens are set to 400000/128000 for every model, since the gateway's model list does not report per-model limits.

License

MIT