@stablekernel/opencode-bifrost
v0.13.2
Published
OpenCode plugin that routes models through the Bifrost gateway, resolving per-project virtual keys via gateway-cli. Supports OpenCode 1.x and 2.x.
Readme
@stablekernel/opencode-bifrost
OpenCode plugin that routes model traffic through a Bifrost LLM gateway, with per-project virtual-key resolution delegated to gateway-cli.
What it does
- Registers a
bifrostprovider on OpenCode's OpenAI-compatible surface whengateway-cliis available. Without the CLI it registers no provider, but/bifrost-refreshstill works. - Fetches the model list at startup through
gateway-cli models --wire=openai, with per-model context/output limits and pricing already applied — no catalog is checked in, so a model added to the gateway appears without a local edit. - Seeds reasoning capability per model: catalog-flagged models are registered
reasoning: truewith one variant per effort value they accept. The config cascade's defaultreasoning_effortis seeded as the model's default when the model accepts it — on OpenCode 1.x asoptions.reasoningEffort, on OpenCode 2 as model-levelsettings.reasoningEffort— and a variant picked in the model picker overrides it. The staticgateway-cli emit opencodeblock mirrors this (--v2for the 2.x form). - Routes first-party OpenAI GPT models (
…openai.gpt-*, notgpt-oss) over the Responses API, since the gateway answers their chat-completions requests with 400: a per-modelprovider.npm: "@ai-sdk/openai"(+options.forceReasoning) on 1.x,package: "@opencode/ai/providers/openai/responses"on 2.x. - Adds rolling prompt-cache breakpoints for GPT-6.2 on Bedrock (
bedrock/openai.gpt-6.2-*) on both OpenCode majors. Those models reuse a cached prefix only up to a content block markedprompt_cache_breakpoint: {mode: "explicit"}, which neither@ai-sdk/openainor OpenCode 2's native Responses route sends, so every agent turn was a full cache write. The plugin marks the last input item of each Responses request and the item that ended the previous request; other requests pass through unchanged.- OpenCode 1.x: through the provider's in-memory
fetch. Verified live 2026-11-24 on OpenCode 1.18.18 withgpt-6.2-sol: cache reads per step went from 0 on every step to 22.5K, 25.4K, 28.3K, 31.0K. - OpenCode 2: the native Responses route takes no custom fetch, so the plugin registers a session
http.requesthook scoped to thebifrostprovider (in@opencode/pluginsince 2.0.0). The host passes each outgoing provider request to it as a webRequestand sends the one the hook leaves in its place. Verified live 2026-11-24 on OpenCode 2.3.2 withgpt-6.2-sol(four sequential tool steps and a final answer): cache reads per step went from 0 on every step with the released 0.11.1 to 19.6K, 20.5K, 20.8K, 21.1K, 21.4K.
- OpenCode 1.x: through the provider's in-memory
- Sets
useron chat-completions requests to Fireworks models (fireworks/*) to a hash of the conversation's first messages, Fireworks' documented session-affinity key, on both OpenCode majors (the same providerfetchandhttp.requesthook as above). OpenCode already sends anx-session-affinityheader, but Bifrost forwards onlyx-bf-eh-*headers upstream; it does forwarduser. 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). - Resolves the virtual key per project directory (
gateway-cli resolve/gateway-cli key print), so two projects on different keys never collide in OpenCode's global auth store. On OpenCode 1.x it falls back to a credential stored viaopencode auth loginon machines withoutgateway-cli; OpenCode 2 removed that hook, so there discovery requires the CLI.
No secret is held by the plugin; the key is read at runtime.
/bifrost-refresh
Registered on every startup, with or without gateway-cli — in a sandbox that
has no CLI at all the plugin registers no provider, so this command is the only
way to see what the gateway offers. It reconciles the model list whenever you
want it, without restarting OpenCode. Two modes, chosen by what is available at
the moment you run it:
gateway-clipresent — runsgateway-cli sync, which reconciles the saved selection on disk, and prints its output. On OpenCode 1.x, once that turn ends, the plugin disposes the instance so the TUI re-bootstraps and the model picker re-reads the reconciled list (disposing mid-turn would cut the turn short); OpenCode 2 exposes no dispose hook, so restart the service (opencode service stop) to pick up a reconciled list. On 1.x the list was re-registered, so the report does not tell you to restart; on OpenCode 2 the report isgateway-cli sync's own output.gateway-cligone (sandboxed machine) — asks$BIFROST_DISCOVERY_URL(or$BIFROST_GATEWAY_URL)/v1/modelsdirectly and reports what the gateway offers versus what this session registered: new ids, ids no longer offered, or "this session's list is current". Report only — nothing is written, here or anywhere else, and no instance is disposed; the text says to restart because this mode cannot re-register anything. The key comes from$BIFROST_VK, else the CLI's own~/.config/bifrost/keys/default.env(on OpenCode 1.x, else the credential stored byopencode auth login). 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 result arrives as a message part, never as an error: a failure prints one line. The virtual key is never printed or logged.
Requirements
gateway-clionPATH(or theGATEWAY_CLI_BINenv var pointing at it), connected once withgateway-cli connect.
Install
opencode plugin --global @stablekernel/opencode-bifrost # OpenCode 1.x
opencode plugin add @stablekernel/opencode-bifrost # OpenCode 2.xLicense
UNLICENSED — published for installation convenience; all rights reserved. Intended for use within the organization that operates the Bifrost gateway.
