# opencode

## Getting started

Install opencode and omniroute, configure providers and connect them through a local API.

### References

<ReferenceLinks references={frontmatter.references} />

---

1.  ## Install opencode

    Install opencode using the official installer.

    ```sh
    curl -fsSL https://opencode.ai/install | bash
    ```

2.  ## Install omniroute

    Install the latest omniroute release globally, then start the local server.

    ```sh
    pnpm add -g omniroute@latest --allow-build=better-sqlite3 --allow-build=@swc/core && omniroute
    ```

3.  ## Configure omniroute

    Open the omniroute web UI and complete the initial setup.

    ```sh
    open http://localhost:20128/login
    ```

        - Set an omniroute password.
        - Get API keys for the providers you want to use:
            - [Cerebras](https://cloud.cerebras.ai/platform)
            - [Mistral](https://console.mistral.ai/api-keys)
            - [Google AI Studio (Gemini)](https://aistudio.google.com/api-keys)
            - [Groq](https://console.groq.com/keys)
            - [DeepSeek](https://platform.deepseek.com/api_keys)
            - [OpenRouter](https://openrouter.ai/workspaces/default/keys)
        - Add providers [http://localhost:20128/dashboard/providers](http://localhost:20128/dashboard/providers).
        - Create omniroute API key [http://localhost:20128/dashboard/api-manager](http://localhost:20128/dashboard/api-manager).

        

4.  ## Configure opencode

    Create the opencode configuration directory and file.

    ```sh
    mkdir -p ~/.config/opencode
    ```

    ```sh
    nano ~/.config/opencode/opencode.json
    ```

    Add the following configuration and replace `YOUR_OMNIROUTE_API_KEY` with your omniroute API key.

    ```sh title="opencode.json"
    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "omniroute": {
          "npm": "@ai-sdk/openai-compatible",
          "name": "omniroute",
          "options": {
            "baseURL": "http://localhost:20128/v1",
            "apiKey": "YOUR_OMNIROUTE_API_KEY"
          },
          "models": {
            "auto": {
              "name": "Auto / Best Available"
            }
          }
        }
      }
    }
    ```

5.  ## Start opencode

    Start opencode from your terminal.

    ```sh
    opencode
    ```

    Verify that omniroute is available as a provider. If needed, use `/connect` and select `omniroute`.
