Skip to content

feat: add plugin-litellm + provider-litellm presets (runtime model discovery) - #45

Merged
trick77 merged 2 commits into
masterfrom
feat/provider-litellm-preset
Jul 23, 2026
Merged

feat: add plugin-litellm + provider-litellm presets (runtime model discovery)#45
trick77 merged 2 commits into
masterfrom
feat/provider-litellm-preset

Conversation

@trick77

@trick77 trick77 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

What

Wires opencode to a LiteLLM proxy using runtime model discovery — the model list is pulled from the proxy at startup rather than hand-maintained in opencode.json. Two presets, matching the two config areas the plugin needs:

  • plugin-litellm (@mode: appendplugin) — adds opencode-plugin-litellm (npm opencode-plugin-litellm, pinned @0.5.0). At startup the plugin queries the proxy's /v1/models and injects every model into the picker. For a proxy on localhost:4000/8000/8080 with the key in $LITELLM_API_KEY, the plugin auto-detects the URL and creates the litellm provider itself — so this preset alone is enough.
  • provider-litellm (@mode: replaceprovider.litellm) — for a custom/remote proxy URL. Prompts for baseURL, sets @ai-sdk/openai-compatible with apiKey: {env:LITELLM_API_KEY}, and declares no models (the plugin fills them).

Resulting config for the remote case matches the plugin README's "explicit provider" block verbatim:

{
  "plugin": ["opencode-plugin-litellm@0.5.0"],
  "provider": {
    "litellm": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "LiteLLM (proxy)",
      "options": { "baseURL": "...", "apiKey": "{env:LITELLM_API_KEY}" }
    }
  }
}

Why this shape (not a static provider block)

LiteLLM is not in models.dev, and opencode only auto-discovers models for a few hardcoded providers (gitlab, etc.) — a plain @ai-sdk/openai-compatible provider shows zero models unless each is listed by hand. The opencode-plugin-litellm plugin is the mechanism that makes "all models available"; it reads $LITELLM_API_KEY / $LITELLM_MASTER_KEY directly for discovery, which is why the key is env-based and the provider key must be exactly litellm.

Usage

# localhost proxy, key in env — plugin auto-detects everything
export LITELLM_API_KEY=sk-...
opencode-presets install plugin-litellm

# remote/custom proxy — add the provider block too (run separately; --set is one preset per call)
opencode-presets install plugin-litellm
opencode-presets install provider-litellm --set baseURL=https://litellm.example.com/v1

Restart opencode after installing a plugin preset.

Changes

  • presets/plugin-litellm.conf — new
  • presets/provider-litellm.conf — new
  • README.md — two built-in-preset rows
  • test/builtin-presets.test.tsparseConf tests for both

Verification

  • npm test → 99/99 pass (both new tests included)
  • Temp-config install of both presets produces the exact documented config; validate config passes against opencode's live schema; remove plugin-litellm provider-litellm cleanly reverts.
  • Not verified locally: runtime /v1/models discovery (needs a live LiteLLM proxy + opencode). Correctness rests on matching the plugin's documented config exactly.

Note

Plugin pinned to @0.5.0 rather than the README's @latest, per this repo's supply-chain stance. Bump in plugin-litellm.conf to update.

Wire opencode to a LiteLLM proxy with runtime model discovery via the
opencode-plugin-litellm plugin, instead of a hand-maintained models list.

- plugin-litellm: appends opencode-plugin-litellm@0.5.0 to the plugin
  array. At startup the plugin queries the proxy's /v1/models and injects
  every model into the picker. For localhost with the key in
  $LITELLM_API_KEY the plugin auto-detects the URL and creates the
  provider itself, so this preset alone suffices.
- provider-litellm: for a custom/remote proxy, sets provider.litellm
  (@ai-sdk/openai-compatible) with the prompted baseURL and
  apiKey={env:LITELLM_API_KEY}. Declares NO models; the plugin fills them.

Plugin pinned to an exact version (repo supply-chain stance) rather than
the README's @latest. Adds README rows and parseConf tests.
@trick77
trick77 force-pushed the feat/provider-litellm-preset branch from b042fb3 to 36f7d8d Compare July 23, 2026 18:55
@trick77 trick77 changed the title feat: add provider-litellm preset feat: add plugin-litellm + provider-litellm presets (runtime model discovery) Jul 23, 2026
@trick77
trick77 merged commit 32c6405 into master Jul 23, 2026
3 checks passed
@trick77
trick77 deleted the feat/provider-litellm-preset branch July 23, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant