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

# OpenCode

> Configure 4096bytes in OpenCode

OpenCode can connect to 4096bytes through an OpenAI-compatible Provider. Write the dashboard-generated `opencode.json` config into an OpenCode config file.

Prefer copying the config from the dashboard **Use key** dialog. The OpenCode tab inserts the current API Key, Base URL, and model names in OpenCode format.

## Prerequisites

* You have completed [Create an account](/en/quickstart/create-account).
* You have completed [Get an API Key](/en/quickstart/get-api-key).
* OpenCode is installed and `opencode --version` works.
* The **Use key** dialog is open for the API Key you want to use.

<Warning>
  The API Key in `opencode.json` is stored as a local plaintext credential. Do not commit config files, screenshots, or terminal output that include a full API Key.
</Warning>

## Install

If OpenCode is not installed, check the latest instructions in the [OpenCode documentation](https://opencode.ai/docs).

macOS or Linux:

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

If you use npm for global CLI tools:

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

After installation, reopen the terminal and verify:

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

## Copy config from the dashboard

<Steps>
  <Step title="Open API Keys">
    Open the dashboard and go to **API Keys**.
  </Step>

  <Step title="Choose OpenCode">
    Find the key you want to use for OpenCode, click **Use key**, then choose **OpenCode**.
  </Step>

  <Step title="Copy config">
    Copy the generated `opencode.json` content. The sample is only a reference. Use the Base URL, API Key, and model names shown in your dashboard.
  </Step>

  <Step title="Write the config file">
    For global use, write it to `~/.config/opencode/opencode.json`. For project-only use, write it to `opencode.json` in the project root.
  </Step>
</Steps>

## Config file paths

| Scope          | Path                               | Use case                                     |
| -------------- | ---------------------------------- | -------------------------------------------- |
| Global config  | `~/.config/opencode/opencode.json` | Use 4096bytes by default in all projects.    |
| Project config | `opencode.json`                    | Use this config only in the current project. |

Create the file manually if it does not exist. Project config has higher precedence than global config.

## Verify

Save the config, go to a project directory, and run:

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

After OpenCode opens, start with a low-risk prompt:

```text theme={null}
Describe the purpose of the current directory in one sentence. Do not modify files.
```

If OpenCode responds without authentication or model errors, the config is active.

## Common issues

<AccordionGroup>
  <Accordion title="OpenCode reports authentication failure">
    Check that `opencode.json` is valid JSON. Confirm `apiKey` has no missing characters, newlines, or extra spaces.
  </Accordion>

  <Accordion title="OpenCode cannot find the model">
    The model ID must match the model name shown in the dashboard. Do not copy names from someone else's screenshot.
  </Accordion>

  <Accordion title="The config does not take effect">
    Confirm you edited the file OpenCode is actually reading. A project-root `opencode.json` overrides matching fields in global config.
  </Accordion>

  <Accordion title="Can I configure the API Key with /connect?">
    Yes, but `/connect` only stores credentials. Provider, Base URL, and model list should still come from the dashboard-generated `opencode.json`.
  </Accordion>
</AccordionGroup>
