> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sinarcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use OpenCode with SinarCloud

> Add SinarCloud to OpenCode, the open source coding agent for the terminal, and run it on SinarCloud models through the OpenAI Chat Completions format.

[OpenCode](https://opencode.ai) is an open source coding agent that runs in your terminal. It can send its requests to any OpenAI-compatible API. Add SinarCloud to OpenCode's config file, and OpenCode runs on SinarCloud models, charged to your balance.

This guide was last checked with OpenCode 1.19.4.

## Before you start

* Get an API key and a model alias as described in [Before you connect](https://docs.sinarcloud.com/integrations/before-you-connect.md). The base URL is `https://ai.sinarcloud.com/v1`.

**1. Install OpenCode**

Open a terminal in your project's root folder. If you use VS Code, open your project, then open the Command Palette and run **Terminal: Create New Terminal**. The terminal opens in the project's folder.

Install OpenCode with npm, or see the [OpenCode documentation](https://opencode.ai/docs/) for other ways to install it:

```bash theme={null}
npm install -g opencode-ai
```

To check that it's installed, run:

```bash theme={null}
opencode --version
```

OpenCode prints its version, for example `1.19.4`.

![VS Code's Terminal panel. The command opencode --version printed 1.19.4.](https://mintcdn.com/sinar-cloud/ShOrAB8ikH3IKe3Y/images/integrations/opencode-install.png?fit=max\&auto=format\&n=ShOrAB8ikH3IKe3Y\&q=85\&s=f250c52a92085ab1b443c0a44251dd8d)

OpenCode prints its version

**2. Create opencode.json in your project**

OpenCode reads its settings from a file named `opencode.json`. To use SinarCloud in one project, create `opencode.json` in the project's root folder and paste the following into it. To use it in every project on macOS or Linux, create the file at `~/.config/opencode/opencode.json` instead. If the file already exists, add the `model` and `provider` keys to it.

```json opencode.json theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "model": "sinarcloud/deepseek/deepseek-v4-1-flash",
  "provider": {
    "sinarcloud": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "SinarCloud",
      "options": {
        "baseURL": "https://ai.sinarcloud.com/v1",
        "apiKey": "{env:SINARCLOUD_API_KEY}"
      },
      "models": {
        "deepseek/deepseek-v4-1-flash": {
          "name": "DeepSeek V4.1 Flash",
          "limit": {
            "context": 1000000,
            "output": 393216
          }
        }
      }
    }
  }
}
```

Save the file.

![VS Code with a project open. The Explorer lists src, opencode.json and README.md, and opencode.json is open in the editor. It sets model to sinarcloud/deepseek/deepseek-v4-1-flash. Under the sinarcloud key, it sets npm to @ai-sdk/openai-compatible, name to SinarCloud, baseURL to https://ai.sinarcloud.com/v1 and apiKey to \{env:SINARCLOUD\_API\_KEY}, and lists the model deepseek/deepseek-v4-1-flash named DeepSeek V4.1 Flash, with a context limit of 1000000 and an output limit of 393216.](https://mintcdn.com/sinar-cloud/ShOrAB8ikH3IKe3Y/images/integrations/opencode-config-file.png?fit=max\&auto=format\&n=ShOrAB8ikH3IKe3Y\&q=85\&s=b42d71e3bf3880e94a72307eae4c6370)

opencode.json in the project's root folder, with the SinarCloud base URL

Here's what each part does:

* `provider.sinarcloud` adds SinarCloud to OpenCode under the ID `sinarcloud`. The `@ai-sdk/openai-compatible` package makes OpenCode use the OpenAI Chat Completions format.
* `baseURL` makes OpenCode send its requests to `https://ai.sinarcloud.com/v1`.
* `{env:SINARCLOUD_API_KEY}` makes OpenCode read your API key from the environment variable, so your key isn't stored in the file.
* Each key under `models` is a model alias from the **Models** page, and `name` is the name OpenCode shows for it. Set `limit.context` and `limit.output` to the model's **Context window (tokens)** and **Maximum output (tokens)**, which OpenCode uses to manage long conversations.
* `model` sets the default model: `sinarcloud/` followed by the model alias.

> [!TIP]
>
> The console can write this file for you. On the **Models** page, click **Details** on a model, then open the **Use via API** tab and its **OpenCode** tab. It shows a config for that model with the base URL filled in. Before you save it, replace `YOUR_API_KEY` with `{env:SINARCLOUD_API_KEY}`.

**3. Set your API key in the terminal**

In the same terminal, set the `SINARCLOUD_API_KEY` environment variable to your API key, then check that it's set:

> [tab] macOS and Linux
>
> ```bash theme={null}
> export SINARCLOUD_API_KEY="paste-your-api-key"
> [ -n "$SINARCLOUD_API_KEY" ] && echo set
> ```

> [tab] Windows PowerShell
>
> ```powershell theme={null}
> $env:SINARCLOUD_API_KEY = "paste-your-api-key"
> if ($env:SINARCLOUD_API_KEY) { "set" }
> ```

Replace `paste-your-api-key` with your key, and keep the quotes. The check prints `set` without showing your key. If you already saved the key for every new terminal, as described in [Before you connect](https://docs.sinarcloud.com/integrations/before-you-connect.md), run only the check.

![VS Code's Terminal panel with two commands: the export line that sets SINARCLOUD\_API\_KEY to the placeholder paste-your-api-key, and the check that the variable is set, which printed set.](https://mintcdn.com/sinar-cloud/ShOrAB8ikH3IKe3Y/images/integrations/opencode-api-key.png?fit=max\&auto=format\&n=ShOrAB8ikH3IKe3Y\&q=85\&s=8063236f5adac2e03acc5acdc09a4c62)

The key is set in the terminal, and the check prints set

The variable lasts until you close the terminal, so start OpenCode from this terminal.

**4. Start OpenCode**

In the same terminal, in your project's root folder, start OpenCode:

```bash theme={null}
opencode
```

OpenCode opens in the terminal. In the prompt box, under the placeholder text, OpenCode shows the agent, **Build**, and the model, **DeepSeek V4.1 Flash**, followed by **SinarCloud**.

![OpenCode's start screen in the terminal: the OpenCode logo, a hint to run /update to upgrade to OpenCode 2.0, and the prompt box with the placeholder Ask anything… and an example task. In the box, under the placeholder, is Build · DeepSeek V4.1 Flash SinarCloud. Below the box are the hints tab agents and ctrl+p commands.](https://mintcdn.com/sinar-cloud/ShOrAB8ikH3IKe3Y/images/integrations/opencode-start.png?fit=max\&auto=format\&n=ShOrAB8ikH3IKe3Y\&q=85\&s=8fca5b9d21fe5d2f94fca5e87f0d9416)

OpenCode started, with DeepSeek V4.1 Flash from SinarCloud

**5. Check the model with /models**

Type `/models` and press Enter. In **Select model**, type `sinarcloud` to show only the models you added for SinarCloud. A dot marks the model OpenCode uses. To switch to another model you added, select it and press Enter. To close the list, press Esc.

The full list also shows models under other headings, such as **OpenCode**. Only the models under **SinarCloud** use your SinarCloud API key.

![OpenCode's Select model dialog with sinarcloud typed in its search box. The only result, DeepSeek V4.1 Flash with SinarCloud on the right, is highlighted and marked with a dot. At the bottom are the hints Connect provider ctrl+a and Favorite ctrl+f.](https://mintcdn.com/sinar-cloud/ShOrAB8ikH3IKe3Y/images/integrations/opencode-models.png?fit=max\&auto=format\&n=ShOrAB8ikH3IKe3Y\&q=85\&s=13d1081600f295094ae577f10132f038)

Select model, filtered to SinarCloud

**6. Send a prompt**

Type a task in the prompt box, for example `Add a GET /products/:id route to src/server.js`, and press Enter.

![OpenCode's prompt box with the task Add a GET /products/:id route to src/server.js typed in, above Build · DeepSeek V4.1 Flash SinarCloud.](https://mintcdn.com/sinar-cloud/ShOrAB8ikH3IKe3Y/images/integrations/opencode-prompt.png?fit=max\&auto=format\&n=ShOrAB8ikH3IKe3Y\&q=85\&s=9fe4f83232d15d0faaed070d82a952f2)

A task in OpenCode's prompt box, ready to send

To try the connection without opening the full interface, send a single prompt from the terminal instead:

```bash theme={null}
opencode run "Say hello in Indonesian."
```

The output starts with the agent and model that answered, for example `build · deepseek/deepseek-v4-1-flash`.

**7. Find the requests in Usage**

In the console, under **AI**, click **Usage**, then choose the key you created for OpenCode in the **API key** filter. When you start a session, OpenCode usually sends two requests: one that names the session and one for your prompt. Only requests whose charge is final appear, so click **Refresh** if you don't see them yet.

![Log & Usage page with the Date range, Model and API key filters, a Refresh button and five cards of totals, starting with Total charged and Total saved. Below them are the Log, Summary, Spending, Models and Tokens tabs, with the Log tab's Recent requests table showing a Show details button on each row.](https://mintcdn.com/sinar-cloud/Zz311Jgf5s_A88RD/images/ai-usage.png?fit=max\&auto=format\&n=Zz311Jgf5s_A88RD\&q=85\&s=81c8d86294bf5b9247d4970ce519223f)

The Usage page, with the API key filter at the top

## Add more models

Add each model you want to use under `models`, with its alias as the key. To use a lower-cost model for small tasks such as naming sessions, set `small_model`. Otherwise, OpenCode uses your default model for them too.

```json opencode.json theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "model": "sinarcloud/deepseek/deepseek-v4-pro",
  "small_model": "sinarcloud/deepseek/deepseek-v4-1-flash",
  "provider": {
    "sinarcloud": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "SinarCloud",
      "options": {
        "baseURL": "https://ai.sinarcloud.com/v1",
        "apiKey": "{env:SINARCLOUD_API_KEY}"
      },
      "models": {
        "deepseek/deepseek-v4-1-flash": {
          "name": "DeepSeek V4.1 Flash",
          "limit": { "context": 1000000, "output": 393216 }
        },
        "deepseek/deepseek-v4-pro": {
          "name": "DeepSeek V4 Pro",
          "limit": { "context": 1000000, "output": 393216 }
        }
      }
    }
  }
}
```

Compare prices on the **Models** page before you choose a default model, because every step of an agent's work is a separate request.

## Troubleshooting

OpenCode shows errors from SinarCloud after `Error:`.

> [accordion] Error: Invalid API key.
>
> The API key is missing, mistyped, expired, or revoked. Check that `SINARCLOUD_API_KEY` is set in the terminal where you started OpenCode and that it holds your whole key. If the key has expired or been revoked, create a new one.

> [accordion] Error: The requested model does not exist or is not available for this endpoint.
>
> The model alias doesn't exist, the model isn't available right now, or it doesn't support chat completions. Copy the alias again from the **Models** page and check that the key under `models` matches it exactly, and that `model` is `sinarcloud/` followed by the same alias. Then check that the model's **Model capabilities** list **Chat completions**.

> [accordion] Error: Your balance is empty or negative and no token credits remain for this model.
>
> [Add balance](https://docs.sinarcloud.com/billing/top-up.md), then send your prompt again.

For other problems, see [Troubleshooting](https://docs.sinarcloud.com/help/troubleshooting.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.