omp packages

pi-cliproxyapi0.6.0

Pi extension for corporate management of model providers via a single CliProxyAPI endpoint

abix5 Published 2 days ago MIT ~568 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

██████╗ ██╗     ██████╗██╗     ██╗██████╗ ██████╗  ██████╗ ██╗  ██╗██╗   ██╗
██╔══██╗██║    ██╔════╝██║     ██║██╔══██╗██╔══██╗██╔═══██╗╚██╗██╔╝╚██╗ ██╔╝
██████╔╝██║    ██║     ██║     ██║██████╔╝██████╔╝██║   ██║ ╚███╔╝  ╚████╔╝
██╔═══╝ ██║    ██║     ██║     ██║██╔═══╝ ██╔══██╗██║   ██║ ██╔██╗   ╚██╔╝
██║     ██║    ╚██████╗███████╗██║██║     ██║  ██║╚██████╔╝██╔╝ ██╗   ██║
╚═╝     ╚═╝     ╚═════╝╚══════╝╚═╝╚═╝     ╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═╝   ╚═╝

pi-cliproxyapi

npm GitHub

Pi extension for corporate management of model providers via a single CliProxyAPI endpoint.

One (endpoint, apiKey) pair — every provider and model inherits it automatically, including live quota.

Quota in the status line

The footer shows how much of each provider window is left for the model you are currently using, so a limit is visible before it bites rather than after:

claude-sonnet-5   󰘧 5h ⣶69 ↻4:40  7d ⣷81 ↻2д4ч
claude-fable-5    󰘧 5h ⣶69 ↻4:40  7d ⣷81 ↻2д4ч  Fable ⣾91 ↻2д4ч
burning too fast  󰘧 5h ⣀31 ↻4:40 2.1x  7d ⣷81 ↻2д4ч

The segment uses at most half the terminal width and adjusts immediately on resize. For example, at 80 columns it can keep a pace warning and all three windows; at 50 columns two healthy windows fit without their countdowns:

80 columns   󰘧 5h ⣤31 ↻4:40 2.1x  7d ⣷81  Fable ⣷81
50 columns   󰘧 5h ⣶69  7d ⣷81

Countdowns for windows without warnings go first, then all countdowns, then the gauge icon. If necessary only the highest pace warning (or, without a warning, the least remaining window) stays. If that cannot fit, the segment is hidden. With an unknown terminal width, nothing is removed.

Each window shows what is left and the time until it resets: ↻4:40 under a day, ↻2д4ч (days and hours) beyond. Durations round down. When everything is fine that is all you see. Only when the current pace would exhaust a window before it resets does the pace multiplier appear after it — 2.1x means quota is going 2.1 times faster than would last until the reset; yellow from 1.0x, red from 1.5x. The pace is computed by the bridge from its own history, so every Pi instance sees the same number; an older bridge simply shows no multiplier.

The figures are for the account your session is actually bound to when the bridge knows it; otherwise they follow the router’s active tier, weighted by share. Without routing information they show the maximum remaining per period.

Windows are read live, not guessed. Anthropic caps some models against a slice of the weekly pool — Fable may draw down half of it, and draws faster than other models — so that per-model window is shown alongside the weekly figure rather than folded into it. Switching models switches the window on display. Other models' windows never drag down the general figure.

Green ≥ 70%, yellow 30–69%, red < 30%. The Usage tab breaks the same data down per account and answers "how fast and until when":

▾ claude  1 account  5h 31% ↻4:40 ⚠ 2.1x
  ● ◆ daniil@example.com  serves new requests
    5h Session  [███░░░░░░░]  31%  ↻4:40 ⚠ 2.1x · out 14:20
    7d Weekly   [████████░░]  81%  ↻2д4ч
    7d Fable    [████████░░]  81%  ↻2д4ч

Each window shows its remaining quota and reset countdown. A warning appears only at or above the sustainable pace (1.0x): yellow below 1.5x, red from 1.5x. When available, out gives the projected exhaustion time. ◆ marks the account serving this session, not necessarily the one serving new requests.

Local model aliases

Use an alias such as latest/opus in /model, as a default, or in an agent definition. On the Aliases tab press a and enter the alias name and a pattern such as claude-opus-*; the provider follows the pattern. The star captures a numeric version (5-10 outranks 5-9); an exact id pins a fixed target. A bare alias name gets the latest/ prefix. Other prefixes work too, e.g. my/cheap.

The picker shows the newest eligible target, not every matching version. An exclude can disqualify an alias target even if that model remains selectable by hand. Unresolved aliases stay in the hub with a reason, not in the picker. Suggested aliases are examples, not registrations.

