@stablekernel/pi-bifrost
v0.13.2
Published
Pi extension that registers the Bifrost gateway as a model provider, resolving per-project virtual keys via gateway-cli.
Downloads
1,762
Readme
@stablekernel/pi-bifrost
Pi extension that registers a Bifrost LLM gateway as a model provider, with per-project virtual-key resolution delegated to gateway-cli.
What it does
- Registers two providers:
bifrost-openai— the OpenAI-compatible surface, every chat model the gateway serves. First-party OpenAI GPT models (notgpt-oss) are sent over the Responses API (api: "openai-responses"per model): gpt-6-class models reject chat completions through the gateway.bifrost-anthropic— the Anthropic Messages surface, Claude models only. The Anthropic wire carries prompt-cache control blocks that only Claude accepts, so non-Claude models are registered on the OpenAI surface instead of being listed twice with one copy broken.
- Fetches each surface's model list, limits and pricing through
gateway-cli models --wire=…at startup — no catalog is checked in. - Seeds reasoning capability per model: catalog-flagged models register
reasoning: true. On the OpenAI surface they also get athinkingLevelMaptranslating pi's thinking levels to the model's effort values (unapplicable levels are hidden, never passed through by name) plussupportsReasoningEffort, so pi's per-request effort picker sends the provider's own values. On the Anthropic surface the capability is flagged and pi's Claude thinking handling applies;claude-sonnet-5-5also setsforceAdaptiveThinking, because pi 1.4.0 otherwise sendsthinking.type=enabledand Bifrost returns a 400 (verified live 2026-11-25; Opus 5.5, Haiku 5.5 and Fable 5.2 work without it). Models with effort levels also setsupportsPerMessageEffort(omp); those whose id is in pi-ai 1.7.0's catalog of mid-conversation-effort Claude models (Opus 5 and 5.5, Sonnet 5.5, Haiku 5.5, Fable 5.1 and 5.2) also setsupportsMidConvoEffort(the flag pi reads) so thinking-level changes keep the prompt cache. Cache-keeping has been verified live only onclaude-opus-5-5through Bifrost; other models remain unverified (G-012). Toggle-only reasoning models get no effort map. The default effort itself is pi's own thinking-level default. - Adds rolling prompt-cache breakpoints for GPT-6.2 on Bedrock (
bedrock/openai.gpt-6.2-*). Those models reuse a cached prefix only up to a content block markedprompt_cache_breakpoint: {mode: "explicit"}, so without markers every agent turn was a full cache write. Abefore_provider_requesthook marks the last input item of each request and the item that ended the previous request; string content on a marked item is sent as a one-blockinput_textlist. Other models, 6.0/6.1 included, cache implicitly and are left untouched. Verified live 2026-11-24 ongpt-6.2-solthrough omp: cache reads per turn went from 0, 0, 0, 0 to 44.5K, 46.0K, 47.6K, 49.0K (about 97% of the prompt). - Sets
useron chat-completions requests to Fireworks models (fireworks/*) to a hash of the conversation's first messages, Fireworks' documented session-affinity key (Bifrost forwards it), so a session's turns tend to reach the replica that holds its cached prefix. It is a hint, not a pin: measured live 2026-11-24 onkimi-k3.1, follow-up turns that missed the previous prefix fell from 26% to 18% (200 turns each). The rest is Fireworks routing (G-020). Auserthe harness already set is kept. - Never holds the key: pi resolves it per request via the
!gateway-cli key printcommand form, so the per-project key cascade (environment override → project → user default) applies on every turn.
/bifrost-refresh
Reconciles the model list on demand, in pi and omp alike (one package, one implementation, one command):
- With
gateway-clionPATHit runsgateway-cli sync— the same reconcile as the background sync — and shows that command's own output. It rewrites the saved selection and the harness configs on disk. - Without it it asks the gateway directly:
$BIFROST_DISCOVERY_URL(or$BIFROST_GATEWAY_URL) with$BIFROST_VK, falling back to the key in~/.config/bifrost/keys/default.env. It then reports how many models the gateway offers and which are new or gone against the ids this session registered. This mode reports only — it writes nothing, and the key is never printed. Project lookup also honors committed.gateway/shared.json, with personal > shared > user precedence per deployment. A saved project selection is the exception: refresh refuses before making a request and tells you to installgateway-cli, because direct discovery cannot apply the project context.
Either way the answer arrives as a notification, and any failure is one readable line rather than an error thrown into the session.
Restart the session to use a newly added model. Pi and omp build a provider's model list once, while the session starts, and neither can re-register one to a running session — so the report names the new models and says to restart, and nothing here fakes a reload.
Requirements
gateway-clionPATH(or theGATEWAY_CLI_BINenv var pointing at it), connected once withgateway-cli connect.
Without it nothing is registered — there is no credential to hand pi — but
/bifrost-refresh still reports the gateway's live list from the environment
(see above).
Install
pi install npm:@stablekernel/pi-bifrostWorks in omp (the Pi fork) too — its plugin loader accepts the same package and pi.extensions manifest:
omp plugin install npm:@stablekernel/pi-bifrostLicense
UNLICENSED — published for installation convenience; all rights reserved. Intended for use within the organization that operates the Bifrost gateway.
