翻篇收录说明
翻篇网页快照

Models | OpenCode

https://opencode.ai/docs/models/

最近抓取:2026-12-02 17:38:54(北京时间)

最近内容变化:2026-11-30 03:14:51(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Choose a model per session or run, set a default, and configure variants, reasoning, prompt caching, and local models.

正文摘录

ModelsChoose a model for the current session with /models: /models OpenCode lists models from models.dev, provider integrations, and your configuration. The selector only shows enabled models whose provider is available in the current project. Connect providers in Providers. Select Pick an entry from /models instead of guessing its provider or model ID. The selection applies to the current session and does not change your configuration. anthropic/claude-sonnet-5-5 Availability is project-specific: The model must be enabled. Its provider must be available in the current project. Credentials and configuration from another project do not carry over automatically. Runs Use --model to choose a model for one command-line run without changing the configured default: Terminalopencode run --model anthropic/claude-sonnet-5-5 "Refactor parseToken" Agents and commands can also choose their own model. See Agents and Commands. Defaults Set model in opencode.json or opencode.jsonc to choose the default for new work: opencode.jsonc{ "$schema": "https://opencode.ai/config.json", "model": "anthropic/claude-sonnet-5-5", } The configured model becomes the catalog default when it is enabled and its provider is available. Otherwise, OpenCode falls back to the newest available supported model. A model already selected for a session takes precedence over the configured default. Switching a session’s model does not rewrite the config file. The root model currently retains only the default provider and model, not a variant. See Config for configuration locations and precedence. Free models Set OPENCODE_DISABLE_FREE_MODELS=1 (or true) on the server process to hide free OpenCode models: TerminalOPENCODE_DISABLE_FREE_MODELS=1 opencode serve For the shared background server: Terminalopencode service set env OPENCODE_DISABLE_FREE_MODELS 1 Free means an opencode or opencode-go model with no input price. These models disappear from the catalog and defaults; explicitly selecting one fails with Model unavailable. Signed out, the opencode provider is absent until you connect an OpenCode Console account or set OPENCODE_API_KEY, which restores its paid models. To block free models for everyone in an organization, use a policy instead. See Enterprise. Variants Variants are named options for one model, often used for reasoning effort or token budgets. Add #variant when selecting one for a run, session, agent, or command: Terminalopencode run --model openai/gpt-6.1-sol#high "Review this migration plan" Variant names come from the selected model’s current catalog metadata. Names such as low, high, and max are not available for every model, and an unknown variant produces a model-resolution error. Define new variants, or replace catalog variants with the same ID, in the model’s variants array: opencode.jsonc{ "$schema": "https://opencode.ai/config.json", "providers": { "openai": { "models": { "gpt-6.1-sol": { "settings": { "reasoningEffort": "medium", }, "variants": [ { "id": "fast", "settings": { "reasoningEffort": "low", }, }, { "id": "deep", "settings": { "reasoningEffort": "high", "reasoningSummary": "auto", }, }, ], }, }, }, }, } Each variant can contain settings, headers, and body. Its values are applied after provider and model values. To replace a model’s reasoning variants, describe its reasoning controls in capabilities.reasoning, using the models.dev v2 shape. OpenCode builds the variants for the model’s package from them: opencode.jsonc{ "providers": { "openai": { "models": { "gpt-6.1-sol": { "capabilities": { "reasoning": { "supported": true, "effort": ["low", "medium", "high"], }, }, }, }, }, }, } FieldPurposesupportedWhether the model reasons. false, or true without controls, adds no variants.toggleAdds a none variant that turns reasoning off.effortEffort levels to offer. default keeps the provider default and adds no variant.budgetOptional min and max thinking tokens. Ignored when effort is set. Variants listed in variants are applied on top of the ones built from capabilities.reasoning. Options Provider and model entries can customize requests with settings, headers, and body: opencode.jsonc{ "providers": { "openai": { "settings": { "baseURL": "https://api.example.com/v1", }, "headers": { "X-Team": "platform", }, "models": { "gpt-6.1-sol": { "settings": { "reasoningEffort": "high", }, "body": { "store": false, }, }, }, }, }, } FieldPurposesettingsProvider-package options such as baseURL or reasoningEffort.headersAdditional HTTP request headers.bodyProvider-specific request body fields. OpenCode applies provider values first, model values second, and the selected variant last. Nested settings and body objects are merged. Later arrays and scalar values replace earlier values. Header names are matched case-insensitively. Options are provider-specific and may be ignored or rejected by another provider package. Aliases Use modelID to give an API model a friendlier catalog ID: opencode.jsonc{ "$schema": "https://opencode.ai/config.json", "model": "openai/coding-default", "providers": { "openai": { "models": { "coding-default": { "modelID": "gpt-6.1-sol", "name": "Coding default", "capabilities": { "tools": true, "freeform": ["text", "lark"], "input": ["text", "image"], "output": ["text"], }, "limit": { "context": 200000, "output": 32000, }, }, }, }, }, } Here, openai/coding-default is the selectable reference and gpt-6.1-sol is sent to the provider. For a model that is not already in the catalog, OpenCode assumes: JSON tool support, text and image input, and text output. No freeform tool input unless capabilities.freeform lists the format. A 200,000-token context limit and 32,000-token output limit. An unspecified input limit. OpenCode recognizes text, regex, and lark. Other format names from models.dev are ignored without dropping the model or its tools. If a proxy in front of a catalog model rejects freeform tools, set capabilities.freeform to [] on that model. These are fallback assumptions, not detected capabilities. Set accurate capabilities and limit values when known; explicit values replace the fallbacks. Automatic compaction uses limit.input capped at limit.context; see Window. Add disabled: true to hide a model from the available catalog: opencode.jsonc{ "providers": { "openai": { "models": { "legacy-model": { "disabled": true, }, }, }, }, } Reasoning For an OpenAI-compatible model that streams reasoning in a custom assistant-message field, set compatibility.reasoningField: opencode.jsonc{ "providers": { "local": { "models": { "reasoner": { "compatibility": { "reasoningField": "reasoning_content", }, }, }, }, }, } OpenCode recognizes reasoning, reasoning_content, and reasoning_text, and also accepts another provider-specific string. It reads streamed reasoning from that field and restores the field when sending prior assistant messages back to the model. See Compatibility for the related requireReasoning field. Prompt caching OpenCode places prompt-cache breakpoints automatically on routes that are known to need them, such as Anthropic. When Claude models are served through an OpenAI-compatible proxy such as LiteLLM, OpenCode cannot tell that they need Anthropic-style cache_control breakpoints. Set compatibility.cacheFormat on those Claude models: opencode.jsonc{ "providers": { "litellm": { "package": "@opencode/ai/providers/openai-compatible", "settings": { "baseURL": "https://litellm.example.com/v1" }, "models": { "claude-sonnet-5-5": { "compatibility": { "cacheFormat": "anthropic" }, }, "claude-opus-5-5": { "compatibility": { "cacheFormat": "anthropic" }, }, // Other models on the same proxy cache automatically and need no setting. "gpt-6.1-sol": {}, }, }, }, } OpenCode then marks the last tool definition, the system prompt, and the latest message with cache_control: { "type": "ephemeral" }, which uses the endpoint’s default five-minute cache lifetime. Use "alibaba" for Alibaba Model Studio models, which accept the same markers but ignore them on tool definitions. Set compatibility.cacheFormat on the provider instead when every model it serves accepts the same format. See Compatibility for the other fields. Cache lifetime OpenCode doesn’t send a cache lifetime by default, so each provider uses its own default, such as five minutes on Anthropic. Set settings.cache.ttl on a provider or model to request a different one. A model setting overrides the provider setting. opencode.jsonc{ "providers": { "anthropic": { "settings": { "cache": { "ttl": "1h" } }, "models": { "claude-haiku-5-5": { "settings": { "cache": { "ttl": "5m" } } }, }, }, }, } ttl takes a number and a unit: ms, s, m, h or d, such as "5m", "1h" or "24h". OpenCode sends it as given, so use a value the provider accepts: APIWhere the lifetime goesAnthropic Messagescache_control.ttl on each cache marker. Anthropic accepts "5m" and "1h".Bedrock Conversettl on each cachePoint. Older Claude models that only cache for five minutes ignore "1h".OpenAI Chat and Responses"24h" goes to prompt_cache_retention; other values go to prompt_cache_options.ttl. Providers that cache automatically without markers, such as Gemini, ignore it. A longer lifetime usually costs more to write: Anthropic charges 2× the input price for a one-hour cache write and 1.25× for a five-minute one. Warming can use the lifetime to time its requests with interval: "auto". Compatibility compatibility describes request and response quirks of the API a model is served through, such as which field carries reasoning or whether the endpoint accepts prompt_cache_key. Each model is served through one API, and a field only takes effect when that API reads it. Other fields are ignored. opencode.jsonc{ "providers": { "local": { "compatibility": { "streamUsage": false }, "models": { "reasoner": { "compatibility": { "reasoningField": "reasoning_content", "maxTokensField": "max_tokens" }, }, }, }, }, } Provider compatibility applies to every model of that provider. A model’s own compatibility overrides it field by field: O