Sin descripción

Paul Klumpp 60f6425e36 Add --format v1/v2: output both V2-native and V1-compatible opencode.jsonc hace 2 semanas
.gitignore 5909713865 Fetch OpenAI-compatible models and generate opencode.jsonc config hace 1 mes
LICENSE 0027e58ed3 Initial commit hace 2 meses
README.md 60f6425e36 Add --format v1/v2: output both V2-native and V1-compatible opencode.jsonc hace 2 semanas
fetch_models_for_opencode.go 60f6425e36 Add --format v1/v2: output both V2-native and V1-compatible opencode.jsonc hace 2 semanas
go.mod 5909713865 Fetch OpenAI-compatible models and generate opencode.jsonc config hace 1 mes
opencode.jsonc 5909713865 Fetch OpenAI-compatible models and generate opencode.jsonc config hace 1 mes

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 /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 OmniRoute --baseurl http://localhost:20128/v1 --token sk-1234

Output: an opencode.jsonc file ready to use — either V2-native (default) or V1-compatible.

Formats

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

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
-format v2 Output format: v2 (default) or v1

Build

go build -o fetch_models_for_opencode .