-
Couldn't load subscription status.
- Fork 2.2k
Fetch from model list from /v1/models/ from OpenAI Compatible APIs
#3427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
- Implement automatic fetching of models from /v1/models endpoint for custom OpenAI-compatible providers - Add proper API key handling from auth.json or environment variables - Include enhanced logging for debugging provider configuration - Enable support for providers configured with @ai-sdk/openai-compatible npm package
/v1/models/ from OpenAI Compatible APIs
| // For custom config providers, we may need to get the npm field from config | ||
| const npmPackage = providerInfo?.npm || config.provider?.[providerID]?.npm; | ||
| if (npmPackage !== "@ai-sdk/openai-compatible") { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't gonna work for like any providers
| }, | ||
| limit: { | ||
| context: 4096, // Default context limit | ||
| output: 4096, // Default output limit | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause a veryyy poor experience for a lot of people 4096 context window isn't gonna be useful for most agentic work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just opened the repo to search if I could get away with 4096 context window length (or by disabling /compact)
And yes, I agree it was pretty ugly. just happened to me. should have also tested out the models itself as well.
| // Create a default model entry with basic information | ||
| fetchedModels[modelData.id] = { | ||
| id: modelData.id, | ||
| name: modelData.id || modelData.name || modelData.object || "Unknown Model", // Use id, name, or object from API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't model name required, i think it will always be defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm, It is required but ig a good idea to let it stay here as well? unless I am missing out on something that you can see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean name field returned from the api will always be defined modelData.name so no need for all the ORs
|
There is something to this for providing a good ux, I'm wondering can we restrict it to:
And then don't override any of their existing custom models for that provider What is teh default context size for LM studio? |
|
Also we have these style preferences I should make a style guide: |

This commit introduces automatic model discovery for OpenAI-compatible providers, allowing OpenCode to dynamically fetch available models from the /v1/models endpoint instead of requiring manual model configuration.
Key changes:
This enhancement enables OpenCode to work seamlessly with OpenAI-compatible APIs such as local LLM servers (Ollama, LocalAI), API proxies, and custom implementations without requiring manual model definitions in the configuration. The functionality addresses the need for supporting custom and local AI providers with dynamic model discovery.
Fixes the issue where OpenAI-compatible providers would show no available models unless manually configured in opencode.json.
(the PR is generated by qwen, though I have tested it out locally properly with the provider, used nano-gpt.com/api/v1 for this)