Skip to content

feat(opencode): auto-discover models from OpenAI-compatible providers - #2

Closed
sethjones wants to merge 11 commits into
devfrom
custom-model-discovery
Closed

sethjones wants to merge 11 commits into
devfrom
custom-model-discovery

Conversation

@sethjones

@sethjones sethjones commented Jun 15, 2026 •

Copy link
Copy Markdown
Owner

Issue for this PR

Type of change

  • New feature

What does this PR do?

Auto-discovers available models from OpenAI-compatible providers that have a baseURL configured in opencode.json. Instead of requiring users to list every model manually, opencode now calls GET /v1/models at startup and populates the model list.

Models come from three sources: Models.dev (metadata), config file (overrides), and the provider API (actual availability). A model is visible only if the provider API returns it or it is declared in config. Metadata is merged with API > config > Models.dev precedence.

This means providers like LM Studio, Ollama, and self-hosted OpenAI-compatible servers automatically show their loaded models without any per-model configuration.

How did you verify your code works?

  • Built a standalone binary and ran it with an LM Studio server configured via baseURL
  • Confirmed models appear in the TUI /models list without manual per-model config
  • Confirmed models not returned by the provider API are hidden, even if listed in Models.dev
  • Confirmed startup completes without hanging or displaying discovery output to the terminal
  • Ran bun typecheck from packages/opencode — passes
  • Ran provider tests — pass

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

- Fetch models from OpenAI-compatible providers with baseURL in config
- Support plugin-registered discovery loaders (e.g., GitLab)
- Discovery runs synchronously during bootstrap init
- Remove providers with no models after successful discovery
- Add tests for discovery and model registration
@sethjones sethjones changed the title Custom model discovery feat(opencode): auto-discover models from OpenAI-compatible providers Jun 15, 2026
sethjones and others added 9 commits June 17, 2026 15:52
- Extract discoverProviderModels() helper from inline 110-line Effect.gen
- Replace globalThis.fetch with HttpClient layer (FetchHttpClient)
- Add Effect.timeout(10s) to HTTP discovery requests
- Replace Exit._tag with Exit.isSuccess/IsFailure
- Remove redundant config.get() in init() (use captured s.cfg)
- Remove unnecessary 'as any' casts
- Fix indentation to consistent 2-space
- Set family: 'discovered' on discovered models
- Update discovery tests to use HttpClient layer mocks
…nai-compatible schemas

- Log warning and continue when provider disappears between discovery snapshot and apply
- Add @ai-sdk/openai-compatible to schema sanitization check
- Add test case for openai-compatible schema sanitization
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