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

# How to use OpenCode with Claude, DeepSeek and GPT via RuAPI

> Step-by-step setup of OpenCode — the open-source AI coding agent for the terminal — with RuAPI: Claude via the Anthropic provider with prompt caching; DeepSeek, GPT and other models via an OpenAI-compatible provider. No VPN needed; pay in USDT.

[OpenCode](https://opencode.ai) is an open-source AI coding agent that runs in your terminal: it reads and edits project files, runs commands and sees a task through from start to finish. It isn't tied to a single model vendor, so it connects to RuAPI directly. RuAPI gives you access to Claude, GPT, Gemini, DeepSeek, GLM, Qwen and Kimi with a single API key, and works from Russia without a VPN. You top up your balance in USDT; no foreign-issued card required.

## How it works

In OpenCode, models are connected through providers defined in `opencode.json`. For RuAPI you need two:

| OpenCode provider | Base URL | Models | Why |
| - | - | - | - |
| `anthropic` (built-in) | `https://www.ruapi.ai/v1` | Claude: `claude-opus-5-5`, `claude-sonnet-5-5`, `claude-haiku-5-5` | Claude's native format: prompt caching works, so re-sent context costs at least 10× less |
| `ruapi` (custom, OpenAI-compatible) | `https://www.ruapi.ai/v1` | DeepSeek, GPT, Gemini, GLM, Qwen, Kimi and others | One URL for every other model |

## Before you start

<Steps>
  <Step title="RuAPI API key">
    Sign up at [www.ruapi.ai](https://www.ruapi.ai/?utm_source=docs\&utm_campaign=en-opencode) and top up your balance ([how to top up](/en/topup)). Then go to Console → **API Keys** and click **Create API key**. Keys start with `sk-`.
  </Step>

  <Step title="OpenCode installed">
    On macOS and Linux:

    ```bash theme={null}
    curl -fsSL https://opencode.ai/install | bash
    ```

    Or via npm on any OS, including Windows:

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

    On Windows, the OpenCode team recommends running it under WSL.
  </Step>
</Steps>

<Tip>
  No bank card needed: you can top up your balance in USDT. If you don't have USDT yet, follow our [step-by-step guide to buying it with rubles](/en/buy-usdt). Foreign-issued cards are accepted too.
</Tip>

## Step 1. Store your key in an environment variable

To keep the key out of your config file, OpenCode will read it from the `RUAPI_API_KEY` environment variable.

<Tabs>
  <Tab title="macOS / Linux">
    Add the line to `~/.zshrc` (or `~/.bashrc` if you use bash), with your own key:

    ```bash theme={null}
    echo 'export RUAPI_API_KEY="sk-your-key"' >> ~/.zshrc
    ```

    Then open a new terminal window for the change to take effect.
  </Tab>

  <Tab title="Windows (PowerShell)">
    ```powershell theme={null}
    setx RUAPI_API_KEY "sk-your-key"
    ```

    Then open a new PowerShell window for the change to take effect.
  </Tab>
</Tabs>

## Step 2. Define the providers in opencode.json

Open (or create) the global config file `~/.config/opencode/opencode.json` and paste:

```json theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "anthropic": {
      "options": {
        "baseURL": "https://www.ruapi.ai/v1",
        "apiKey": "{env:RUAPI_API_KEY}"
      }
    },
    "ruapi": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "RuAPI",
      "options": {
        "baseURL": "https://www.ruapi.ai/v1",
        "apiKey": "{env:RUAPI_API_KEY}"
      },
      "models": {
        "deepseek-flash": { "name": "DeepSeek Flash" },
        "deepseek-v4-pro": { "name": "DeepSeek V4 Pro" },
        "gpt-5.4": { "name": "GPT-5.4" },
        "glm-5.3": { "name": "GLM-5.3" }
      }
    }
  },
  "model": "anthropic/claude-sonnet-5-5"
}
```

What this does:

* **`anthropic`** is OpenCode's built-in Claude provider. The config only points it at RuAPI and passes in your key, so requests use Claude's native format, with caching.
* **`ruapi`** is a custom provider for all other models. To add a model, add a line to the `models` block, e.g. `"kimi/kimi-k3": { "name": "Kimi K3" }`. You'll find the exact model names on the [pricing page](https://www.ruapi.ai/pricing?utm_source=docs\&utm_campaign=en-opencode).
* **`model`** sets the default model in `provider/model` format.

<Note>
  If your project folder also has an `opencode.json`, OpenCode merges the two files, and project settings take precedence. Don't put the key directly in a project file — use `{env:RUAPI_API_KEY}` as in the example.
</Note>

## Step 3. Start OpenCode and pick a model

Go to your project folder and start the agent:

```bash theme={null}
cd path/to/project
```

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

In OpenCode, type `/models` and pick a model — for example, `anthropic/claude-sonnet-5-5` or `ruapi/deepseek-flash`. Then give it a task:

```
Add error handling to the parseConfig function in config.ts
```

To confirm that requests are going through RuAPI, open Console → **Usage Logs**: you'll see an entry for each request with the model and cost. For Claude, from the second or third step onward the entry details show how many tokens were read from the cache.

## Which model to pick

| Task | Model |
| - | - |
| Complex tasks, design work | `anthropic/claude-opus-5-5` |
| Everyday coding | `anthropic/claude-sonnet-5-5` |
| Lots of routine edits on a tight budget | `ruapi/deepseek-flash` (DeepSeek caches automatically) |

## Troubleshooting

<AccordionGroup>
  <Accordion title="401 / Invalid key">
    * Make sure `RUAPI_API_KEY` is available in the terminal where OpenCode runs: after creating the variable, open a new window.
    * `baseURL` must be `https://www.ruapi.ai/v1` for both providers.
  </Accordion>

  <Accordion title="A Claude model is missing from /models">
    OpenCode takes the model list for the built-in `anthropic` provider from its own catalog. Update OpenCode; if the model is still missing, add a `models` section to the `anthropic` block with the name you need, e.g. `"claude-opus-5-5": { "name": "Claude Opus 5.5" }`.
  </Accordion>

  <Accordion title="Model not found (404 or 503)">
    The model name must match the one on RuAPI exactly — copy it from the [pricing page](https://www.ruapi.ai/pricing?utm_source=docs\&utm_campaign=en-opencode). Pick Claude models from the `anthropic` provider and all other models from `ruapi`.
  </Accordion>

  <Accordion title="Config file error">
    Make sure the JSON is valid: all quotes are double quotes, and there's no trailing comma after the last item in a block.
  </Accordion>

  <Accordion title="400: The reasoning_content in the thinking mode must be passed back">
    This can happen with DeepSeek in reasoning mode if you switch models mid-task. In most cases RuAPI automatically fixes and retries the request. If the error persists, start a new session.
  </Accordion>
</AccordionGroup>

## What's next

* [Claude Code](/en/integrations/claude-code) and [Codex](/en/integrations/codex) — other terminal agents.
* [Switching from Cursor](/en/integrations/cursor-alternatives) — a comparison of coding agents and step-by-step migration.
* [Models and prices](/en/models) — the full list of available models.


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