pi-sub2api-provider
v0.2.1
Published
Pi extension that auto-registers sub2api/OpenAI-compatible providers and displays quota usage.
Maintainers
Readme
pi-sub2api-provider
A standalone pi package that reads OpenAI-compatible / sub2api provider config from ~/.pi/agent/models.json and ~/.pi/agent/auth.json, registers providers, and shows quota usage in the pi status bar and via the /quota command.
Features
- Scans providers in
~/.pi/agent/models.json. - Reads the matching
keyoraccessfrom~/.pi/agent/auth.json. - Auto-detects the usage endpoint:
${baseUrl}/usage${root}/v1/usage
- Fetches and caches rate limit / daily usage.
- Pulls
${baseUrl}/modelsand prefers the remote model list, falling back to locally configured models only when the remote endpoint is unavailable. - Reads remote model limit metadata when present (
context_window,max_tokens, and common aliases), with conservative built-in fallbacks for endpoints that only returnid/display_name. - Registers providers via
pi.registerProvider(). - Refreshes / displays quota on
session_start,model_select, andturn_end. - Registers a
/quotacommand that shows detailed billing and quota for the current provider.
Installation
Option 1: From npm (recommended)
pi install npm:pi-sub2api-providerOr add it to ~/.pi/agent/settings.json:
{
"packages": ["npm:pi-sub2api-provider"]
}Option 2: From git
pi install git:github.com/dereknex/pi-sub2api-providerOption 3: As a local package
pi install ./pi-sub2api-providerOption 4: Load temporarily for testing
pi -e /Users/derek/workspaces/pi-sub2api-providerOption 5: Keep using the global extensions directory
If you do not want to switch installation methods yet, copy the entry back to the global extension:
cp /Users/derek/workspaces/pi-sub2api-provider/src/index.ts ~/.pi/agent/extensions/sub2api-quota.tsRequirements
You need the following files in place:
~/.pi/agent/models.jsonwith provider connection settings; the per-modelmodelsarray is optional.~/.pi/agent/auth.json
Example structure:
// ~/.pi/agent/models.json
{
"providers": {
"my-sub2api": {
"baseUrl": "https://example.com/v1"
}
}
}// ~/.pi/agent/auth.json
{
"my-sub2api": {
"type": "api-key",
"key": "..."
}
}Security note: this repository never stores or copies any API key or auth file.
Development
cd /Users/derek/workspaces/pi-sub2api-provider
npm ci
npm run check
npm run pack:dry-runRelease
This project uses Changesets to manage versioning and npm publishing. For the first release, package.json stays at 0.0.0; the 0.1.0 release PR is generated from .changeset/initial-release.md.
See docs/RELEASE.md for details.
Usage
Inside pi:
/model
/quotaThe status bar will show something like:
● my-sub2api: 5h $1.23/$10 • daily $4.56/$50 • weekly $12.34/$200License
MIT © dereknex
