models.mdx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. ---
  2. title: Models
  3. description: Configuring an LLM provider and model.
  4. ---
  5. OpenCode uses the [AI SDK](https://ai-sdk.dev/) and [Models.dev](https://models.dev) to support for **75+ LLM providers** and it supports running local models.
  6. ---
  7. ## Providers
  8. Most popular providers are preloaded by default. If you've added the credentials for a provider through `opencode auth login`, they'll be available when you start OpenCode.
  9. Learn more about [providers](/docs/providers).
  10. ---
  11. ## Select a model
  12. Once you've configured your provider you can select the model you want by typing in:
  13. ```bash frame="none"
  14. /models
  15. ```
  16. ---
  17. ## Recommended models
  18. There are a lot of models out there, with new models coming out every week.
  19. :::tip
  20. Consider using one of the models we recommend.
  21. :::
  22. However, there are only a few of them that are good at both generating code and tool calling.
  23. Here are several models, in no particular order, that work well with OpenCode (to name a few):
  24. - GPT 5
  25. - GPT 5 Codex
  26. - Claude Sonnet 4.5
  27. - Claude Sonnet 4
  28. - Claude Opus 4.1
  29. - Kimi K2
  30. - Qwen3 Coder
  31. - GPT 4.1
  32. - Gemini 2.5 Pro
  33. ---
  34. ## Set a default
  35. To set one of these as the default model, you can set the `model` key in your
  36. OpenCode config.
  37. ```json title="opencode.json" {3}
  38. {
  39. "$schema": "https://opencode.ai/config.json",
  40. "model": "lmstudio/google/gemma-3n-e4b"
  41. }
  42. ```
  43. Here the full ID is `provider_id/model_id`.
  44. If you've configured a [custom provider](/docs/providers#custom), the `provider_id` is key from the `provider` part of your config, and the `model_id` is the key from `provider.models`.
  45. ---
  46. ## Configure models
  47. You can globally configure a model's options through the config.
  48. ```jsonc title="opencode.jsonc" {7-12,19-24}
  49. {
  50. "$schema": "https://opencode.ai/config.json",
  51. "provider": {
  52. "openai": {
  53. "models": {
  54. "gpt-5": {
  55. "options": {
  56. "reasoningEffort": "high",
  57. "textVerbosity": "low",
  58. "reasoningSummary": "auto",
  59. "include": ["reasoning.encrypted_content"],
  60. },
  61. },
  62. },
  63. },
  64. "anthropic": {
  65. "models": {
  66. "claude-sonnet-4-5-20250929": {
  67. "options": {
  68. "thinking": {
  69. "type": "enabled",
  70. "budgetTokens": 16000,
  71. },
  72. },
  73. },
  74. },
  75. },
  76. },
  77. }
  78. ```
  79. Here we're configuring global settings for two built-in models: `gpt-5` when accessed via the `openai` provider, and `claude-sonnet-4-20250514` when accessed via the `anthropic` provider.
  80. The built-in provider and model names can be found on [Models.dev](https://models.dev).
  81. You can also configure these options for any agents that you are using. The agent config overrides any global options here. [Learn more](/docs/agents/#additional).
  82. You can also define custom models that extend built-in ones and can optionally use specific options by referring to their id:
  83. ```jsonc title="opencode.jsonc" {6-20}
  84. {
  85. "$schema": "https://opencode.ai/config.json",
  86. "provider": {
  87. "opencode": {
  88. "models": {
  89. "gpt-5-high": {
  90. "id": "gpt-5",
  91. "options": {
  92. "reasoningEffort": "high",
  93. "textVerbosity": "low",
  94. "reasoningSummary": "auto",
  95. },
  96. },
  97. "gpt-5-low": {
  98. "id": "gpt-5",
  99. "options": {
  100. "reasoningEffort": "low",
  101. "textVerbosity": "low",
  102. "reasoningSummary": "auto",
  103. },
  104. },
  105. },
  106. },
  107. },
  108. }
  109. ```
  110. ---
  111. ## Loading models
  112. When OpenCode starts up, it checks for models in the following priority order:
  113. 1. The `--model` or `-m` command line flag. The format is the same as in the config file: `provider_id/model_id`.
  114. 2. The model list in the OpenCode config.
  115. ```json title="opencode.json"
  116. {
  117. "$schema": "https://opencode.ai/config.json",
  118. "model": "anthropic/claude-sonnet-4-20250514"
  119. }
  120. ```
  121. The format here is `provider/model`.
  122. 3. The last used model.
  123. 4. The first model using an internal priority.