Repository navigation
Conversation
|
The following comment was made by an LLM, it may be inaccurate: |
There was a problem hiding this comment.
This works as described. I ran a mock LiteLLM proxy on 127.0.0.1:4000 and ran opencode models from source. On the base, no litellm models appear. With this PR, chat models are discovered, the embedding model is left out, and max_input_tokens becomes the context limit. I also tried a config that already defines a custom providers.litellm provider (headers, apiKey, models with tools/image capabilities, and a model the proxy doesn't list). All of those settings were kept, and discovery sent the Bearer key. The LiteLLM and vLLM tests pass, and typecheck in packages/core is clean.
Public API: this adds the built-in provider ID litellm and the plugin ID opencode.provider.litellm. Settings are providers.litellm.settings.baseURL/apiKey, and discovery can be turned off with -opencode.provider.litellm. OpenCode now also checks 127.0.0.1:4000 by default. It is backwards compatible: existing custom litellm provider configs keep working, and I tested this.
Two optional suggestions, noted inline: the default check on port 4000 could confirm the server is actually LiteLLM, and the docs could explain how to turn tools and images back on.
| discover: (client) => | ||
| Effect.gen(function* () { | ||
| const response = yield* client.getJson("/v1/models", Response) | ||
| return response.data |
There was a problem hiding this comment.
This now checks 127.0.0.1:4000 every 30s for every user, and port 4000 is a common dev-server port (Phoenix, Jekyll, …). The vLLM plugin checks /health and only accepts models where owned_by === "vllm", so other servers aren't mistaken for it. Here, any OpenAI-compatible server on port 4000 would appear as "LiteLLM". Could you first check something only LiteLLM serves, such as the unauthenticated /health/liveliness endpoint, before reading /v1/models?
| OpenCode refreshes `/v1/models` in the background. It uses `max_input_tokens` as the context limit when the proxy | ||
| reports it, and it excludes models whose `mode` is not `chat`. | ||
|
|
||
| Discovered models advertise text input and output, but not vision or tools. `/v1/models` does not report what the model |
There was a problem hiding this comment.
Most LiteLLM proxies sit in front of models that support tools and images (Claude, GPT, …). With input: ["text"], pasted images are replaced with a text placeholder (see #47480). Overriding this per model in providers.litellm.models.<id>.capabilities works: I tested it, and the override is kept after discovery. A short example of that override here would save users from getting stuck.
Another OpenAI-compatible server on port 4000 is no longer shown as LiteLLM. The docs show how to set tools and image input for a discovered model.
|
Thanks for the review. I changed both points:
The LiteLLM and vLLM tests pass, and |
|
Thanks for implementing this. One missing piece for local coding-agent use is enriching discovery with LiteLLM’s /model/info metadata.
|
Issue for this PR
Refs #48938
Type of change
What does this PR do?
I add LiteLLM as a built-in provider with the id
litellm, with tests and docs. It reuses the local-provider code that vLLM and Ollama use.OpenCode reads
/v1/modelsfromhttp://127.0.0.1:4000in the background. A user can setproviders.litellm.settings.baseURLand an optionalapiKey. It sends the key as a Bearer token. I do not hardcode a model catalog.#48938 asks for this. PR #29937 closed because of the V2 move, so this change targets V2.
The models.dev entry is a separate PR. This change does not need it. Gateway cost (#43818, #52127) is out of scope.
A proxy with auth needs
apiKeyin config./v1/modelsdoes not report tool or image support, so discovered models start with both off.How did you verify your code works?
bun test test/plugin/provider-litellm.test.ts test/plugin/provider-vllm.test.tsinpackages/core: 7 pass.bun run typecheckinpackages/core: errors only in unrelated files.prettier --checkpasses on the new TypeScript files.oxlintwith default rules finds nothing. I did not run the repooxlintconfig.Screenshots / recordings
No UI change.
Checklist
If you do not follow this template your PR will be automatically rejected.
Added by the opencode bot (AI-generated).
Fixes #48938
Related: #53235, #47480, #52127, #43818
Public API: adds the built-in
litellmprovider (pluginopencode.provider.litellm,providers.litellm.settings.baseURL/apiKey), which auto-discovers models from 127.0.0.1:4000 (backwards compatible)