providers.mdx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. ---
  2. title: Providers
  3. description: Using any LLM provider in OpenCode.
  4. ---
  5. import config from "../../../config.mjs"
  6. export const console = config.console
  7. 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.
  8. To add a provider you need to:
  9. 1. Add the API keys for the provider using `opencode auth login`.
  10. 2. Configure the provider in your OpenCode config.
  11. ---
  12. ### Credentials
  13. When you add a provider's API keys with `opencode auth login`, they are stored
  14. in `~/.local/share/opencode/auth.json`.
  15. ---
  16. ### Config
  17. You can customize the providers through the `provider` section in your OpenCode
  18. config.
  19. ---
  20. #### Base URL
  21. You can customize the base URL for any provider by setting the `baseURL` option. This is useful when using proxy services or custom endpoints.
  22. ```json title="opencode.json" {6}
  23. {
  24. "$schema": "https://opencode.ai/config.json",
  25. "provider": {
  26. "anthropic": {
  27. "options": {
  28. "baseURL": "https://api.anthropic.com/v1"
  29. }
  30. }
  31. }
  32. }
  33. ```
  34. ---
  35. ## OpenCode Zen
  36. OpenCode Zen is a list of models provided by the OpenCode team that have been
  37. tested and verified to work well with OpenCode. [Learn more](/docs/zen).
  38. :::tip
  39. If you are new, we recommend starting with OpenCode Zen.
  40. :::
  41. 1. Run `opencode auth login`, select opencode, and head to [opencode.ai/auth](https://opencode.ai/auth).
  42. 2. Sign in, add your billing details, and copy your API key.
  43. 3. Paste your API key.
  44. ```bash
  45. $ opencode auth login
  46. ┌ Add credential
  47. ◇ Select provider
  48. │ opencode
  49. ● Create an api key at https://opencode.ai/auth
  50. ◆ Enter your API key
  51. │ _
  52. ```
  53. 4. Run `/models` in the TUI to see the list of models we recommend.
  54. It works like any other provider in OpenCode. And is completely optional to use
  55. it.
  56. ---
  57. ## Directory
  58. Let's look at some of the providers in detail. If you'd like to add a provider to the
  59. list, feel free to open a PR.
  60. :::note
  61. Don't see a provider here? Submit a PR.
  62. :::
  63. ---
  64. ### Amazon Bedrock
  65. To use Amazon Bedrock with OpenCode:
  66. 1. Head over to the **Model catalog** in the Amazon Bedrock console and request
  67. access to the models you want.
  68. :::tip
  69. You need to have access to the model you want in Amazon Bedrock.
  70. :::
  71. 1. You'll need either to set one of the following environment variables:
  72. - `AWS_ACCESS_KEY_ID`: You can get this by creating an IAM user and generating
  73. an access key for it.
  74. - `AWS_PROFILE`: First login through AWS IAM Identity Center (or AWS SSO) using
  75. `aws sso login`. Then get the name of the profile you want to use.
  76. - `AWS_BEARER_TOKEN_BEDROCK`: You can generate a long-term API key from the
  77. Amazon Bedrock console.
  78. Once you have one of the above, set it while running opencode.
  79. ```bash
  80. AWS_ACCESS_KEY_ID=XXX opencode
  81. ```
  82. Or add it to a `.env` file in the project root.
  83. ```bash title=".env"
  84. AWS_ACCESS_KEY_ID=XXX
  85. ```
  86. Or add it to your bash profile.
  87. ```bash title="~/.bash_profile"
  88. export AWS_ACCESS_KEY_ID=XXX
  89. ```
  90. 1. Run the `/models` command to select the model you want.
  91. ---
  92. ### Anthropic
  93. We recommend signing up for [Claude Pro](https://www.anthropic.com/news/claude-pro) or [Max](https://www.anthropic.com/max), it's the most cost-effective way to use opencode.
  94. Once you've signed up, run `opencode auth login` and select Anthropic.
  95. ```bash
  96. $ opencode auth login
  97. ┌ Add credential
  98. ◆ Select provider
  99. │ ● Anthropic
  100. │ ...
  101. ```
  102. Here you can select the **Claude Pro/Max** option and it'll open your browser
  103. and ask you to authenticate.
  104. ```bash
  105. $ opencode auth login
  106. ┌ Add credential
  107. ◇ Select provider
  108. │ Anthropic
  109. ◆ Login method
  110. │ ● Claude Pro/Max
  111. │ ○ Create API Key
  112. │ ○ Manually enter API Key
  113. ```
  114. Now all the the Anthropic models should be available when you use the `/models` command.
  115. ##### Using API keys
  116. You can also select **Create API Key** if you don't have a Pro/Max subscription. It'll also open your browser and ask you to login to Anthropic and give you a code you can paste in your terminal.
  117. Or if you already have an API key, you can select **Manually enter API Key** and paste it in your terminal.
  118. ---
  119. ### Azure OpenAI
  120. 1. Head over to the [Azure portal](https://portal.azure.com/) and create an **Azure OpenAI** resource. You'll need:
  121. - **Resource name**: This becomes part of your API endpoint (`https://RESOURCE_NAME.openai.azure.com/`)
  122. - **API key**: Either `KEY 1` or `KEY 2` from your resource
  123. 2. Go to [Azure AI Foundry](https://ai.azure.com/) and deploy a model.
  124. :::note
  125. The deployment name must match the model name for opencode to work properly.
  126. :::
  127. 3. Run `opencode auth login` and select **Azure**.
  128. ```bash
  129. $ opencode auth login
  130. ┌ Add credential
  131. ◆ Select provider
  132. │ ● Azure
  133. │ ...
  134. ```
  135. 4. Enter your API key.
  136. ```bash
  137. $ opencode auth login
  138. ┌ Add credential
  139. ◇ Select provider
  140. │ Azure
  141. ◇ Enter your API key
  142. │ _
  143. ```
  144. 5. Set your resource name as an environment variable:
  145. ```bash
  146. AZURE_RESOURCE_NAME=XXX opencode
  147. ```
  148. Or add it to a `.env` file in the project root:
  149. ```bash title=".env"
  150. AZURE_RESOURCE_NAME=XXX
  151. ```
  152. Or add it to your bash profile:
  153. ```bash title="~/.bash_profile"
  154. export AZURE_RESOURCE_NAME=XXX
  155. ```
  156. 6. Run the `/models` command to select your deployed model.
  157. ---
  158. ### Cerebras
  159. 1. Head over to the [Cerebras console](https://inference.cerebras.ai/), create an account, and generate an API key.
  160. 2. Run `opencode auth login` and select **Cerebras**.
  161. ```bash
  162. $ opencode auth login
  163. ┌ Add credential
  164. ◆ Select provider
  165. │ ● Cerebras
  166. │ ...
  167. ```
  168. 3. Enter your Cerebras API key.
  169. ```bash
  170. $ opencode auth login
  171. ┌ Add credential
  172. ◇ Select provider
  173. │ Cerebras
  174. ◇ Enter your API key
  175. │ _
  176. ```
  177. 4. Run the `/models` command to select a model like _Qwen 3 Coder 480B_.
  178. ---
  179. ### DeepSeek
  180. 1. Head over to the [DeepSeek console](https://platform.deepseek.com/), create an account, and click **Create new API key**.
  181. 2. Run `opencode auth login` and select **DeepSeek**.
  182. ```bash
  183. $ opencode auth login
  184. ┌ Add credential
  185. ◆ Select provider
  186. │ ● DeepSeek
  187. │ ...
  188. ```
  189. 3. Enter your DeepSeek API key.
  190. ```bash
  191. $ opencode auth login
  192. ┌ Add credential
  193. ◇ Select provider
  194. │ DeepSeek
  195. ◇ Enter your API key
  196. │ _
  197. ```
  198. 4. Run the `/models` command to select a DeepSeek model like _DeepSeek Reasoner_.
  199. ---
  200. ### Fireworks AI
  201. 1. Head over to the [Fireworks AI console](https://app.fireworks.ai/), create an account, and click **Create API Key**.
  202. 2. Run `opencode auth login` and select **Fireworks AI**.
  203. ```bash
  204. $ opencode auth login
  205. ┌ Add credential
  206. ◆ Select provider
  207. │ ● Fireworks AI
  208. │ ...
  209. ```
  210. 3. Enter your Fireworks AI API key.
  211. ```bash
  212. $ opencode auth login
  213. ┌ Add credential
  214. ◇ Select provider
  215. │ Fireworks AI
  216. ◇ Enter your API key
  217. │ _
  218. ```
  219. 4. Run the `/models` command to select a model like _Kimi K2 Instruct_.
  220. ---
  221. ### GitHub Copilot
  222. To use your GitHub Copilot subscription with opencode:
  223. :::note
  224. Some models might need a [Pro+
  225. subscription](https://github.com/features/copilot/plans) to use.
  226. Some models need to be manually enabled in your [GitHub Copilot settings](https://docs.github.com/en/copilot/how-tos/use-ai-models/configure-access-to-ai-models#setup-for-individual-use).
  227. :::
  228. 1. Run `opencode auth login` and select GitHub Copilot.
  229. ```bash
  230. $ opencode auth login
  231. ┌ Add credential
  232. ◇ Select provider
  233. │ GitHub Copilot
  234. ◇ ──────────────────────────────────────────────╮
  235. │ │
  236. │ Please visit: https://github.com/login/device │
  237. │ Enter code: 8F43-6FCF │
  238. │ │
  239. ├─────────────────────────────────────────────────╯
  240. ◓ Waiting for authorization...
  241. ```
  242. 2. Navigate to [github.com/login/device](https://github.com/login/device) and enter the code.
  243. 3. Now run the `/models` command to select the model you want.
  244. ---
  245. ### Groq
  246. 1. Head over to the [Groq console](https://console.groq.com/), click **Create API Key**, and copy the key.
  247. 2. Run `opencode auth login` and select Groq.
  248. ```bash
  249. $ opencode auth login
  250. ┌ Add credential
  251. ◆ Select provider
  252. │ ● Groq
  253. │ ...
  254. ```
  255. 3. Enter the API key for the provider.
  256. ```bash
  257. $ opencode auth login
  258. ┌ Add credential
  259. ◇ Select provider
  260. │ Groq
  261. ◇ Enter your API key
  262. │ _
  263. ```
  264. 4. Run the `/models` command to select the one you want.
  265. ---
  266. ### LM Studio
  267. You can configure opencode to use local models through LM Studio.
  268. ```json title="opencode.json" "lmstudio" {5, 6, 8, 10-14}
  269. {
  270. "$schema": "https://opencode.ai/config.json",
  271. "provider": {
  272. "lmstudio": {
  273. "npm": "@ai-sdk/openai-compatible",
  274. "name": "LM Studio (local)",
  275. "options": {
  276. "baseURL": "http://127.0.0.1:1234/v1"
  277. },
  278. "models": {
  279. "google/gemma-3n-e4b": {
  280. "name": "Gemma 3n-e4b (local)"
  281. }
  282. }
  283. }
  284. }
  285. }
  286. ```
  287. In this example:
  288. - `lmstudio` is the custom provider ID. This can be any string you want.
  289. - `npm` specifies the package to use for this provider. Here, `@ai-sdk/openai-compatible` is used for any OpenAI-compatible API.
  290. - `name` is the display name for the provider in the UI.
  291. - `options.baseURL` is the endpoint for the local server.
  292. - `models` is a map of model IDs to their configurations. The model name will be displayed in the model selection list.
  293. ---
  294. ### Moonshot AI
  295. To use Kimi K2 from Moonshot AI:
  296. 1. Head over to the [Moonshot AI console](https://platform.moonshot.ai/console), create an account, and click **Create API key**.
  297. 2. Run `opencode auth login` and select **Moonshot AI**.
  298. ```bash
  299. $ opencode auth login
  300. ┌ Add credential
  301. ◆ Select provider
  302. │ ...
  303. │ ● Moonshot AI
  304. ```
  305. 3. Enter your Moonshot API key.
  306. ```bash
  307. $ opencode auth login
  308. ┌ Add credential
  309. ◇ Select provider
  310. │ Moonshot AI
  311. ◇ Enter your API key
  312. │ _
  313. ```
  314. 4. Run the `/models` command to select _Kimi K2_.
  315. ---
  316. ### Ollama
  317. You can configure opencode to use local models through Ollama.
  318. ```json title="opencode.json" "ollama" {5, 6, 8, 10-14}
  319. {
  320. "$schema": "https://opencode.ai/config.json",
  321. "provider": {
  322. "ollama": {
  323. "npm": "@ai-sdk/openai-compatible",
  324. "name": "Ollama (local)",
  325. "options": {
  326. "baseURL": "http://localhost:11434/v1"
  327. },
  328. "models": {
  329. "llama2": {
  330. "name": "Llama 2"
  331. }
  332. }
  333. }
  334. }
  335. }
  336. ```
  337. In this example:
  338. - `ollama` is the custom provider ID. This can be any string you want.
  339. - `npm` specifies the package to use for this provider. Here, `@ai-sdk/openai-compatible` is used for any OpenAI-compatible API.
  340. - `name` is the display name for the provider in the UI.
  341. - `options.baseURL` is the endpoint for the local server.
  342. - `models` is a map of model IDs to their configurations. The model name will be displayed in the model selection list.
  343. ---
  344. ### OpenAI
  345. 1. Head over to the [OpenAI Platform console](https://platform.openai.com/api-keys), click **Create new secret key**, and copy the key.
  346. 2. Run `opencode auth login` and select OpenAI.
  347. ```bash
  348. $ opencode auth login
  349. ┌ Add credential
  350. ◆ Select provider
  351. │ ● OpenAI
  352. │ ...
  353. ```
  354. 3. Enter the API key for the provider.
  355. ```bash
  356. $ opencode auth login
  357. ┌ Add credential
  358. ◇ Select provider
  359. │ OpenAI
  360. ◇ Enter your API key
  361. │ _
  362. ```
  363. 4. Run the `/models` command to select the one you want.
  364. ---
  365. ### OpenCode Zen
  366. OpenCode Zen is a list of tested and verified models provided by the OpenCode team. [Learn more](/docs/zen).
  367. 1. Sign in to **<a href={console}>OpenCode Zen</a>** and click **Create API Key**.
  368. 2. Run `opencode auth login` and select **OpenCode Zen**.
  369. ```bash
  370. $ opencode auth login
  371. ┌ Add credential
  372. ◆ Select provider
  373. │ ● OpenCode Zen
  374. │ ...
  375. ```
  376. 3. Enter your OpenCode API key.
  377. ```bash
  378. $ opencode auth login
  379. ┌ Add credential
  380. ◇ Select provider
  381. │ OpenCode Zen
  382. ◇ Enter your API key
  383. │ _
  384. ```
  385. 4. Run the `/models` command to select a model like _Qwen 3 Coder 480B_.
  386. ---
  387. ### OpenRouter
  388. 1. Head over to the [OpenRouter dashboard](https://openrouter.ai/settings/keys), click **Create API Key**, and copy the key.
  389. 2. Run `opencode auth login` and select OpenRouter.
  390. ```bash
  391. $ opencode auth login
  392. ┌ Add credential
  393. ◆ Select provider
  394. │ ● OpenRouter
  395. │ ○ Anthropic
  396. │ ○ Google
  397. │ ...
  398. ```
  399. 3. Enter the API key for the provider.
  400. ```bash
  401. $ opencode auth login
  402. ┌ Add credential
  403. ◇ Select provider
  404. │ OpenRouter
  405. ◇ Enter your API key
  406. │ _
  407. ```
  408. 4. Many OpenRouter models are preloaded by default, run the `/models` command to select the one you want.
  409. You can also add additional models through your opencode config.
  410. ```json title="opencode.json" {6}
  411. {
  412. "$schema": "https://opencode.ai/config.json",
  413. "provider": {
  414. "openrouter": {
  415. "models": {
  416. "somecoolnewmodel": {}
  417. }
  418. }
  419. }
  420. }
  421. ```
  422. 5. You can also customize them through your opencode config. Here's an example of specifying a provider
  423. ```json title="opencode.json"
  424. {
  425. "$schema": "https://opencode.ai/config.json",
  426. "provider": {
  427. "openrouter": {
  428. "models": {
  429. "moonshotai/kimi-k2": {
  430. "options": {
  431. "provider": {
  432. "order": ["baseten"],
  433. "allow_fallbacks": false
  434. }
  435. }
  436. }
  437. }
  438. }
  439. }
  440. }
  441. ```
  442. ---
  443. ### Together AI
  444. 1. Head over to the [Together AI console](https://api.together.ai), create an account, and click **Add Key**.
  445. 2. Run `opencode auth login` and select **Together AI**.
  446. ```bash
  447. $ opencode auth login
  448. ┌ Add credential
  449. ◆ Select provider
  450. │ ● Together AI
  451. │ ...
  452. ```
  453. 3. Enter your Together AI API key.
  454. ```bash
  455. $ opencode auth login
  456. ┌ Add credential
  457. ◇ Select provider
  458. │ Together AI
  459. ◇ Enter your API key
  460. │ _
  461. ```
  462. 4. Run the `/models` command to select a model like _Kimi K2 Instruct_.
  463. ---
  464. ### xAI
  465. For a limited time, you can use xAI's Grok Code for free with opencode.
  466. :::tip
  467. Grok Code is available for free for a limited time on opencode.
  468. :::
  469. 1. Make sure you are on the latest version of opencode.
  470. 2. Run the `/models` command and select **Grok Code Free**.
  471. As a part of the trial period, the xAI team will be using the request logs to
  472. monitor and improve Grok Code.
  473. ---
  474. ### Z.AI
  475. 1. Head over to the [Z.AI API console](https://z.ai/manage-apikey/apikey-list), create an account, and click **Create a new API key**.
  476. 2. Run `opencode auth login` and select **Z.AI**.
  477. ```bash
  478. $ opencode auth login
  479. ┌ Add credential
  480. ◆ Select provider
  481. │ ● Z.AI
  482. │ ...
  483. ```
  484. If you are subscribed to the **GLM Coding Plan**, select **Z.AI Coding Plan**.
  485. ```bash
  486. $ opencode auth login
  487. ┌ Add credential
  488. ◆ Select provider
  489. │ ● Z.AI Coding Plan
  490. │ ...
  491. ```
  492. 3. Enter your Z.AI API key.
  493. ```bash
  494. $ opencode auth login
  495. ┌ Add credential
  496. ◇ Select provider
  497. │ Z.AI
  498. ◇ Enter your API key
  499. │ _
  500. ```
  501. 4. Run the `/models` command to select a model like _GLM-4.5_.
  502. ---
  503. ## Custom provider
  504. To add any **OpenAI-compatible** provider that's not listed in `opencode auth login`:
  505. :::tip
  506. You can use any OpenAI-compatible provider with opencode. Most modern AI providers offer OpenAI-compatible APIs.
  507. :::
  508. 1. Run `opencode auth login` and scroll down to **Other**.
  509. ```bash
  510. $ opencode auth login
  511. ┌ Add credential
  512. ◆ Select provider
  513. │ ...
  514. │ ● Other
  515. ```
  516. 2. Enter a unique ID for the provider.
  517. ```bash
  518. $ opencode auth login
  519. ┌ Add credential
  520. ◇ Enter provider id
  521. │ myprovider
  522. ```
  523. :::note
  524. Choose a memorable ID, you'll use this in your config file.
  525. :::
  526. 3. Enter your API key for the provider.
  527. ```bash
  528. $ opencode auth login
  529. ┌ Add credential
  530. ▲ This only stores a credential for myprovider - you will need configure it in opencode.json, check the docs for examples.
  531. ◇ Enter your API key
  532. │ sk-...
  533. ```
  534. 4. Create or update your `opencode.json` file in your project directory:
  535. ```json title="opencode.json" ""myprovider"" {5-15}
  536. {
  537. "$schema": "https://opencode.ai/config.json",
  538. "provider": {
  539. "myprovider": {
  540. "npm": "@ai-sdk/openai-compatible",
  541. "name": "My AI ProviderDisplay Name",
  542. "options": {
  543. "baseURL": "https://api.myprovider.com/v1"
  544. },
  545. "models": {
  546. "my-model-name": {
  547. "name": "My Model Display Name"
  548. }
  549. }
  550. }
  551. }
  552. }
  553. ```
  554. Here are the configuration options:
  555. - **npm**: AI SDK package to use, `@ai-sdk/openai-compatible` for OpenAI-compatible providers
  556. - **name**: Display name in UI.
  557. - **models**: Available models.
  558. - **options.baseURL**: API endpoint URL.
  559. - **options.apiKey**: Optionally set the API key, if not using auth.
  560. - **options.headers**: Optionally set custom headers.
  561. More on the advanced options in the example below.
  562. 5. Run the `/models` command and your custom provider and models will appear in the selection list.
  563. ---
  564. ##### Example
  565. Here's an example setting the `apiKey` and `headers` options.
  566. ```json title="opencode.json" {9,11}
  567. {
  568. "$schema": "https://opencode.ai/config.json",
  569. "provider": {
  570. "myprovider": {
  571. "npm": "@ai-sdk/openai-compatible",
  572. "name": "My AI ProviderDisplay Name",
  573. "options": {
  574. "baseURL": "https://api.myprovider.com/v1",
  575. "apiKey": "{env:ANTHROPIC_API_KEY}",
  576. "headers": {
  577. "Authorization": "Bearer custom-token"
  578. }
  579. },
  580. "models": {
  581. "my-model-name": {
  582. "name": "My Model Display Name"
  583. }
  584. }
  585. }
  586. }
  587. }
  588. ```
  589. We are setting the `apiKey` using the `env` variable syntax, [learn more](/docs/config#env-vars).
  590. ---
  591. ## Troubleshooting
  592. If you are having trouble with configuring a provider, check the following:
  593. 1. **Check the auth setup**: Run `opencode auth list` to see if the credentials
  594. for the provider are added to your config.
  595. This doesn't apply to providers like Amazon Bedrock, that rely on environment variables for their auth.
  596. 2. For custom providers, check the opencode config and:
  597. - Make sure the provider ID used in `opencode auth login` matches the ID in your opencode config.
  598. - The right npm package is used for the provider. For example, use `@ai-sdk/cerebras` for Cerebras. And for all other OpenAI-compatible providers, use `@ai-sdk/openai-compatible`.
  599. - Check correct API endpoint is used in the `options.baseURL` field.