|
|
hai 2 semanas | |
|---|---|---|
| .gitignore | hai 1 mes | |
| LICENSE | hai 2 meses | |
| README.md | hai 2 semanas | |
| fetch_models_for_opencode.go | hai 2 semanas | |
| go.mod | hai 1 mes | |
| opencode.jsonc | hai 1 mes |
A small Go tool that fetches the model list from an OpenAI-compatible endpoint
(GET <baseurl>/models) and generates an opencode.jsonc config file for
OpenCode.
OpenCode only allows adding models manually via opencode.jsonc – there is no
way to import them automatically. This is tedious when your provider offers many
models.
Example: I run this tool against OmniRoute, a local AI gateway that exposes hundreds of models and combo models through a single OpenAI-compatible endpoint – exactly the models I want to use in OpenCode. Instead of writing every entry by hand, this tool generates the complete provider config in one go.
/models from the given base URL@ai-sdk/openai-compatible) with all modelsgo run . --provider OmniRoute --baseurl http://localhost:20128/v1 --token sk-1234
Output: an opencode.jsonc file ready to use — either V2-native (default) or V1-compatible.
| Flag | Top-level key | Provider key | Config key |
|---|---|---|---|
--format v2 (default) |
"provider" |
"npm" |
"options" |
--format v1 |
"providers" |
"package" |
"settings" |
Both shapes are accepted by OpenCode V2. Use v2 for new configs, v1 when you need compatibility with existing tooling or the V1-compatible global config.
# V2-native (default)
go run . --provider OmniRoute --baseurl http://localhost:20128/v1
# V1-compatible
go run . --provider OmniRoute --baseurl http://localhost:20128/v1 --format v1
| Flag | Default | Description |
|---|---|---|
-provider |
Myprovider |
Provider name |
-baseurl |
– (required) | Base URL, e.g. http://localhost:8080/v1 |
-output |
opencode.jsonc |
Output file |
-token |
– | API token sent as Authorization: Bearer and x-api-key |
-apiurl |
<baseurl>/models |
Alternative URL for fetching the model list |
-format |
v2 |
Output format: v2 (default) or v1 |
go build -o fetch_models_for_opencode .