models.mdx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. ---
  2. title: "Models"
  3. description: ""
  4. ---
  5. OpenCode builds its model catalog from [Models.dev](https://models.dev), provider integrations, and your configuration.
  6. Only enabled models whose provider is available for the current project appear in the model picker.
  7. Connect a provider with `/connect` in the TUI, or configure it in [Providers](/providers).
  8. ## Choose a model
  9. Open the model picker with `/models` or the default `<leader>m` keybind. The picker shows the models available from
  10. providers connected to the current project.
  11. Select a model to use it in the current session. Switching models updates that session without changing your config. Use
  12. the catalog entries shown in the picker rather than guessing a provider or model name.
  13. ## Per-run model
  14. Select a model for one non-interactive run with `--model` or `-m`:
  15. ```bash
  16. opencode2 run --model openai/gpt-5.2 "Explain this repository"
  17. opencode2 run -m openai/gpt-5.2#high "Review the current changes"
  18. ```
  19. Agents and commands can also select their own model. See [Agents](/agents) and [Commands](/commands).
  20. ## Variants
  21. Variants are named request overlays for one model, commonly used for reasoning effort or token budgets. Available names
  22. are model-specific and are derived from current catalog metadata. Do not assume that names such as `low`, `high`, or
  23. `max` exist for every model; `/variants` shows the valid choices.
  24. Use `/variants` to choose one for the current model, or press `ctrl+t` to cycle through available variants.
  25. ## Configure
  26. ### Default model
  27. Set `model` in `opencode.json` or `opencode.jsonc`:
  28. ```jsonc title="opencode.jsonc"
  29. {
  30. "$schema": "https://opencode.ai/config.json",
  31. "model": "anthropic/claude-sonnet-4-5"
  32. }
  33. ```
  34. The configured model becomes the catalog default when its provider is available and the model is enabled. Otherwise,
  35. session execution falls back to the newest available supported model. An explicit model already selected on a session
  36. takes precedence over the default; switching models changes that session and does not rewrite your config.
  37. See [Config](/config) for configuration locations and precedence.
  38. ### Model settings
  39. Provider and model entries can supply three kinds of request configuration:
  40. - `settings` contains provider-package options such as `baseURL`, `reasoningEffort`, or `thinkingConfig`.
  41. - `headers` adds HTTP request headers.
  42. - `body` adds provider-specific fields to the request body.
  43. These values are provider-specific JSON. OpenCode applies provider values first, then model values, then the selected
  44. variant. Nested `settings` and `body` objects are merged; later array and scalar values replace earlier values. Header
  45. names are matched case-insensitively.
  46. You can also map a friendly catalog ID to a different API model ID with `modelID`:
  47. ```jsonc title="opencode.jsonc"
  48. {
  49. "$schema": "https://opencode.ai/config.json",
  50. "model": "openai/coding-default",
  51. "providers": {
  52. "openai": {
  53. "models": {
  54. "coding-default": {
  55. "modelID": "gpt-5.2",
  56. "name": "Coding default",
  57. "capabilities": {
  58. "tools": true,
  59. "input": ["text", "image"],
  60. "output": ["text"]
  61. },
  62. "limit": {
  63. "context": 200000,
  64. "output": 32000
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }
  71. ```
  72. Here `openai/coding-default` is the selectable catalog reference, while `gpt-5.2` is sent to the provider. When adding a
  73. model that is not already in the catalog, set accurate `capabilities` and `limit` values so OpenCode can expose tools and
  74. enforce the correct context limits. Set `disabled: true` on a model entry to hide it from the available catalog.
  75. ### Custom variants
  76. Add a variant, or override a catalog variant with the same ID, under the model's `variants` array:
  77. ```jsonc title="opencode.jsonc"
  78. {
  79. "$schema": "https://opencode.ai/config.json",
  80. "providers": {
  81. "openai": {
  82. "models": {
  83. "gpt-5.2": {
  84. "settings": {
  85. "reasoningEffort": "medium"
  86. },
  87. "variants": [
  88. {
  89. "id": "fast",
  90. "settings": {
  91. "reasoningEffort": "low"
  92. }
  93. },
  94. {
  95. "id": "deep",
  96. "settings": {
  97. "reasoningEffort": "high",
  98. "reasoningSummary": "auto"
  99. }
  100. }
  101. ]
  102. }
  103. }
  104. }
  105. }
  106. }
  107. ```
  108. Variant entries support `settings`, `headers`, and `body`. Selecting one deeply overlays its values on the effective
  109. provider and model configuration. An unknown variant fails model resolution instead of silently using the base model.
  110. ### Local models
  111. For an OpenAI-compatible server, define a provider package, endpoint, and at least one model:
  112. ```jsonc title="opencode.jsonc"
  113. {
  114. "$schema": "https://opencode.ai/config.json",
  115. "model": "local/coder",
  116. "providers": {
  117. "local": {
  118. "name": "Local server",
  119. "package": "aisdk:@ai-sdk/openai-compatible",
  120. "settings": {
  121. "baseURL": "http://127.0.0.1:1234/v1"
  122. },
  123. "models": {
  124. "coder": {
  125. "modelID": "model-name-on-server",
  126. "capabilities": {
  127. "tools": true,
  128. "input": ["text"],
  129. "output": ["text"]
  130. },
  131. "limit": {
  132. "context": 32768,
  133. "output": 8192
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. ```
  141. Use the server's real model name, limits, modalities, and tool support. OpenCode cannot infer these for a model you add
  142. manually. If the endpoint requires a key, add `apiKey` to provider `settings` using an environment substitution such as
  143. `"apiKey": "{env:LOCAL_API_KEY}"`; do not commit secrets.
  144. ### Model references
  145. Configuration and CLI options identify a model as `provider/model`, with an optional `#variant`:
  146. ```text
  147. openai/gpt-5.2
  148. openai/gpt-5.2#high
  149. openrouter/anthropic/claude-sonnet-4.5#high
  150. ```
  151. OpenCode splits the reference at the first `/`, so model IDs may contain additional slashes. Provider and model IDs are
  152. case-sensitive. Provider IDs cannot contain `/` or `#`, and model IDs cannot contain `#`.
  153. The expanded config form is equivalent when generated or programmatic configuration is more convenient:
  154. ```jsonc
  155. {
  156. "model": {
  157. "providerID": "openrouter",
  158. "model": "anthropic/claude-sonnet-4.5"
  159. }
  160. }
  161. ```
  162. Root, agent, and command `model` fields accept both forms. Use the IDs shown by `/models`, not provider display names.
  163. ### Caveats
  164. - The selector object uses `model`, while a provider catalog entry uses `modelID` for the upstream API identifier.
  165. - The root `model` currently sets the default provider and model only. Although its selection shape accepts a variant,
  166. the V2 catalog default does not retain it; select a variant in the TUI, with `opencode2 run`, or on an agent or command.
  167. - Model options are provider-specific. A setting accepted by one provider package may be ignored or rejected by another.
  168. - Catalog data, credentials, and config are location-scoped. A model available in one project may be unavailable in
  169. another.
  170. - Configuration files are watched and normally reload automatically, but an in-flight model request keeps the settings
  171. with which it started.