providers.mdx 49 KB

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