Before you begin
Make sure you have:Connect to the Modular provider
To get started with Modular Cloud on OpenCode, you can connect a model from any of our shared endpoints:-
Start OpenCode:
-
Run the
/connectcommand and search for Modular. Select Modular and enter your API key. -
Run the
/modelscommand and select a Modular Cloud model.
model in your
opencode.json config file:
opencode.json
Connect a dedicated deployment
Each dedicated deployment runs on your organization’s own endpoint, so you need to add it to OpenCode as a separate provider:- Open your deployment and copy its Dedicated Endpoint and Model ID.
-
Export your API key as an environment variable:
-
Open the
opencode.jsonconfig file in your project directory and add a provider for your deployment:Inopencode.jsonbaseURL, paste the dedicated endpoint you copied in step 1 with/v1at the end. Then replace the model ID with your deployment’s model ID. Modular Cloud supports the OpenAI chat completions API, so setnpmto@ai-sdk/openai-compatible. Avoid naming the providermodularbecause it might conflict with the built-in provider ID for Modular. -
Restart OpenCode, run the
/modelscommand, and select your deployment’s model.