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

# OpenCode

> Use OpenCode with Routeway by adding a custom provider to the OpenCode config file.

OpenCode is an AI coding agent that runs in your terminal. You can connect it to Routeway by defining a custom provider in `~/.config/opencode/opencode.json` and authenticating with your **Routeway API key** inside OpenCode.

<Note>
  Requires a valid Routeway API key. Get yours from the [dashboard](https://routeway.ai/dashboard/api-keys).
</Note>

***

## Setup

<Steps>
  <Step title="Install OpenCode">
    Follow the official installation docs at [opencode.ai](https://opencode.ai/docs).

    <CodeGroup>
      ```bash Install script theme={null}
      curl -fsSL https://opencode.ai/install | bash
      ```

      ```bash npm theme={null}
      npm install -g opencode-ai
      ```
    </CodeGroup>
  </Step>

  <Step title="Add Routeway as a custom provider">
    Open `~/.config/opencode/opencode.json` and configure a custom provider named `routeway`:

    ```json theme={null}
    {
      "$schema": "https://opencode.ai/config.json",
      "disabled_providers": [],
      "provider": {
        "routeway": {
          "name": "Routeway",
          "npm": "@ai-sdk/openai",
          "models": {
            "gpt-4.1": {
              "name": "GPT 4.1",
              "limit": {
                "context": 1048576,
                "output": 32768
              },
              "modalities": {
                "input": ["text", "image"],
                "output": ["text"]
              }
            }
          },
          "options": {
            "baseURL": "https://api.routeway.ai/v1"
          }
        }
      }
    }
    ```

    <Info>
      This example registers `gpt-4.1`, but you can add any Routeway model. For agentic coding, prefer models with tools support — browse at [routeway.ai/models](https://routeway.ai/models).
    </Info>
  </Step>

  <Step title="Connect your API key in OpenCode">
    Start OpenCode in your project directory:

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

    Then run:

    ```
    /connect
    ```

    In the provider list:

    * Select **Routeway**
    * Paste your **Routeway API key**
    * Save the credential
  </Step>

  <Step title="Choose the model and start coding">
    After connecting, select the configured Routeway model in OpenCode and start your session.
  </Step>
</Steps>

***

## Reference

| Setting       | Value                              |
| ------------- | ---------------------------------- |
| Config file   | `~/.config/opencode/opencode.json` |
| Base URL      | `https://api.routeway.ai/v1`       |
| Provider name | `routeway`                         |
| Example model | `gpt-4.1`                          |

***

## Example Prompts

Try these once you're connected:

* *"Summarize this repository: structure, build system, and entry points."*
* *"Find where feature X is implemented and list the relevant files."*
* *"Run tests and fix the first failing test."*
* *"Refactor module Y and update all call sites."*
