feat(opencode): add LiteLLM provider with auto model discovery
Issue for this PR
Closes #13891
Type of change
- [ ] Bug fix
- [x] New feature
- [ ] Refactor / code improvement
- [ ] Documentation
What does this PR do?
Adds a native litellm provider that auto-discovers models from a LiteLLM proxy at startup. Previously users had to manually define every model in opencode.json — now setting LITELLM_API_KEY and LITELLM_HOST is enough.
Discovery: Fetches /model/info for rich metadata (pricing, limits, capabilities). Falls back to the standard /models endpoint for older LiteLLM versions or non-LiteLLM OpenAI-compatible proxies.
What gets mapped from /model/info:
- Per-token pricing → per-million-token (including over-200k tier)
- Context/output limits
- Capabilities: reasoning, vision, PDF, audio, video, tool calling
- Temperature support via
supported_openai_params - Interleaved thinking inference for Claude/Anthropic models
Reasoning transforms: Claude models behind LiteLLM get thinking budget variants, other models get reasoningEffort. This prevents false-positive reasoning param injection for aliased models (e.g. o3-custom → Mistral).
Files changed:
litellm.ts(new): Discovery module — fetches, parses, maps model metadataprovider.ts: Seedslitellmprovider from env vars; custom loader calls discovery and injects models (user config takes precedence)transform.ts: LiteLLM-specific reasoning variant logicllm.ts: Adds explicitproviderID === "litellm"to proxy detection
| Env var | Description | Default |
|---|---|---|
LITELLM_API_KEY |
API key for the proxy | — |
LITELLM_HOST |
Base URL of the proxy | http://localhost:4000 |
LITELLM_BASE_URL |
Alias for LITELLM_HOST |
— |
LITELLM_CUSTOM_HEADERS |
JSON string of extra headers | {} |
LITELLM_TIMEOUT |
Discovery timeout in ms | 5000 |
Builds on ideas from #13896 (fallback endpoint, over-200k pricing, temperature detection) and #14277 (clean fallback chain). Supersedes my earlier #14202 which was auto-closed for not following the PR template.
How did you verify your code works?
- Set
LITELLM_API_KEY+LITELLM_HOSTpointing to a running LiteLLM proxy - Run
opencode— LiteLLM models appear in model picker - Select a model and send a message — streaming works
- Test aliased reasoning model (e.g.
o3-custom→ Mistral) — reasoning params NOT injected - Test actual Claude reasoning model —
thinkingvariants work - Test without proxy running — graceful fallback, provider hidden
- Test with older proxy (no
/model/info) — falls back to/modelswith sensible defaults
Screenshots / recordings
N/A — no UI changes
Checklist
- [x] I have tested my changes locally
- [x] I have not included unrelated changes in this PR
The following comment was made by an LLM, it may be inaccurate:
Based on my search, I found two related PRs that are NOT duplicates but are closely related:
-
PR #14277: feat(opencode): add dynamic model fetching for OpenAI-compatible provider
- Related because the current PR builds on ideas from this PR (clean fallback chain mentioned in description)
-
PR #13896: feat(opencode): add auto loading models for litellm providers
- Related because the current PR explicitly builds on ideas from this PR (fallback endpoint, over-200k pricing, temperature detection mentioned in description)
These PRs appear to be related work in the same area but are separate features. PR #14468 (the current PR) is a distinct, more comprehensive implementation of the LiteLLM provider with auto-discovery, and it references these earlier related PRs rather than duplicating them.
No duplicate PRs found.
lgtm, but test fails. check e2e. this test fails: e2e/projects/projects-switch.spec.ts:49:1 › switching back to a project opens the latest workspace session
Did you try testing locally? bun test:e2e:local
@alexyaroshuk, yes, sorry, fixed all the tests
👍
@alexyaroshuk, may I have your blessing on this? 🥺
@adamdotdevin can this one get a look?
:shipit: maybe?
@alexyaroshuk @adamdotdevin any luck to get it merged soon ?
@balcsida please rebase, there are some conflicts now. @alexyaroshuk @adamdotdevin could you review please? This will make so many opencode users in enterprise world very happy. Thanks!
Hey @kkugot
Thanks for the ping, I rebased the branch and fixed the conflicts, but dev currently fails, so tests for this PR will fail as well.
While I understand how this feature is a very nice to have in an enterprise environment (it is exactly the same reason why I sent this PR - we would like to use this as well), please kindly don't spam alexyaroshuk and adamdotdevin - I would rather not like put additional pressure on them.
Kind regards, @balcsida
I would wait until this is cleared up:
https://github.com/BerriAI/litellm/issues/24512
litellm is compromised https://github.com/BerriAI/litellm/issues/24512
Any eta before this is merged?
I don’t mean to add any pressure, but I’d really appreciate an estimated timeline for this.
Any ETA for this? This would be really useful
I packaged up opencode with this PR merged on my fork until this gets merged: https://github.com/balcsida/opencode/releases
Also made available on my Homebrew tap for your convenience:
brew tap balcsida/tap
brew install balcsida/tap/opencode-fork
Please keep in mind that these are no way official releases and while I'm doing my best effort to keep it up to date, kindly expect some lag behind the official releases.
what do we need to do, to merge this in?
Guys, what's going on here? It's been five months, and it feels like this isn't being prioritized. Could one of the maintainers who really cares about the the open-source community please take a look and review this? At this point, the long delay is starting to feel intentional.
I'm tired
Sorry @balcsida
If it makes you feel better, I've been tracking your PR since the start. Real shame OpenCode ignored this PR.