Selecting an alias switches to the concrete model before use. A new session can pick a newer winner; an existing session records its concrete provider/id. Previously bound versions remain selectable while served unless excluded or disabled. Refresh never switches a concrete session or sends an unresolved local alias to the proxy.

How the numbers get here

Quota and the model catalogue come from the pi-bridge plugin running inside CliProxyAPI, authenticated with the same apiKey used for model calls — no second credential, no extra container:

Pi + extension  ──▶  CliProxyAPI
                       /v1/models, /v1/chat/…          model calls
                       /v0/resource/plugins/pi-bridge/
                           well-known  →  model catalogue
                           usage       →  per-account quota

The plugin caches quota server-side, so every Pi instance shares one upstream poll and provider rate limits stay comfortable. It also knows where each provider keeps its numbers — a description that lives in configuration, so a provider reshuffling its API is answered by an edit rather than a release.

Without the plugin the extension still works: it falls back to raw /v1/models with local heuristics, and the quota display is simply absent.

With pi-bridge Without
Quota in status line + Usage tab Live per-account windows Unavailable
Model discovery Enriched from models.dev — real context windows, costs, reasoning flags Defaults: contextWindow=128k, maxTokens=16k, cost=0
Classification Server-side Local heuristics by owned_by

See the plugin's README for installing it into CliProxyAPI.

Features

  • Live quota — status-line windows for the model in use with reset countdown and a pace warning, per-account bars with shortage forecasts in the Usage tab, no LLM call
  • latest/* aliases — pick a model family; each session pins the newest concrete model
  • Unified hub — Models, Usage, Settings and Diag share one overlay and draft.
  • Built-in provider routing — whitelist which Anthropic / OpenAI / etc. models are available through the proxy
  • Custom provider groups — create named groups (e.g. corp-glm, corp-gemini) for proxy-only models with automatic metadata from models.dev
  • Exclusive model pool — each model has at most one custom group owner; other groups show which one owns it
  • Live save state — edit across tabs, then save the shared draft with s or discard on close
  • Model filters — include / exclude glob patterns per provider register every served model that matches (e.g. claude-opus-*), with a live match preview in the hub
  • Reworked hub — Models tab with a provider-grouped list, selection reasons and live rule previews, grouped Usage tab with per-account quota, per-tab ? key reference, and a footer that refits narrow terminals
  • Settings — /cliproxy-setup opens the connection tab in that same hub.

Commands

Two commands; everything else lives inside the hub as tabs and actions.

Command Description
/cliproxy Hub overlay — Models, Usage, Settings, Diag
/cliproxy-setup Configure endpoint, API key, provider prefix

The /cliproxy hub

Use Tab / Shift+Tab to cycle through tabs, or jump to 1 Models, 2 Aliases, 3 Usage, 4 Settings, or 5 Diag.

The bottom line lists the keys that work right now as key caps (space mark, + include, … ? help); when the terminal is narrow, the least important ones are dropped first and ? always stays. Press ? for the icons and keys of the current tab. ?, q, or Esc returns without acting on the underlying tab. While typing a rule, an alias or a filter, ? and q are text instead.

s saves and applies the shared draft. r refreshes discovery against saved settings without applying draft edits. q, Esc, or Ctrl+C closes a clean hub. With unsaved edits, choose s to save and close, d to discard, or Esc to keep editing.

If discovery fails, the hub opens with the last catalogue cached for the same proxy and API key. The header shows its age (for example, 4:40). Without a matching cache, Models shows the error; Usage and Diagnostics still open. Press r to retry and replace the cached or missing catalogue.

Models tab — one list, grouped by provider. Each provider header shows its rule count (or no rules) and how many of its models are on; under it comes its own rules block, closed by a thin divider, then its models sorted by id. Move with ↑ / ↓ (k / j), PgUp / PgDn, or Home / End; fold or open a provider with ← / →. / filters model ids and o shows only models that are on. N adds a custom group; D removes one after confirmation.

Each model row reads left to right: a circle, the id, then why. The circle tells the state by colour and by shape, so it also reads without colour (NO_COLOR, monochrome): ◉ (accent colour) is on by your hand mark, ● (green) is on by a rule, an alias or a kept session, ○ (dim) is off. ⊕ claude-* means an include rule turned it on, ⊖ *haiku* means an exclude rule keeps it off, a hand-marked row lists the other reasons too (an exclude it beats is dimmed) and says manual when the mark is its only reason, ← latest/opus means that alias currently picks this model, ⟲ kept means a running session still uses it, ⚠ not on proxy means a hand-marked id the proxy no longer serves, and ⊘ names a gate such as provider off or owned by another group. No icon means the model simply follows the rules and none matches.

Space toggles the focused model's hand mark (◉), whatever its rules, aliases or retention say: it adds the mark if absent and removes it if present. The mark is independent and on only: a marked model stays on even if an exclude matches; without the mark the rules decide. The row lists every reason side by side, e.g. ◉ claude-opus-5-5 ⊕ claude-* ← latest/opus. Space never edits rules, aliases or legacy model lists. A model that is not on the proxy is never counted or registered; you can clear its mark. Excluding a kept model may prevent an earlier session from resuming.

Rules are set once per provider. + opens an include line, - an exclude line, right under that provider's rules: type a glob such as claude-* and the matching models below are highlighted with the state they will have. Tab flips between include and exclude, Enter adds the rule to the draft, Esc drops it. On a rule, e edits it in the same line and d deletes it. New models that match a rule appear by themselves after a refresh; only s saves the draft to Pi.

Aliases tab — a list of alias → the model it picks now, with the pattern and provider in quieter columns. a adds an alias, e or Enter edits the focused one, d deletes it; move with ↑ / ↓. The form has a name, a pattern and a provider: Tab moves between them, the provider follows the pattern until you choose one with ← / →, the bottom line shows the model the alias would pick, Enter stages and Esc cancels. ⚠ marks an alias that picks nothing right now and says why.

Usage tab — each folded provider shows its account count and the windows of the one account with the least quota left. The footer separately follows routing. The session’s provider comes first and starts expanded; if there is only one group or the model has no quota provider, all groups start expanded. Each account shows its quota bars, reset countdown and (only for a shortage) pace and exhaustion forecast; ◆ marks the bound account.

Move between provider and account headers with ↑/↓ or k/j. Fold/open the current group with ←/→, toggle a header with Enter or Space, or toggle all groups with f. Page with PgUp/PgDn (b also pages up); jump to the first or last header with Home/End or g/G. Selected shows priority, weight when relevant, request counts and last request time. Use v to show these details, full errors and disabled accounts in the list, or ? for keys. If usage fails to load, r retries and 4 opens Settings.

Settings tab — move between fields with ↑ / ↓, press e or Enter to edit, and t to test without saving. s saves the shared draft. See Setup for the fields.

Diagnostics tab — select a check with ↑ / ↓, inspect details with ← / →, use Enter to open the tab that can fix it, or r to re-check. Reports include endpoint and key checks, discovery source, and conflicts. The filter report shows matches per pattern, warns on zero matches, names models owned by another group, and shows whether discoveryExcludes applied.

Prerequisites

You need a running CliProxyAPI instance — this is the corporate LLM proxy that aggregates multiple providers behind a single OpenAI-compatible endpoint.

For full functionality — quota windows and enriched model metadata — also install the pi-bridge plugin into that instance. See How the numbers get here above.

Install

pi install npm:pi-cliproxyapi

Then run /cliproxy-setup to configure your proxy endpoint.

Taskflow child agents

Taskflow starts children with an extension allowlist, so add this package's entrypoint there as well; otherwise the child cannot register the proxy-backed model catalog. For a normal npm installation:

{
  "taskflow": {
    "piChild": {
      "resourceProfile": "allowlist",
      "extensions": [
        "/Users/your-user/.pi/agent/npm/node_modules/pi-cliproxyapi/index.ts"
      ]
    }
  }
}

Use a real absolute path: taskflow does not expand ~, so replace /Users/your-user with your home directory. Preserve any existing allowlisted extensions (such as taskflow's path guard and MCP adapter). For a local checkout, use its absolute index.ts path instead. A child running in JSON/print mode reads the discovery cache and registers providers without discovery, usage, command, status, or timer work. Start Pi once interactively after configuring the proxy to populate that cache.

Config

~/.pi/agent/pi-cliproxyapi/config.json — created by /cliproxy-setup, editable by hand. If only the legacy ~/.config/pi-cliproxyapi/config.json exists, an installed plugin moves it here once; a local checkout copies it and retains the legacy file.

{
  "proxy": {
    "endpoint": "https://proxy.example.com/v1",
    "apiKey": "!cat ~/.pi/agent/pi-cliproxyapi/key",
    "providerPrefix": "corp"
  },
  "aliases": [{ "name": "latest/opus", "provider": "anthropic", "pattern": "claude-opus-*" }],
  "builtinProviders": {
    "anthropic": {
      "enabled": true,
      "models": ["claude-haiku-4-5"],
      "include": ["claude-opus-*", "claude-sonnet-*"],
      "exclude": ["*-preview", "claude-opus-5-6"],
      "manual": { "claude-sonnet-preview": "on" }
    },
    "openai": { "enabled": true, "models": ["gpt-5.2"] }
  },
  "customProviders": {
    "corp-glm": {
      "api": "openai-completions",
      "models": [{ "id": "glm-4.7", "name": "GLM 4.7", "input": ["text", "image"] }],
      "include": ["glm-*"],
      "manual": { "glm-4.7": "follow" }
    }
  }
}

input is optional per model and lists the input modalities the model accepts ("text", "image"). When the pi-bridge plugin is present this is usually supplied automatically from models.dev; setting it by hand is useful for proxies that cannot serve the enriched catalogue. Omitting it defaults to ["text"].

Model filters: include, exclude and manual

Every entry of builtinProviders and customProviders may carry two optional lists of glob patterns next to models, so a model enabled in CLIProxyAPI shows up in Pi without being listed a second time:

  • include — register every candidate model that matches at least one pattern. A built-in provider's candidates are the models the catalogue lists for that provider; a custom group's candidates are the custom-pool models whose API is compatible with the group's api.
  • exclude — block matching models from rules, aliases and retention in this provider. A hand-on can still enable an excluded concrete model, not an alias target.

Grammar: a pattern matches the whole model id; * matches any run of characters (also an empty run, and across /, :, . and -); every other character, including . and ?, matches only itself, case-sensitively. There is no other wildcard, no negation and no regular-expression syntax. A pattern without * matches exactly one id. Patterns are trimmed and deduplicated; entries that are not strings, are blank or are longer than 128 characters are ignored with a warning. Ids longer than 256 characters never match.

For a served, eligible id, apply these decisions in order:

  1. A hand mark keeps the concrete id on in /model, independently of the rules. There is no hand-off: rules alone turn models off.
  2. Otherwise an exclude match turns it off.
  3. Otherwise an include match, a local alias winner, or a kept version turns it on. Kept versions come from a successful binding or the 0.5.0 upgrade snapshot. Nothing else turns it on. There is no default pattern.

manual is optional and local to one provider. Its keys are literal ids: "a*b" changes only a*b, not ab. The only mark is "on" (a pin). By default an id listed in models is pinned; any other id follows the rules. Clearing a listed id's pin stores "follow" so it can follow rules without deleting its metadata. An "off" value written by an earlier 0.6.0 preview is read as "follow". Restoring the default removes the entry, and saving omits an empty map. A checkbox edit does not rewrite models, include, exclude or aliases.

An alias enables only its newest eligible numeric match. It skips all exclude hits, even if the concrete id is pinned. With no eligible match the alias stays configured but out of the picker. Refresh recomputes these choices, not the current session's model. Excluding a kept id does not erase its binding; removing that rule lets it return if still eligible.

Worked example. Suppose the config above sees claude-haiku-4-5, claude-opus-5-5, claude-opus-5-6 and claude-sonnet-preview under anthropic, and only glm-4.7 in the custom pool. The selected Anthropic ids are claude-haiku-4-5 (listed), claude-opus-5-5 (included, also the target of latest/opus), and claude-sonnet-preview (hand-on despite *-preview). claude-opus-5-6 is excluded, so the alias falls back. corp-glm registers glm-4.7 via its include, not a hand mark, retaining its listed name GLM 4.7 and ["text", "image"] input.

A model belongs to at most one supported custom group. Hand-on claims win, with ties settled by config order. This preserves legacy listed ids served outside the custom pool. Other claims on compatible pool ids use ordinal group-name order. A cleared legacy entry supplies metadata but no ownership priority. Unsupported groups own nothing.

Changed since 0.5.0. 0.5.0 registered a model explicitly listed by two custom groups under both. When both groups explicitly list the model and neither has an overriding edit, the first group in config order keeps it; a session using the second group must reselect it. Duplicate entries within a list retain their order and metadata in a config without patterns; with patterns the selected id is registered once.

discoveryExcludes (top level, default ["*:*"]) is a different, earlier stage and is not deprecated: it removes ids from the catalogue only when the extension builds it from the plain /v1/models listing (fallback path; the bridge catalogue applies its own server-side excludes). It uses the same glob grammar. An id it removed is not a candidate, so no include can bring it back.

Also changed since 0.5.0. discoveryExcludes uses the same glob grammar: * is the only wildcard and ? is a literal character (0.5.0 treated it as a regular-expression quantifier). The default *:* and patterns such as lproxy/* behave as before.

Downgrade / mixed versions. 0.5.0 reads the original models lists, not the new patterns, manual exceptions (including follow), or local alias definitions. Its picker can therefore differ, and saving from an old hub can discard new settings. Back up the file before sharing or downgrading.

Values support !command (shell exec), $ENV_VAR, or literal strings. The Settings tab also accepts bare ~/path values and saves them as !cat commands; when editing the file by hand, write the !cat ~/path form explicitly.

Setup

Open /cliproxy-setup (or press 3 in /cliproxy). First run opens Settings automatically. Select a field with the arrows and press e or Enter to edit.

  • endpoint — your public proxy URL ending with /v1
  • apiKey — CliProxyAPI bearer key
  • providerPrefix — short slug for custom provider names (e.g. corp)
  • Refresh (min) — automatic discovery interval; 0 disables it
  • Usage key — optional legacy sidecar key

Enter keeps the field in the draft; Esc cancels the field edit. t tests the draft connection without changing Pi. s saves and applies the whole draft, including model edits.

0.6.0 release notes (unreleased)

  • Fresh install: /cliproxy starts on Settings. Test and save your connection, then open Models. Each provider has its own include/exclude rules; aliases have their own tab. The first save starts with "aliases": [] unless you add your own. The suggested example on the empty Aliases tab does not create an alias; press a there to define one.
  • Upgrade from 0.5.0: back up the config. Leave aliases absent (not []): the first usable live bridge catalogue imports the old selectable aliases under their existing names and retains the previously registered concrete provider/ids. For example, latest/opus keeps its picker name. Its definition is written to the aliases array in ~/.pi/agent/pi-cliproxyapi/config.json and appears on the Aliases tab. Offline startup defers import; once imported, deleting an alias does not re-import it.
  • Family compatibility: one explicit family member no longer enables every future version. The current alias winner and retained versions are registered; use an include rule if you want every served version in /model. A model listed in two custom groups now registers once; sessions that used the second group's name must pick the model again.
  • Models shows on/off and its cause as icons and previews a typed include/exclude rule live on the matching models. Aliases have their own tab. The five tabs share one draft, Usage groups accounts, and the quota footer adapts to narrow terminals. See the hub walkthrough for keys.

Migrating from the wellknown sidecar

Earlier versions read /.well-known/pi and /api/usage from a separate pi-cliproxyapi-wellknown container, which needed its own usageKey. Version 0.4.0 reads both from the pi-bridge plugin instead.

  1. Install pi-bridge into CliProxyAPI (see its README).
  2. Update this extension to 0.4.0 or later.
  3. Confirm the Usage tab still populates — it now says source=plugin.
  4. Drop the sidecar's routes from your reverse proxy, then stop the container.
  5. Remove proxy.usageKey from the config above; Settings retains this optional key only for legacy sidecar fallback.

Steps 1–2 are safe in either order: until the plugin answers, the extension keeps using the sidecar, and a version older than 0.4.0 keeps working against a server that already runs the plugin.

Layout

index.ts            ExtensionFactory entry point
src/
  config.ts         ~/.pi/agent/pi-cliproxyapi/config.json
  commands.ts       2 slash commands (hub + setup)
  apply.ts          pi.registerProvider calls
  fetch-models.ts   catalogue from pi-bridge, /v1/models fallback
  fetch-usage.ts    quota from pi-bridge, sidecar fallback, TTL cache
  compat.ts         baseUrl derivation, model classification
  conflicts.ts      read-only ~/.pi/{models,auth}.json scan
  ui-frame.ts       single source of truth for overlay frames
  ui-usage.ts       ANSI-coloured usage renderer
  ui-hub/           the /cliproxy hub overlay
    index.ts        public runHub entry
    hub.ts          tabs, status header, global actions
    types.ts        HubView contract
    shell.ts        tab bar, status header, scroll/slice helpers
    icons.ts        state circles and cause icons (◉ ● ○ ⊕ ⊖ ← ⟲ ⚠ ⊘)
    view-models.ts  Models tab: provider headers, rules, model rows, inline rule line
    models-list.ts  Models rows as data (no painting)
    view-aliases.ts Aliases tab: list and add/edit form
    models-alias.ts alias validation and well-known examples
    view-settings.ts connection draft and test
    view-usage.ts   grouped quota windows and account detail
    view-diagnostics.ts  diagnostics tab
  ui-picker/        picker building blocks reused by the Models view
    types.ts        shared TS types
    catalog.ts      build a model lookup from discovery
    providers.ts    resolve the providers shown in the Models list
    mutate.ts       model pool grouping and display order
    render-text.ts  ANSI-aware pad / truncate
    prompt-confirm.ts    remove-group confirmation
    prompt-name.ts       new-group name prompt
  log.ts            tagged logger