providers.mdx 53 KB

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