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

# Configure OpenCode AI Coding Agent with KiosAPI API

> Set up the OpenCode terminal AI coding agent to use KiosAPI as its backend, connecting it to KiosAPI's OpenAI-compatible API gateway.

OpenCode is an AI coding agent designed for the terminal. This tutorial walks you through installing OpenCode, configuring it to route requests through KiosAPI, and verifying that everything works — so you can start using OpenCode with any model available on KiosAPI.

## Prerequisites

* **Node.js 18+** — verify with `node --version`
* A **KiosAPI API key** (starts with `sk-`) from the [Dashboard](https://kiosapi.com) → **Token Management**

<Steps>
  ### Install OpenCode

  Install OpenCode globally via npm:

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

  Verify the installation:

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

  ### Set environment variables

  <Tabs>
    <Tab title="macOS / Linux">
      Add the following to `~/.bashrc` or `~/.zshrc`:

      ```bash theme={null}
      export OPENAI_API_KEY="sk-xxx"
      export OPENAI_BASE_URL="https://kiosapi.com/v1"
      ```

      Then reload your shell:

      ```bash theme={null}
      source ~/.bashrc  # or ~/.zshrc
      ```
    </Tab>

    <Tab title="Windows (PowerShell)">
      ```powershell theme={null}
      setx OPENAI_API_KEY "sk-xxx"
      setx OPENAI_BASE_URL "https://kiosapi.com/v1"
      ```
    </Tab>
  </Tabs>

  Replace `sk-xxx` with your actual KiosAPI key.

  ### Create the config file

  Create or edit `~/.config/opencode/config.json`:

  ```json theme={null}
  {
    "provider": "openai",
    "apiBase": "https://kiosapi.com/v1",
    "apiKey": "sk-xxx",
    "model": "gpt-4o"
  }
  ```

  Replace `sk-xxx` with your actual KiosAPI key.

  <Tip>
    OpenCode supports any OpenAI-compatible model on KiosAPI. See the [models list](../api-reference/models/list-models) for all available options.
  </Tip>

  ### Verify your setup

  Run a quick test to confirm everything is connected:

  ```bash theme={null}
  opencode "Say hello"
  ```

  If OpenCode responds, your configuration is working correctly.
</Steps>

## Usage

<CodeGroup>
  ```bash Interactive mode theme={null}
  opencode
  ```

  ```bash Direct question theme={null}
  opencode "Write a Python script to parse CSV files"
  ```

  ```bash Specify a model theme={null}
  opencode --model gpt-4o-mini "Explain this error message"
  ```
</CodeGroup>

## Troubleshooting

### Authentication error

* Verify `OPENAI_API_KEY` is set correctly: `echo $OPENAI_API_KEY`
* Ensure the key starts with `sk-`
* Check that `apiBase` in the config file matches the `OPENAI_BASE_URL` environment variable

### Model not found

* Check the model name is valid on the [KiosAPI models page](https://kiosapi.com/pricing)
* Ensure the model is included in your token group

## Need Help?

* [KiosAPI Dashboard](https://kiosapi.com)
* [Available Models](../api-reference/models/list-models)
