# fetch_models_for_opencode A small Go tool that fetches the model list from an OpenAI-compatible endpoint (`GET /models`) and generates an `opencode.jsonc` config file for [OpenCode](https://opencode.ai). 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](https://omniroute.online), 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 `/models` from 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 ``` ## Flags | Flag | Default | Description | |-------------|--------------------|---------------------------------------------| | `-provider` | `Myprovider` | Provider name | | `-baseurl` | – (required) | Base URL, e.g. `http://localhost:8080/v1` | | `-apiurl` | `/models` | Alternative URL for fetching the model list | | `-output` | `opencode.jsonc` | Output file | ## Build ``` go build -o fetch_models_for_opencode . ```