No description
- Go 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
- Fetch /models from OpenAI-compatible endpoint - Support both x-api-key and Authorization: Bearer headers - Generate opencode.jsonc with all models and context/output limits - Add README and go.mod |
||
| .gitignore | ||
| fetch_models_for_opencode.go | ||
| go.mod | ||
| LICENSE | ||
| opencode.jsonc | ||
| README.md | ||
fetch_models_for_opencode
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.
How it works
- Fetches
/modelsfrom the given base URL - Creates a provider entry (
@ai-sdk/openai-compatible) with all models - Context/output limits are read from model metadata (fallbacks: 131072 / 8192)
Usage
go run . --provider Myprovider --baseurl http://localhost:8080/v1 --token sk-1234
Flags
| 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 |
Build
go build -o fetch_models_for_opencode .