providers.mdx 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207
  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 **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 the `/connect` command.
  10. 2. Configure the provider in your OpenCode config.
  11. ---
  12. ### Credentials
  13. When you add a provider's API keys with the `/connect` command, 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 the `/connect` command in the TUI, select `OpenCode Zen`, and head to [opencode.ai/auth](https://opencode.ai/zen).
  42. ```txt
  43. /connect
  44. ```
  45. 2. Sign in, add your billing details, and copy your API key.
  46. 3. Paste your API key.
  47. ```txt
  48. ┌ API key
  49. │
  50. │
  51. └ enter
  52. ```
  53. 4. Run `/models` in the TUI to see the list of models we recommend.
  54. ```txt
  55. /models
  56. ```
  57. It works like any other provider in OpenCode and is completely optional to use.
  58. ---
  59. ## OpenCode Go
  60. OpenCode Go is a low cost subscription plan that provides reliable access to popular open coding models provided by the OpenCode team that have been
  61. tested and verified to work well with OpenCode.
  62. 1. Run the `/connect` command in the TUI, select `OpenCode Go`, and head to [opencode.ai/auth](https://opencode.ai/zen).
  63. ```txt
  64. /connect
  65. ```
  66. 2. Sign in, add your billing details, and copy your API key.
  67. 3. Paste your API key.
  68. ```txt
  69. ┌ API key
  70. │
  71. │
  72. └ enter
  73. ```
  74. 4. Run `/models` in the TUI to see the list of models we recommend.
  75. ```txt
  76. /models
  77. ```
  78. It works like any other provider in OpenCode and is completely optional to use.
  79. ---
  80. ## Directory
  81. Let's look at some of the providers in detail. If you'd like to add a provider to the
  82. list, feel free to open a PR.
  83. :::note
  84. Don't see a provider here? Submit a PR.
  85. :::
  86. ---
  87. ### 302.AI
  88. 1. Head over to the [302.AI console](https://302.ai/), create an account, and generate an API key.
  89. 2. Run the `/connect` command and search for **302.AI**.
  90. ```txt
  91. /connect
  92. ```
  93. 3. Enter your 302.AI API key.
  94. ```txt
  95. ┌ API key
  96. │
  97. │
  98. └ enter
  99. ```
  100. 4. Run the `/models` command to select a model.
  101. ```txt
  102. /models
  103. ```
  104. ---
  105. ### Amazon Bedrock
  106. To use Amazon Bedrock with OpenCode:
  107. 1. Head over to the **Model catalog** in the Amazon Bedrock console and request
  108. access to the models you want.
  109. :::tip
  110. You need to have access to the model you want in Amazon Bedrock.
  111. :::
  112. 2. **Configure authentication** using one of the following methods:
  113. ***
  114. #### Environment Variables (Quick Start)
  115. Set one of these environment variables while running opencode:
  116. ```bash
  117. # Option 1: Using AWS access keys
  118. AWS_ACCESS_KEY_ID=XXX AWS_SECRET_ACCESS_KEY=YYY opencode
  119. # Option 2: Using named AWS profile
  120. AWS_PROFILE=my-profile opencode
  121. # Option 3: Using Bedrock bearer token
  122. AWS_BEARER_TOKEN_BEDROCK=XXX opencode
  123. ```
  124. Or add them to your bash profile:
  125. ```bash title="~/.bash_profile"
  126. export AWS_PROFILE=my-dev-profile
  127. export AWS_REGION=us-east-1
  128. ```
  129. ***
  130. #### Configuration File (Recommended)
  131. For project-specific or persistent configuration, use `opencode.json`:
  132. ```json title="opencode.json"
  133. {
  134. "$schema": "https://opencode.ai/config.json",
  135. "provider": {
  136. "amazon-bedrock": {
  137. "options": {
  138. "region": "us-east-1",
  139. "profile": "my-aws-profile"
  140. }
  141. }
  142. }
  143. }
  144. ```
  145. **Available options:**
  146. - `region` - AWS region (e.g., `us-east-1`, `eu-west-1`)
  147. - `profile` - AWS named profile from `~/.aws/credentials`
  148. - `endpoint` - Custom endpoint URL for VPC endpoints (alias for generic `baseURL` option)
  149. :::tip
  150. Configuration file options take precedence over environment variables.
  151. :::
  152. ***
  153. #### Advanced: VPC Endpoints
  154. If you're using VPC endpoints for Bedrock:
  155. ```json title="opencode.json"
  156. {
  157. "$schema": "https://opencode.ai/config.json",
  158. "provider": {
  159. "amazon-bedrock": {
  160. "options": {
  161. "region": "us-east-1",
  162. "profile": "production",
  163. "endpoint": "https://bedrock-runtime.us-east-1.vpce-xxxxx.amazonaws.com"
  164. }
  165. }
  166. }
  167. }
  168. ```
  169. :::note
  170. The `endpoint` option is an alias for the generic `baseURL` option, using AWS-specific terminology. If both `endpoint` and `baseURL` are specified, `endpoint` takes precedence.
  171. :::
  172. ***
  173. #### Authentication Methods
  174. - **`AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY`**: Create an IAM user and generate access keys in the AWS Console
  175. - **`AWS_PROFILE`**: Use named profiles from `~/.aws/credentials`. First configure with `aws configure --profile my-profile` or `aws sso login`
  176. - **`AWS_BEARER_TOKEN_BEDROCK`**: Generate long-term API keys from the Amazon Bedrock console
  177. - **`AWS_WEB_IDENTITY_TOKEN_FILE` / `AWS_ROLE_ARN`**: For EKS IRSA (IAM Roles for Service Accounts) or other Kubernetes environments with OIDC federation. These environment variables are automatically injected by Kubernetes when using service account annotations.
  178. ***
  179. #### Authentication Precedence
  180. Amazon Bedrock uses the following authentication priority:
  181. 1. **Bearer Token** - `AWS_BEARER_TOKEN_BEDROCK` environment variable or token from `/connect` command
  182. 2. **AWS Credential Chain** - Profile, access keys, shared credentials, IAM roles, Web Identity Tokens (EKS IRSA), instance metadata
  183. :::note
  184. When a bearer token is set (via `/connect` or `AWS_BEARER_TOKEN_BEDROCK`), it takes precedence over all AWS credential methods including configured profiles.
  185. :::
  186. 3. Run the `/models` command to select the model you want.
  187. ```txt
  188. /models
  189. ```
  190. :::note
  191. For custom inference profiles, use the model and provider name in the key and set the `id` property to the arn. This ensures correct caching.
  192. :::
  193. ```json title="opencode.json"
  194. {
  195. "$schema": "https://opencode.ai/config.json",
  196. "provider": {
  197. "amazon-bedrock": {
  198. // ...
  199. "models": {
  200. "anthropic-claude-sonnet-4.5": {
  201. "id": "arn:aws:bedrock:us-east-1:xxx:application-inference-profile/yyy"
  202. }
  203. }
  204. }
  205. }
  206. }
  207. ```
  208. ---
  209. ### Anthropic
  210. 1. Once you've signed up, run the `/connect` command and select Anthropic.
  211. ```txt
  212. /connect
  213. ```
  214. 2. Here you can select the **Claude Pro/Max** option and it'll open your browser
  215. and ask you to authenticate.
  216. ```txt
  217. ┌ Select auth method
  218. │
  219. │ Manually enter API Key
  220. └
  221. ```
  222. 3. Now all the Anthropic models should be available when you use the `/models` command.
  223. ```txt
  224. /models
  225. ```
  226. :::info
  227. There are plugins that allow you to use your Claude Pro/Max models with
  228. OpenCode. Anthropic explicitly prohibits this.
  229. Previous versions of OpenCode came bundled with these plugins but that is no
  230. longer the case as of 1.3.0
  231. Other companies support freedom of choice with developer tooling - you can use
  232. the following subscriptions in OpenCode with zero setup:
  233. - ChatGPT Plus
  234. - Github Copilot
  235. - Gitlab Duo
  236. :::
  237. ---
  238. ### Atomic Chat
  239. You can configure opencode to use local models through [Atomic Chat](https://atomic.chat), a desktop application that runs local LLMs behind an OpenAI-compatible API server (default endpoint `http://127.0.0.1:1337/v1`).
  240. ```json title="opencode.json" "atomic-chat" {5, 6, 8, 10-14}
  241. {
  242. "$schema": "https://opencode.ai/config.json",
  243. "provider": {
  244. "atomic-chat": {
  245. "npm": "@ai-sdk/openai-compatible",
  246. "name": "Atomic Chat (local)",
  247. "options": {
  248. "baseURL": "http://127.0.0.1:1337/v1"
  249. },
  250. "models": {
  251. "<your-model-id>": {
  252. "name": "<your-model-name>"
  253. }
  254. }
  255. }
  256. }
  257. }
  258. ```
  259. In this example:
  260. - `atomic-chat` is the custom provider ID. This can be any string you want.
  261. - `npm` specifies the package to use for this provider. Here, `@ai-sdk/openai-compatible` is used for any OpenAI-compatible API.
  262. - `name` is the display name for the provider in the UI.
  263. - `options.baseURL` is the endpoint for the local server. Change the host and port to match your Atomic Chat setup.
  264. - `models` is a map of model IDs to their display names. Each ID must match the `id` returned by `GET /v1/models` — run `curl http://127.0.0.1:1337/v1/models` to list the ids currently loaded in Atomic Chat.
  265. :::tip
  266. If tool calls aren't working well, pick a loaded model with strong tool-calling support (for example, a Qwen-Coder or DeepSeek-Coder variant).
  267. :::
  268. ---
  269. ### Azure OpenAI
  270. :::note
  271. If you encounter "I'm sorry, but I cannot assist with that request" errors, try changing the content filter from **DefaultV2** to **Default** in your Azure resource.
  272. :::
  273. 1. Head over to the [Azure portal](https://portal.azure.com/) and create an **Azure OpenAI** resource. You'll need:
  274. - **Resource name**: This becomes part of your API endpoint (`https://RESOURCE_NAME.openai.azure.com/`)
  275. - **API key**: Either `KEY 1` or `KEY 2` from your resource
  276. 2. Go to [Azure AI Foundry](https://ai.azure.com/) and deploy a model.
  277. :::note
  278. The deployment name must match the model name for opencode to work properly.
  279. :::
  280. 3. Run the `/connect` command and search for **Azure**.
  281. ```txt
  282. /connect
  283. ```
  284. 4. Enter your API key.
  285. ```txt
  286. ┌ API key
  287. │
  288. │
  289. └ enter
  290. ```
  291. 5. Set your resource name as an environment variable:
  292. ```bash
  293. AZURE_RESOURCE_NAME=XXX opencode
  294. ```
  295. Or add it to your bash profile:
  296. ```bash title="~/.bash_profile"
  297. export AZURE_RESOURCE_NAME=XXX
  298. ```
  299. 6. Run the `/models` command to select your deployed model.
  300. ```txt
  301. /models
  302. ```
  303. ---
  304. ### Azure Cognitive Services
  305. 1. Head over to the [Azure portal](https://portal.azure.com/) and create an **Azure OpenAI** resource. You'll need:
  306. - **Resource name**: This becomes part of your API endpoint (`https://AZURE_COGNITIVE_SERVICES_RESOURCE_NAME.cognitiveservices.azure.com/`)
  307. - **API key**: Either `KEY 1` or `KEY 2` from your resource
  308. 2. Go to [Azure AI Foundry](https://ai.azure.com/) and deploy a model.
  309. :::note
  310. The deployment name must match the model name for opencode to work properly.
  311. :::
  312. 3. Run the `/connect` command and search for **Azure Cognitive Services**.
  313. ```txt
  314. /connect
  315. ```
  316. 4. Enter your API key.
  317. ```txt
  318. ┌ API key
  319. │
  320. │
  321. └ enter
  322. ```
  323. 5. Set your resource name as an environment variable:
  324. ```bash
  325. AZURE_COGNITIVE_SERVICES_RESOURCE_NAME=XXX opencode
  326. ```
  327. Or add it to your bash profile:
  328. ```bash title="~/.bash_profile"
  329. export AZURE_COGNITIVE_SERVICES_RESOURCE_NAME=XXX
  330. ```
  331. 6. Run the `/models` command to select your deployed model.
  332. ```txt
  333. /models
  334. ```
  335. ---
  336. ### Baseten
  337. 1. Head over to the [Baseten](https://app.baseten.co/), create an account, and generate an API key.
  338. 2. Run the `/connect` command and search for **Baseten**.
  339. ```txt
  340. /connect
  341. ```
  342. 3. Enter your Baseten API key.
  343. ```txt
  344. ┌ API key
  345. │
  346. │
  347. └ enter
  348. ```
  349. 4. Run the `/models` command to select a model.
  350. ```txt
  351. /models
  352. ```
  353. ---
  354. ### Cerebras
  355. 1. Head over to the [Cerebras console](https://inference.cerebras.ai/), create an account, and generate an API key.
  356. 2. Run the `/connect` command and search for **Cerebras**.
  357. ```txt
  358. /connect
  359. ```
  360. 3. Enter your Cerebras API key.
  361. ```txt
  362. ┌ API key
  363. │
  364. │
  365. └ enter
  366. ```
  367. 4. Run the `/models` command to select a model like _Qwen 3 Coder 480B_.
  368. ```txt
  369. /models
  370. ```
  371. ---
  372. ### Cloudflare AI Gateway
  373. Cloudflare AI Gateway lets you access models from OpenAI, Anthropic, Workers AI, and more through a unified endpoint. With [Unified Billing](https://developers.cloudflare.com/ai-gateway/features/unified-billing/) you don't need separate API keys for each provider.
  374. 1. Head over to the [Cloudflare dashboard](https://dash.cloudflare.com/), navigate to **AI** > **AI Gateway**, and create a new gateway. Note your **Account ID** and **Gateway ID**.
  375. 2. Run the `/connect` command and search for **Cloudflare AI Gateway**.
  376. ```txt
  377. /connect
  378. ```
  379. 3. Enter your **Account ID** when prompted.
  380. ```txt
  381. ┌ Enter your Cloudflare Account ID
  382. │
  383. │
  384. └ enter
  385. ```
  386. 4. Enter your **Gateway ID** when prompted.
  387. ```txt
  388. ┌ Enter your Cloudflare AI Gateway ID
  389. │
  390. │
  391. └ enter
  392. ```
  393. 5. Enter your **Cloudflare API token**.
  394. ```txt
  395. ┌ Gateway API token
  396. │
  397. │
  398. └ enter
  399. ```
  400. 6. Run the `/models` command to select a model.
  401. ```txt
  402. /models
  403. ```
  404. You can also add models through your opencode config.
  405. ```json title="opencode.json"
  406. {
  407. "$schema": "https://opencode.ai/config.json",
  408. "provider": {
  409. "cloudflare-ai-gateway": {
  410. "models": {
  411. "openai/gpt-4o": {},
  412. "anthropic/claude-sonnet-4": {}
  413. }
  414. }
  415. }
  416. }
  417. ```
  418. Alternatively, you can set environment variables instead of using `/connect`.
  419. ```bash title="~/.bash_profile"
  420. export CLOUDFLARE_ACCOUNT_ID=your-32-character-account-id
  421. export CLOUDFLARE_GATEWAY_ID=your-gateway-id
  422. export CLOUDFLARE_API_TOKEN=your-api-token
  423. ```
  424. ---
  425. ### Cloudflare Workers AI
  426. Cloudflare Workers AI lets you run AI models on Cloudflare's global network directly via REST API, with no separate provider accounts needed for supported models.
  427. 1. Head over to the [Cloudflare dashboard](https://dash.cloudflare.com/), navigate to **Workers AI**, and select **Use REST API** to get your **Account ID** and create an API token.
  428. 2. Run the `/connect` command and search for **Cloudflare Workers AI**.
  429. ```txt
  430. /connect
  431. ```
  432. 3. Enter your **Account ID** when prompted.
  433. ```txt
  434. ┌ Enter your Cloudflare Account ID
  435. │
  436. │
  437. └ enter
  438. ```
  439. 4. Enter your **Cloudflare API key**.
  440. ```txt
  441. ┌ API key
  442. │
  443. │
  444. └ enter
  445. ```
  446. 5. Run the `/models` command to select a model.
  447. ```txt
  448. /models
  449. ```
  450. Alternatively, you can set environment variables instead of using `/connect`.
  451. ```bash title="~/.bash_profile"
  452. export CLOUDFLARE_ACCOUNT_ID=your-32-character-account-id
  453. export CLOUDFLARE_API_KEY=your-api-token
  454. ```
  455. ---
  456. ### Cortecs
  457. 1. Head over to the [Cortecs console](https://cortecs.ai/), create an account, and generate an API key.
  458. 2. Run the `/connect` command and search for **Cortecs**.
  459. ```txt
  460. /connect
  461. ```
  462. 3. Enter your Cortecs API key.
  463. ```txt
  464. ┌ API key
  465. │
  466. │
  467. └ enter
  468. ```
  469. 4. Run the `/models` command to select a model like _Kimi K2 Instruct_.
  470. ```txt
  471. /models
  472. ```
  473. ---
  474. ### DeepSeek
  475. 1. Head over to the [DeepSeek console](https://platform.deepseek.com/), create an account, and click **Create new API key**.
  476. 2. Run the `/connect` command and search for **DeepSeek**.
  477. ```txt
  478. /connect
  479. ```
  480. 3. Enter your DeepSeek API key.
  481. ```txt
  482. ┌ API key
  483. │
  484. │
  485. └ enter
  486. ```
  487. 4. Run the `/models` command to select a DeepSeek model like _DeepSeek V4 Pro_.
  488. ```txt
  489. /models
  490. ```
  491. ---
  492. ### Deep Infra
  493. 1. Head over to the [Deep Infra dashboard](https://deepinfra.com/dash), create an account, and generate an API key.
  494. 2. Run the `/connect` command and search for **Deep Infra**.
  495. ```txt
  496. /connect
  497. ```
  498. 3. Enter your Deep Infra API key.
  499. ```txt
  500. ┌ API key
  501. │
  502. │
  503. └ enter
  504. ```
  505. 4. Run the `/models` command to select a model.
  506. ```txt
  507. /models
  508. ```
  509. ---
  510. ### Firmware
  511. 1. Head over to the [Firmware dashboard](https://app.firmware.ai/signup), create an account, and generate an API key.
  512. 2. Run the `/connect` command and search for **Firmware**.
  513. ```txt
  514. /connect
  515. ```
  516. 3. Enter your Firmware API key.
  517. ```txt
  518. ┌ API key
  519. │
  520. │
  521. └ enter
  522. ```
  523. 4. Run the `/models` command to select a model.
  524. ```txt
  525. /models
  526. ```
  527. ---
  528. ### Fireworks AI
  529. 1. Head over to the [Fireworks AI console](https://app.fireworks.ai/), create an account, and click **Create API Key**.
  530. 2. Run the `/connect` command and search for **Fireworks AI**.
  531. ```txt
  532. /connect
  533. ```
  534. 3. Enter your Fireworks AI API key.
  535. ```txt
  536. ┌ API key
  537. │
  538. │
  539. └ enter
  540. ```
  541. 4. Run the `/models` command to select a model like _Kimi K2 Instruct_.
  542. ```txt
  543. /models
  544. ```
  545. ---
  546. ### GitLab Duo
  547. :::caution[Experimental]
  548. GitLab Duo support in OpenCode is experimental. Features, configuration, and
  549. behavior may change in future releases.
  550. :::
  551. OpenCode integrates with the [GitLab Duo Agent Platform](https://docs.gitlab.com/user/duo_agent_platform/),
  552. providing AI-powered agentic chat with native tool calling capabilities.
  553. :::note[License requirements]
  554. GitLab Duo Agent Platform requires a **Premium** or **Ultimate** GitLab
  555. subscription. It is available on GitLab.com and GitLab Self-Managed.
  556. See [GitLab Duo Agent Platform prerequisites](https://docs.gitlab.com/user/duo_agent_platform/#prerequisites)
  557. for full requirements.
  558. :::
  559. 1. Run the `/connect` command and select GitLab.
  560. ```txt
  561. /connect
  562. ```
  563. 2. Choose your authentication method:
  564. ```txt
  565. ┌ Select auth method
  566. │
  567. │ OAuth (Recommended)
  568. │ Personal Access Token
  569. └
  570. ```
  571. #### Using OAuth (Recommended)
  572. Select **OAuth** and your browser will open for authorization.
  573. #### Using Personal Access Token
  574. 1. Go to [GitLab User Settings > Access Tokens](https://gitlab.com/-/user_settings/personal_access_tokens)
  575. 2. Click **Add new token**
  576. 3. Name: `OpenCode`, Scopes: `api`
  577. 4. Copy the token (starts with `glpat-`)
  578. 5. Enter it in the terminal
  579. 3. Run the `/models` command to see available models.
  580. ```txt
  581. /models
  582. ```
  583. Three Claude-based models are available:
  584. - **duo-chat-haiku-4-5** (Default) - Fast responses for quick tasks
  585. - **duo-chat-sonnet-4-5** - Balanced performance for most workflows
  586. - **duo-chat-opus-4-5** - Most capable for complex analysis
  587. :::note
  588. You can also specify 'GITLAB_TOKEN' environment variable if you don't want
  589. to store token in opencode auth storage.
  590. :::
  591. ##### Self-Hosted GitLab
  592. :::note[compliance note]
  593. OpenCode uses a small model for some AI tasks like generating the session title.
  594. It is configured to use gpt-5-nano by default, hosted by Zen. To lock OpenCode
  595. to only use your own GitLab-hosted instance, add the following to your
  596. `opencode.json` file. It is also recommended to disable session sharing.
  597. ```json
  598. {
  599. "$schema": "https://opencode.ai/config.json",
  600. "small_model": "gitlab/duo-chat-haiku-4-5",
  601. "share": "disabled"
  602. }
  603. ```
  604. :::
  605. For self-hosted GitLab instances:
  606. ```bash
  607. export GITLAB_INSTANCE_URL=https://gitlab.company.com
  608. export GITLAB_TOKEN=glpat-...
  609. ```
  610. If your instance runs a custom AI Gateway:
  611. ```bash
  612. GITLAB_AI_GATEWAY_URL=https://ai-gateway.company.com
  613. ```
  614. Or add to your bash profile:
  615. ```bash title="~/.bash_profile"
  616. export GITLAB_INSTANCE_URL=https://gitlab.company.com
  617. export GITLAB_AI_GATEWAY_URL=https://ai-gateway.company.com
  618. export GITLAB_TOKEN=glpat-...
  619. ```
  620. :::note
  621. Your GitLab administrator must:
  622. 1. [Turn on GitLab Duo](https://docs.gitlab.com/user/duo_agent_platform/turn_on_off/#turn-gitlab-duo-on-or-off)
  623. for the user, group, or instance
  624. 2. [Turn on the Agent Platform](https://docs.gitlab.com/user/duo_agent_platform/turn_on_off/#turn-gitlab-duo-agent-platform-on-or-off)
  625. (GitLab 18.8+) or [enable beta and experimental features](https://docs.gitlab.com/user/duo_agent_platform/turn_on_off/#turn-on-beta-and-experimental-features)
  626. (GitLab 18.7 and earlier)
  627. 3. For Self-Managed, [configure your instance](https://docs.gitlab.com/administration/gitlab_duo/configure/gitlab_self_managed/)
  628. :::
  629. ##### OAuth for Self-Hosted instances
  630. In order to make Oauth working for your self-hosted instance, you need to create
  631. a new application (Settings → Applications) with the
  632. callback URL `http://127.0.0.1:8080/callback` and following scopes:
  633. - api (Access the API on your behalf)
  634. - read_user (Read your personal information)
  635. - read_repository (Allows read-only access to the repository)
  636. Then expose application ID as environment variable:
  637. ```bash
  638. export GITLAB_OAUTH_CLIENT_ID=your_application_id_here
  639. ```
  640. More documentation on [opencode-gitlab-auth](https://www.npmjs.com/package/opencode-gitlab-auth) homepage.
  641. ##### Configuration
  642. Customize through `opencode.json`:
  643. ```json title="opencode.json"
  644. {
  645. "$schema": "https://opencode.ai/config.json",
  646. "provider": {
  647. "gitlab": {
  648. "options": {
  649. "instanceUrl": "https://gitlab.com"
  650. }
  651. }
  652. }
  653. }
  654. ```
  655. ##### GitLab Duo Agent Platform (DAP) Workflow Models
  656. DAP workflow models provide an alternative execution path that routes tool calls
  657. through GitLab's Duo Workflow Service (DWS) instead of the standard agentic chat.
  658. When a `duo-workflow-*` model is selected, OpenCode will:
  659. 1. Discover available models from your GitLab namespace
  660. 2. Present a selection picker if multiple models are available
  661. 3. Cache the selected model to disk for fast subsequent startups
  662. 4. Route tool execution requests through OpenCode's permission-gated tool system
  663. Available DAP workflow models follow the `duo-workflow-*` naming convention and
  664. are dynamically discovered from your GitLab instance.
  665. ##### GitLab API Tools (Optional, but highly recommended)
  666. To access GitLab tools (merge requests, issues, pipelines, CI/CD, etc.):
  667. ```json title="opencode.json"
  668. {
  669. "$schema": "https://opencode.ai/config.json",
  670. "plugin": ["opencode-gitlab-plugin"]
  671. }
  672. ```
  673. This plugin provides comprehensive GitLab repository management capabilities including MR reviews, issue tracking, pipeline monitoring, and more.
  674. ---
  675. ### GitHub Copilot
  676. To use your GitHub Copilot subscription with opencode:
  677. :::note
  678. Some models might need a [Pro+
  679. subscription](https://github.com/features/copilot/plans) to use.
  680. :::
  681. 1. Run the `/connect` command and search for GitHub Copilot.
  682. ```txt
  683. /connect
  684. ```
  685. 2. Navigate to [github.com/login/device](https://github.com/login/device) and enter the code.
  686. ```txt
  687. ┌ Login with GitHub Copilot
  688. │
  689. │ https://github.com/login/device
  690. │
  691. │ Enter code: 8F43-6FCF
  692. │
  693. └ Waiting for authorization...
  694. ```
  695. 3. Now run the `/models` command to select the model you want.
  696. ```txt
  697. /models
  698. ```
  699. ---
  700. ### Google Vertex AI
  701. To use Google Vertex AI with OpenCode:
  702. 1. Head over to the **Model Garden** in the Google Cloud Console and check the
  703. models available in your region.
  704. :::note
  705. You need to have a Google Cloud project with Vertex AI API enabled.
  706. :::
  707. 2. Set the required environment variables:
  708. - `GOOGLE_CLOUD_PROJECT`: Your Google Cloud project ID
  709. - `VERTEX_LOCATION` (optional): The region for Vertex AI (defaults to `global`)
  710. - Authentication (choose one):
  711. - `GOOGLE_APPLICATION_CREDENTIALS`: Path to your service account JSON key file
  712. - Authenticate using gcloud CLI: `gcloud auth application-default login`
  713. Set them while running opencode.
  714. ```bash
  715. GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json GOOGLE_CLOUD_PROJECT=your-project-id opencode
  716. ```
  717. Or add them to your bash profile.
  718. ```bash title="~/.bash_profile"
  719. export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
  720. export GOOGLE_CLOUD_PROJECT=your-project-id
  721. export VERTEX_LOCATION=global
  722. ```
  723. :::tip
  724. The `global` region improves availability and reduces errors at no extra cost. Use regional endpoints (e.g., `us-central1`) for data residency requirements. [Learn more](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-partner-models#regional_and_global_endpoints)
  725. :::
  726. 3. Run the `/models` command to select the model you want.
  727. ```txt
  728. /models
  729. ```
  730. ---
  731. ### Groq
  732. 1. Head over to the [Groq console](https://console.groq.com/), click **Create API Key**, and copy the key.
  733. 2. Run the `/connect` command and search for Groq.
  734. ```txt
  735. /connect
  736. ```
  737. 3. Enter the API key for the provider.
  738. ```txt
  739. ┌ API key
  740. │
  741. │
  742. └ enter
  743. ```
  744. 4. Run the `/models` command to select the one you want.
  745. ```txt
  746. /models
  747. ```
  748. ---
  749. ### Hugging Face
  750. [Hugging Face Inference Providers](https://huggingface.co/docs/inference-providers) provides access to open models supported by 17+ providers.
  751. 1. Head over to [Hugging Face settings](https://huggingface.co/settings/tokens/new?ownUserPermissions=inference.serverless.write&tokenType=fineGrained) to create a token with permission to make calls to Inference Providers.
  752. 2. Run the `/connect` command and search for **Hugging Face**.
  753. ```txt
  754. /connect
  755. ```
  756. 3. Enter your Hugging Face token.
  757. ```txt
  758. ┌ API key
  759. │
  760. │
  761. └ enter
  762. ```
  763. 4. Run the `/models` command to select a model like _Kimi-K2-Instruct_ or _GLM-4.6_.
  764. ```txt
  765. /models
  766. ```
  767. ---
  768. ### Helicone
  769. [Helicone](https://helicone.ai) is an LLM observability platform that provides logging, monitoring, and analytics for your AI applications. The Helicone AI Gateway routes your requests to the appropriate provider automatically based on the model.
  770. 1. Head over to [Helicone](https://helicone.ai), create an account, and generate an API key from your dashboard.
  771. 2. Run the `/connect` command and search for **Helicone**.
  772. ```txt
  773. /connect
  774. ```
  775. 3. Enter your Helicone API key.
  776. ```txt
  777. ┌ API key
  778. │
  779. │
  780. └ enter
  781. ```
  782. 4. Run the `/models` command to select a model.
  783. ```txt
  784. /models
  785. ```
  786. For more providers and advanced features like caching and rate limiting, check the [Helicone documentation](https://docs.helicone.ai).
  787. #### Optional Configs
  788. In the event you see a feature or model from Helicone that isn't configured automatically through opencode, you can always configure it yourself.
  789. Here's [Helicone's Model Directory](https://helicone.ai/models), you'll need this to grab the IDs of the models you want to add.
  790. ```jsonc title="~/.config/opencode/opencode.jsonc"
  791. {
  792. "$schema": "https://opencode.ai/config.json",
  793. "provider": {
  794. "helicone": {
  795. "npm": "@ai-sdk/openai-compatible",
  796. "name": "Helicone",
  797. "options": {
  798. "baseURL": "https://ai-gateway.helicone.ai",
  799. },
  800. "models": {
  801. "gpt-4o": {
  802. // Model ID (from Helicone's model directory page)
  803. "name": "GPT-4o", // Your own custom name for the model
  804. },
  805. "claude-sonnet-4-20250514": {
  806. "name": "Claude Sonnet 4",
  807. },
  808. },
  809. },
  810. },
  811. }
  812. ```
  813. #### Custom Headers
  814. Helicone supports custom headers for features like caching, user tracking, and session management. Add them to your provider config using `options.headers`:
  815. ```jsonc title="~/.config/opencode/opencode.jsonc"
  816. {
  817. "$schema": "https://opencode.ai/config.json",
  818. "provider": {
  819. "helicone": {
  820. "npm": "@ai-sdk/openai-compatible",
  821. "name": "Helicone",
  822. "options": {
  823. "baseURL": "https://ai-gateway.helicone.ai",
  824. "headers": {
  825. "Helicone-Cache-Enabled": "true",
  826. "Helicone-User-Id": "opencode",
  827. },
  828. },
  829. },
  830. },
  831. }
  832. ```
  833. ##### Session tracking
  834. Helicone's [Sessions](https://docs.helicone.ai/features/sessions) feature lets you group related LLM requests together. Use the [opencode-helicone-session](https://github.com/H2Shami/opencode-helicone-session) plugin to automatically log each OpenCode conversation as a session in Helicone.
  835. ```bash
  836. npm install -g opencode-helicone-session
  837. ```
  838. Add it to your config.
  839. ```json title="opencode.json"
  840. {
  841. "plugin": ["opencode-helicone-session"]
  842. }
  843. ```
  844. The plugin injects `Helicone-Session-Id` and `Helicone-Session-Name` headers into your requests. In Helicone's Sessions page, you'll see each OpenCode conversation listed as a separate session.
  845. ##### Common Helicone headers
  846. | Header | Description |
  847. | -------------------------- | ------------------------------------------------------------- |
  848. | `Helicone-Cache-Enabled` | Enable response caching (`true`/`false`) |
  849. | `Helicone-User-Id` | Track metrics by user |
  850. | `Helicone-Property-[Name]` | Add custom properties (e.g., `Helicone-Property-Environment`) |
  851. | `Helicone-Prompt-Id` | Associate requests with prompt versions |
  852. See the [Helicone Header Directory](https://docs.helicone.ai/helicone-headers/header-directory) for all available headers.
  853. ---
  854. ### llama.cpp
  855. You can configure opencode to use local models through [llama.cpp's](https://github.com/ggml-org/llama.cpp) llama-server utility
  856. ```json title="opencode.json" "llama.cpp" {5, 6, 8, 10-15}
  857. {
  858. "$schema": "https://opencode.ai/config.json",
  859. "provider": {
  860. "llama.cpp": {
  861. "npm": "@ai-sdk/openai-compatible",
  862. "name": "llama-server (local)",
  863. "options": {
  864. "baseURL": "http://127.0.0.1:8080/v1"
  865. },
  866. "models": {
  867. "qwen3-coder:a3b": {
  868. "name": "Qwen3-Coder: a3b-30b (local)",
  869. "limit": {
  870. "context": 128000,
  871. "output": 65536
  872. }
  873. }
  874. }
  875. }
  876. }
  877. }
  878. ```
  879. In this example:
  880. - `llama.cpp` is the custom provider ID. This can be any string you want.
  881. - `npm` specifies the package to use for this provider. Here, `@ai-sdk/openai-compatible` is used for any OpenAI-compatible API.
  882. - `name` is the display name for the provider in the UI.
  883. - `options.baseURL` is the endpoint for the local server.
  884. - `models` is a map of model IDs to their configurations. The model name will be displayed in the model selection list.
  885. ---
  886. ### IO.NET
  887. IO.NET offers 17 models optimized for various use cases:
  888. 1. Head over to the [IO.NET console](https://ai.io.net/), create an account, and generate an API key.
  889. 2. Run the `/connect` command and search for **IO.NET**.
  890. ```txt
  891. /connect
  892. ```
  893. 3. Enter your IO.NET API key.
  894. ```txt
  895. ┌ API key
  896. │
  897. │
  898. └ enter
  899. ```
  900. 4. Run the `/models` command to select a model.
  901. ```txt
  902. /models
  903. ```
  904. ---
  905. ### LM Studio
  906. You can configure opencode to use local models through LM Studio.
  907. ```json title="opencode.json" "lmstudio" {5, 6, 8, 10-14}
  908. {
  909. "$schema": "https://opencode.ai/config.json",
  910. "provider": {
  911. "lmstudio": {
  912. "npm": "@ai-sdk/openai-compatible",
  913. "name": "LM Studio (local)",
  914. "options": {
  915. "baseURL": "http://127.0.0.1:1234/v1"
  916. },
  917. "models": {
  918. "google/gemma-3n-e4b": {
  919. "name": "Gemma 3n-e4b (local)"
  920. }
  921. }
  922. }
  923. }
  924. }
  925. ```
  926. In this example:
  927. - `lmstudio` is the custom provider ID. This can be any string you want.
  928. - `npm` specifies the package to use for this provider. Here, `@ai-sdk/openai-compatible` is used for any OpenAI-compatible API.
  929. - `name` is the display name for the provider in the UI.
  930. - `options.baseURL` is the endpoint for the local server.
  931. - `models` is a map of model IDs to their configurations. The model name will be displayed in the model selection list.
  932. ---
  933. ### Moonshot AI
  934. To use Kimi K2 from Moonshot AI:
  935. 1. Head over to the [Moonshot AI console](https://platform.moonshot.ai/console), create an account, and click **Create API key**.
  936. 2. Run the `/connect` command and search for **Moonshot AI**.
  937. ```txt
  938. /connect
  939. ```
  940. 3. Enter your Moonshot API key.
  941. ```txt
  942. ┌ API key
  943. │
  944. │
  945. └ enter
  946. ```
  947. 4. Run the `/models` command to select _Kimi K2_.
  948. ```txt
  949. /models
  950. ```
  951. ---
  952. ### MiniMax
  953. 1. Head over to the [MiniMax API Console](https://platform.minimax.io/login), create an account, and generate an API key.
  954. 2. Run the `/connect` command and search for **MiniMax**.
  955. ```txt
  956. /connect
  957. ```
  958. 3. Enter your MiniMax API key.
  959. ```txt
  960. ┌ API key
  961. │
  962. │
  963. └ enter
  964. ```
  965. 4. Run the `/models` command to select a model like _M2.1_.
  966. ```txt
  967. /models
  968. ```
  969. ---
  970. ### NVIDIA
  971. NVIDIA provides access to Nemotron models and many other open models through [build.nvidia.com](https://build.nvidia.com) for free.
  972. 1. Head over to [build.nvidia.com](https://build.nvidia.com), create an account, and generate an API key.
  973. 2. Run the `/connect` command and search for **NVIDIA**.
  974. ```txt
  975. /connect
  976. ```
  977. 3. Enter your NVIDIA API key.
  978. ```txt
  979. ┌ API key
  980. │
  981. │
  982. └ enter
  983. ```
  984. 4. Run the `/models` command to select a model like nemotron-3-super-120b-a12b.
  985. ```txt
  986. /models
  987. ```
  988. #### On-Prem / NIM
  989. You can also use NVIDIA models locally via [NVIDIA NIM](https://docs.nvidia.com/nim/) by setting a custom base URL.
  990. ```json title="opencode.json" {6}
  991. {
  992. "$schema": "https://opencode.ai/config.json",
  993. "provider": {
  994. "nvidia": {
  995. "options": {
  996. "baseURL": "http://localhost:8000/v1"
  997. }
  998. }
  999. }
  1000. }
  1001. ```
  1002. #### Environment Variable
  1003. Alternatively, set your API key as an environment variable.
  1004. ```bash frame="none"
  1005. export NVIDIA_API_KEY=nvapi-your-key-here
  1006. ```
  1007. ---
  1008. ### Nebius Token Factory
  1009. 1. Head over to the [Nebius Token Factory console](https://tokenfactory.nebius.com/), create an account, and click **Add Key**.
  1010. 2. Run the `/connect` command and search for **Nebius Token Factory**.
  1011. ```txt
  1012. /connect
  1013. ```
  1014. 3. Enter your Nebius Token Factory API key.
  1015. ```txt
  1016. ┌ API key
  1017. │
  1018. │
  1019. └ enter
  1020. ```
  1021. 4. Run the `/models` command to select a model like _Kimi K2 Instruct_.
  1022. ```txt
  1023. /models
  1024. ```
  1025. ---
  1026. ### Ollama
  1027. You can configure opencode to use local models through Ollama.
  1028. :::tip
  1029. Ollama can automatically configure itself for OpenCode. See the [Ollama integration docs](https://docs.ollama.com/integrations/opencode) for details.
  1030. :::
  1031. ```json title="opencode.json" "ollama" {5, 6, 8, 10-14}
  1032. {
  1033. "$schema": "https://opencode.ai/config.json",
  1034. "provider": {
  1035. "ollama": {
  1036. "npm": "@ai-sdk/openai-compatible",
  1037. "name": "Ollama (local)",
  1038. "options": {
  1039. "baseURL": "http://localhost:11434/v1"
  1040. },
  1041. "models": {
  1042. "llama2": {
  1043. "name": "Llama 2"
  1044. }
  1045. }
  1046. }
  1047. }
  1048. }
  1049. ```
  1050. In this example:
  1051. - `ollama` is the custom provider ID. This can be any string you want.
  1052. - `npm` specifies the package to use for this provider. Here, `@ai-sdk/openai-compatible` is used for any OpenAI-compatible API.
  1053. - `name` is the display name for the provider in the UI.
  1054. - `options.baseURL` is the endpoint for the local server.
  1055. - `models` is a map of model IDs to their configurations. The model name will be displayed in the model selection list.
  1056. :::tip
  1057. If tool calls aren't working, try increasing `num_ctx` in Ollama. Start around 16k - 32k.
  1058. :::
  1059. ---
  1060. ### Ollama Cloud
  1061. To use Ollama Cloud with OpenCode:
  1062. 1. Head over to [https://ollama.com/](https://ollama.com/) and sign in or create an account.
  1063. 2. Navigate to **Settings** > **Keys** and click **Add API Key** to generate a new API key.
  1064. 3. Copy the API key for use in OpenCode.
  1065. 4. Run the `/connect` command and search for **Ollama Cloud**.
  1066. ```txt
  1067. /connect
  1068. ```
  1069. 5. Enter your Ollama Cloud API key.
  1070. ```txt
  1071. ┌ API key
  1072. │
  1073. │
  1074. └ enter
  1075. ```
  1076. 6. **Important**: Before using cloud models in OpenCode, you must pull the model information locally:
  1077. ```bash
  1078. ollama pull gpt-oss:20b-cloud
  1079. ```
  1080. 7. Run the `/models` command to select your Ollama Cloud model.
  1081. ```txt
  1082. /models
  1083. ```
  1084. ---
  1085. ### OpenAI
  1086. We recommend signing up for [ChatGPT Plus or Pro](https://chatgpt.com/pricing).
  1087. 1. Once you've signed up, run the `/connect` command and select OpenAI.
  1088. ```txt
  1089. /connect
  1090. ```
  1091. 2. Here you can select the **ChatGPT Plus/Pro** option and it'll open your browser
  1092. and ask you to authenticate.
  1093. ```txt
  1094. ┌ Select auth method
  1095. │
  1096. │ ChatGPT Plus/Pro
  1097. │ Manually enter API Key
  1098. └
  1099. ```
  1100. 3. Now all the OpenAI models should be available when you use the `/models` command.
  1101. ```txt
  1102. /models
  1103. ```
  1104. ##### Using API keys
  1105. If you already have an API key, you can select **Manually enter API Key** and paste it in your terminal.
  1106. ---
  1107. ### OpenCode Zen
  1108. OpenCode Zen is a list of tested and verified models provided by the OpenCode team. [Learn more](/docs/zen).
  1109. 1. Sign in to **<a href={console}>OpenCode Zen</a>** and click **Create API Key**.
  1110. 2. Run the `/connect` command and search for **OpenCode Zen**.
  1111. ```txt
  1112. /connect
  1113. ```
  1114. 3. Enter your OpenCode API key.
  1115. ```txt
  1116. ┌ API key
  1117. │
  1118. │
  1119. └ enter
  1120. ```
  1121. 4. Run the `/models` command to select a model like _Qwen 3 Coder 480B_.
  1122. ```txt
  1123. /models
  1124. ```
  1125. ---
  1126. ### OpenRouter
  1127. 1. Head over to the [OpenRouter dashboard](https://openrouter.ai/settings/keys), click **Create API Key**, and copy the key.
  1128. 2. Run the `/connect` command and search for OpenRouter.
  1129. ```txt
  1130. /connect
  1131. ```
  1132. 3. Enter the API key for the provider.
  1133. ```txt
  1134. ┌ API key
  1135. │
  1136. │
  1137. └ enter
  1138. ```
  1139. 4. Many OpenRouter models are preloaded by default, run the `/models` command to select the one you want.
  1140. ```txt
  1141. /models
  1142. ```
  1143. You can also add additional models through your opencode config.
  1144. ```json title="opencode.json" {6}
  1145. {
  1146. "$schema": "https://opencode.ai/config.json",
  1147. "provider": {
  1148. "openrouter": {
  1149. "models": {
  1150. "somecoolnewmodel": {}
  1151. }
  1152. }
  1153. }
  1154. }
  1155. ```
  1156. 5. You can also customize them through your opencode config. Here's an example of specifying a provider
  1157. ```json title="opencode.json"
  1158. {
  1159. "$schema": "https://opencode.ai/config.json",
  1160. "provider": {
  1161. "openrouter": {
  1162. "models": {
  1163. "moonshotai/kimi-k2": {
  1164. "options": {
  1165. "provider": {
  1166. "order": ["baseten"],
  1167. "allow_fallbacks": false
  1168. }
  1169. }
  1170. }
  1171. }
  1172. }
  1173. }
  1174. }
  1175. ```
  1176. ---
  1177. ### LLM Gateway
  1178. 1. Head over to the [LLM Gateway dashboard](https://llmgateway.io/dashboard), click **Create API Key**, and copy the key.
  1179. 2. Run the `/connect` command and search for LLM Gateway.
  1180. ```txt
  1181. /connect
  1182. ```
  1183. 3. Enter the API key for the provider.
  1184. ```txt
  1185. ┌ API key
  1186. │
  1187. │
  1188. └ enter
  1189. ```
  1190. 4. Many LLM Gateway models are preloaded by default, run the `/models` command to select the one you want.
  1191. ```txt
  1192. /models
  1193. ```
  1194. You can also add additional models through your opencode config.
  1195. ```json title="opencode.json" {6}
  1196. {
  1197. "$schema": "https://opencode.ai/config.json",
  1198. "provider": {
  1199. "llmgateway": {
  1200. "models": {
  1201. "somecoolnewmodel": {}
  1202. }
  1203. }
  1204. }
  1205. }
  1206. ```
  1207. 5. You can also customize them through your opencode config. Here's an example of specifying a provider
  1208. ```json title="opencode.json"
  1209. {
  1210. "$schema": "https://opencode.ai/config.json",
  1211. "provider": {
  1212. "llmgateway": {
  1213. "models": {
  1214. "glm-4.7": {
  1215. "name": "GLM 4.7"
  1216. },
  1217. "gpt-5.2": {
  1218. "name": "GPT-5.2"
  1219. },
  1220. "gemini-2.5-pro": {
  1221. "name": "Gemini 2.5 Pro"
  1222. },
  1223. "claude-3-5-sonnet-20241022": {
  1224. "name": "Claude 3.5 Sonnet"
  1225. }
  1226. }
  1227. }
  1228. }
  1229. }
  1230. ```
  1231. ---
  1232. ### SAP AI Core
  1233. SAP AI Core provides access to 40+ models from OpenAI, Anthropic, Google, Amazon, Meta, Mistral, and AI21 through a unified platform.
  1234. 1. Go to your [SAP BTP Cockpit](https://account.hana.ondemand.com/), navigate to your SAP AI Core service instance, and create a service key.
  1235. :::tip
  1236. The service key is a JSON object containing `clientid`, `clientsecret`, `url`, and `serviceurls.AI_API_URL`. You can find your AI Core instance under **Services** > **Instances and Subscriptions** in the BTP Cockpit.
  1237. :::
  1238. 2. Run the `/connect` command and search for **SAP AI Core**.
  1239. ```txt
  1240. /connect
  1241. ```
  1242. 3. Enter your service key JSON.
  1243. ```txt
  1244. ┌ Service key
  1245. │
  1246. │
  1247. └ enter
  1248. ```
  1249. Or set the `AICORE_SERVICE_KEY` environment variable:
  1250. ```bash
  1251. AICORE_SERVICE_KEY='{"clientid":"...","clientsecret":"...","url":"...","serviceurls":{"AI_API_URL":"..."}}' opencode
  1252. ```
  1253. Or add it to your bash profile:
  1254. ```bash title="~/.bash_profile"
  1255. export AICORE_SERVICE_KEY='{"clientid":"...","clientsecret":"...","url":"...","serviceurls":{"AI_API_URL":"..."}}'
  1256. ```
  1257. 4. Optionally set deployment ID and resource group:
  1258. ```bash
  1259. AICORE_DEPLOYMENT_ID=your-deployment-id AICORE_RESOURCE_GROUP=your-resource-group opencode
  1260. ```
  1261. :::note
  1262. These settings are optional and should be configured according to your SAP AI Core setup.
  1263. :::
  1264. 5. Run the `/models` command to select from 40+ available models.
  1265. ```txt
  1266. /models
  1267. ```
  1268. ---
  1269. ### STACKIT
  1270. STACKIT AI Model Serving provides fully managed soverign hosting environment for AI models, focusing on LLMs like Llama, Mistral, and Qwen, with maximum data sovereignty on European infrastructure.
  1271. 1. Head over to [STACKIT Portal](https://portal.stackit.cloud), navigate to **AI Model Serving**, and create an auth token for your project.
  1272. :::tip
  1273. You need a STACKIT customer account, user account, and project before creating auth tokens.
  1274. :::
  1275. 2. Run the `/connect` command and search for **STACKIT**.
  1276. ```txt
  1277. /connect
  1278. ```
  1279. 3. Enter your STACKIT AI Model Serving auth token.
  1280. ```txt
  1281. ┌ API key
  1282. │
  1283. │
  1284. └ enter
  1285. ```
  1286. 4. Run the `/models` command to select from available models like _Qwen3-VL 235B_ or _Llama 3.3 70B_.
  1287. ```txt
  1288. /models
  1289. ```
  1290. ---
  1291. ### OVHcloud AI Endpoints
  1292. 1. Head over to the [OVHcloud panel](https://ovh.com/manager). Navigate to the `Public Cloud` section, `AI & Machine Learning` > `AI Endpoints` and in `API Keys` tab, click **Create a new API key**.
  1293. 2. Run the `/connect` command and search for **OVHcloud AI Endpoints**.
  1294. ```txt
  1295. /connect
  1296. ```
  1297. 3. Enter your OVHcloud AI Endpoints API key.
  1298. ```txt
  1299. ┌ API key
  1300. │
  1301. │
  1302. └ enter
  1303. ```
  1304. 4. Run the `/models` command to select a model like _gpt-oss-120b_.
  1305. ```txt
  1306. /models
  1307. ```
  1308. ---
  1309. ### Scaleway
  1310. To use [Scaleway Generative APIs](https://www.scaleway.com/en/docs/generative-apis/) with Opencode:
  1311. 1. Head over to the [Scaleway Console IAM settings](https://console.scaleway.com/iam/api-keys) to generate a new API key.
  1312. 2. Run the `/connect` command and search for **Scaleway**.
  1313. ```txt
  1314. /connect
  1315. ```
  1316. 3. Enter your Scaleway API key.
  1317. ```txt
  1318. ┌ API key
  1319. │
  1320. │
  1321. └ enter
  1322. ```
  1323. 4. Run the `/models` command to select a model like _devstral-2-123b-instruct-2512_ or _gpt-oss-120b_.
  1324. ```txt
  1325. /models
  1326. ```
  1327. ---
  1328. ### Together AI
  1329. 1. Head over to the [Together AI console](https://api.together.ai), create an account, and click **Add Key**.
  1330. 2. Run the `/connect` command and search for **Together AI**.
  1331. ```txt
  1332. /connect
  1333. ```
  1334. 3. Enter your Together AI API key.
  1335. ```txt
  1336. ┌ API key
  1337. │
  1338. │
  1339. └ enter
  1340. ```
  1341. 4. Run the `/models` command to select a model like _Kimi K2 Instruct_.
  1342. ```txt
  1343. /models
  1344. ```
  1345. ---
  1346. ### Venice AI
  1347. 1. Head over to the [Venice AI console](https://venice.ai), create an account, and generate an API key.
  1348. 2. Run the `/connect` command and search for **Venice AI**.
  1349. ```txt
  1350. /connect
  1351. ```
  1352. 3. Enter your Venice AI API key.
  1353. ```txt
  1354. ┌ API key
  1355. │
  1356. │
  1357. └ enter
  1358. ```
  1359. 4. Run the `/models` command to select a model like _Llama 3.3 70B_.
  1360. ```txt
  1361. /models
  1362. ```
  1363. ---
  1364. ### Vercel AI Gateway
  1365. Vercel AI Gateway lets you access models from OpenAI, Anthropic, Google, xAI, and more through a unified endpoint. Models are offered at list price with no markup.
  1366. 1. Head over to the [Vercel dashboard](https://vercel.com/), navigate to the **AI Gateway** tab, and click **API keys** to create a new API key.
  1367. 2. Run the `/connect` command and search for **Vercel AI Gateway**.
  1368. ```txt
  1369. /connect
  1370. ```
  1371. 3. Enter your Vercel AI Gateway API key.
  1372. ```txt
  1373. ┌ API key
  1374. │
  1375. │
  1376. └ enter
  1377. ```
  1378. 4. Run the `/models` command to select a model.
  1379. ```txt
  1380. /models
  1381. ```
  1382. You can also customize models through your opencode config. Here's an example of specifying provider routing order.
  1383. ```json title="opencode.json"
  1384. {
  1385. "$schema": "https://opencode.ai/config.json",
  1386. "provider": {
  1387. "vercel": {
  1388. "models": {
  1389. "anthropic/claude-sonnet-4": {
  1390. "options": {
  1391. "order": ["anthropic", "vertex"]
  1392. }
  1393. }
  1394. }
  1395. }
  1396. }
  1397. }
  1398. ```
  1399. Some useful routing options:
  1400. | Option | Description |
  1401. | ------------------- | ---------------------------------------------------- |
  1402. | `order` | Provider sequence to try |
  1403. | `only` | Restrict to specific providers |
  1404. | `zeroDataRetention` | Only use providers with zero data retention policies |
  1405. ---
  1406. ### xAI
  1407. 1. Head over to the [xAI console](https://console.x.ai/), create an account, and generate an API key.
  1408. 2. Run the `/connect` command and search for **xAI**.
  1409. ```txt
  1410. /connect
  1411. ```
  1412. 3. Enter your xAI API key.
  1413. ```txt
  1414. ┌ API key
  1415. │
  1416. │
  1417. └ enter
  1418. ```
  1419. 4. Run the `/models` command to select a model like _Grok Beta_.
  1420. ```txt
  1421. /models
  1422. ```
  1423. ---
  1424. ### Z.AI
  1425. 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**.
  1426. 2. Run the `/connect` command and search for **Z.AI**.
  1427. ```txt
  1428. /connect
  1429. ```
  1430. If you are subscribed to the **GLM Coding Plan**, select **Z.AI Coding Plan**.
  1431. 3. Enter your Z.AI API key.
  1432. ```txt
  1433. ┌ API key
  1434. │
  1435. │
  1436. └ enter
  1437. ```
  1438. 4. Run the `/models` command to select a model like _GLM-4.7_.
  1439. ```txt
  1440. /models
  1441. ```
  1442. ---
  1443. ### ZenMux
  1444. 1. Head over to the [ZenMux dashboard](https://zenmux.ai/settings/keys), click **Create API Key**, and copy the key.
  1445. 2. Run the `/connect` command and search for ZenMux.
  1446. ```txt
  1447. /connect
  1448. ```
  1449. 3. Enter the API key for the provider.
  1450. ```txt
  1451. ┌ API key
  1452. │
  1453. │
  1454. └ enter
  1455. ```
  1456. 4. Many ZenMux models are preloaded by default, run the `/models` command to select the one you want.
  1457. ```txt
  1458. /models
  1459. ```
  1460. You can also add additional models through your opencode config.
  1461. ```json title="opencode.json" {6}
  1462. {
  1463. "$schema": "https://opencode.ai/config.json",
  1464. "provider": {
  1465. "zenmux": {
  1466. "models": {
  1467. "somecoolnewmodel": {}
  1468. }
  1469. }
  1470. }
  1471. }
  1472. ```
  1473. ---
  1474. ## Custom provider
  1475. To add any **OpenAI-compatible** provider that's not listed in the `/connect` command:
  1476. :::tip
  1477. You can use any OpenAI-compatible provider with opencode. Most modern AI providers offer OpenAI-compatible APIs.
  1478. :::
  1479. 1. Run the `/connect` command and scroll down to **Other**.
  1480. ```bash
  1481. $ /connect
  1482. ┌ Add credential
  1483. │
  1484. ◆ Select provider
  1485. │ ...
  1486. │ ● Other
  1487. └
  1488. ```
  1489. 2. Enter a unique ID for the provider.
  1490. ```bash
  1491. $ /connect
  1492. ┌ Add credential
  1493. │
  1494. ◇ Enter provider id
  1495. │ myprovider
  1496. └
  1497. ```
  1498. :::note
  1499. Choose a memorable ID, you'll use this in your config file.
  1500. :::
  1501. 3. Enter your API key for the provider.
  1502. ```bash
  1503. $ /connect
  1504. ┌ Add credential
  1505. │
  1506. ▲ This only stores a credential for myprovider - you will need to configure it in opencode.json, check the docs for examples.
  1507. │
  1508. ◇ Enter your API key
  1509. │ sk-...
  1510. └
  1511. ```
  1512. 4. Create or update your `opencode.json` file in your project directory:
  1513. ```json title="opencode.json" ""myprovider"" {5-15}
  1514. {
  1515. "$schema": "https://opencode.ai/config.json",
  1516. "provider": {
  1517. "myprovider": {
  1518. "npm": "@ai-sdk/openai-compatible",
  1519. "name": "My AI ProviderDisplay Name",
  1520. "options": {
  1521. "baseURL": "https://api.myprovider.com/v1"
  1522. },
  1523. "models": {
  1524. "my-model-name": {
  1525. "name": "My Model Display Name"
  1526. }
  1527. }
  1528. }
  1529. }
  1530. }
  1531. ```
  1532. Here are the configuration options:
  1533. - **npm**: AI SDK package to use, `@ai-sdk/openai-compatible` for OpenAI-compatible providers (for `/v1/chat/completions`). If your provider/model uses `/v1/responses`, use `@ai-sdk/openai`.
  1534. - **name**: Display name in UI.
  1535. - **models**: Available models.
  1536. - **options.baseURL**: API endpoint URL.
  1537. - **options.apiKey**: Optionally set the API key, if not using auth.
  1538. - **options.headers**: Optionally set custom headers.
  1539. More on the advanced options in the example below.
  1540. 5. Run the `/models` command and your custom provider and models will appear in the selection list.
  1541. ---
  1542. ##### Example
  1543. Here's an example setting the `apiKey`, `headers`, and model `limit` options.
  1544. ```json title="opencode.json" {9,11,17-20}
  1545. {
  1546. "$schema": "https://opencode.ai/config.json",
  1547. "provider": {
  1548. "myprovider": {
  1549. "npm": "@ai-sdk/openai-compatible",
  1550. "name": "My AI ProviderDisplay Name",
  1551. "options": {
  1552. "baseURL": "https://api.myprovider.com/v1",
  1553. "apiKey": "{env:ANTHROPIC_API_KEY}",
  1554. "headers": {
  1555. "Authorization": "Bearer custom-token"
  1556. }
  1557. },
  1558. "models": {
  1559. "my-model-name": {
  1560. "name": "My Model Display Name",
  1561. "limit": {
  1562. "context": 200000,
  1563. "output": 65536
  1564. }
  1565. }
  1566. }
  1567. }
  1568. }
  1569. }
  1570. ```
  1571. Configuration details:
  1572. - **apiKey**: Set using `env` variable syntax, [learn more](/docs/config#env-vars).
  1573. - **headers**: Custom headers sent with each request.
  1574. - **limit.context**: Maximum input tokens the model accepts.
  1575. - **limit.output**: Maximum tokens the model can generate.
  1576. The `limit` fields allow OpenCode to understand how much context you have left. Standard providers pull these from models.dev automatically.
  1577. ---
  1578. ## Troubleshooting
  1579. If you are having trouble with configuring a provider, check the following:
  1580. 1. **Check the auth setup**: Run `opencode auth list` to see if the credentials
  1581. for the provider are added to your config.
  1582. This doesn't apply to providers like Amazon Bedrock, that rely on environment variables for their auth.
  1583. 2. For custom providers, check the opencode config and:
  1584. - Make sure the provider ID used in the `/connect` command matches the ID in your opencode config.
  1585. - 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` (for `/v1/chat/completions`); if a model uses `/v1/responses`, use `@ai-sdk/openai`. For mixed setups under one provider, you can override per model via `provider.npm`.
  1586. - Check correct API endpoint is used in the `options.baseURL` field.