Skip to content

Provide support to connect to an OpenRouter preset / specific model by chatLanguageModels.json #297863

Description

OpenRouter now supports presets, which can be used to fine tune model access. Such as requesting GLM-4.5 Air (free) and falling through to GLM 4.7 Flash when free inference is limited.

Image

OpenCode can connect to presets via config like the following

{
  "provider": {
   "openrouter": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "OpenRouter (external)",
      "options": {
        "baseURL": "https://openrouter.ai/api/v1"
      },
      "models": {
        "@preset/free-then-cheap": {
          "name": "Free then Cheap (OpenRouter)"
        }
      }
    }

  } 
}

However OpenRouter does not list presets in calls to https://openrouter.ai/api/v1/models, even with the appropriate Auth token, so they have to selected manually.

Provide support to list list in ~/.config/Code/User/chatLanguageModels.json, e.g.

[
	{
		"name": "OpenRouter",
		"vendor": "openrouter",
		"apiKey": "<api_key>",
		"models": [
			{
				"id": "@preset/free-then-cheap",
				"name": "Free then Cheap",
				"url": "https://openrouter.ai/api/v1/chat/completions",
				"toolCalling": true,
				"vision": false,
				"maxInputTokens": 128000,
				"maxOutputTokens": 16000
			}
		]
	},
]

Metadata

Metadata

Labels

*out-of-scopePosted issue is not in scope of VS Code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions