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

# OpenCode

> Connect OpenCode to AihubMax

## Overview

[OpenCode](https://github.com/opencode-ai/opencode) is a Go-based TUI (Terminal User Interface) coding assistant that works with multiple LLM providers. It provides an interactive terminal interface for chatting with AI about your code, generating changes, and running commands.

By configuring OpenCode with AihubMax, you can access a variety of AI models through a single API endpoint.

<Info>
  OpenCode supports custom providers via its JSON configuration, making AihubMax integration straightforward.
</Info>

## Prerequisites

<CardGroup cols={2}>
  <Card title="AihubMax API Key" icon="key">
    An active AihubMax API key.
  </Card>

  <Card title="OpenCode" icon="terminal">
    OpenCode installed on your system.
  </Card>
</CardGroup>

## Installation & Configuration

<Steps>
  <Step title="Install OpenCode">
    <Tabs>
      <Tab title="macOS / Linux (curl)">
        ```bash theme={null}
        curl -fsSL https://opencode.ai/install | bash
        ```
      </Tab>

      <Tab title="Homebrew">
        ```bash theme={null}
        brew install anomalyco/tap/opencode
        ```
      </Tab>

      <Tab title="Windows">
        Visit the [OpenCode download page](https://opencode.ai) to download the Windows installer.
      </Tab>
    </Tabs>

    Verify the installation:

    ```bash theme={null}
    opencode --version
    ```
  </Step>

  <Step title="Register the Custom Provider">
    Before editing the configuration file, you must first register a custom provider using the OpenCode CLI:

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

    When prompted:

    1. Select **"other"** as the provider type.
    2. Enter `foxapi` as the provider ID.
    3. Enter any placeholder value for the token (it will be overridden in the config file).

    <Warning>
      This step is required. OpenCode will not recognize the `foxapi` provider in the configuration file unless it has been registered first via `opencode auth login`.
    </Warning>
  </Step>

  <Step title="Configure AihubMax">
    Edit the OpenCode configuration file:

    <Tabs>
      <Tab title="macOS / Linux">
        ```
        ~/.config/opencode/opencode.json
        ```
      </Tab>

      <Tab title="Windows">
        ```
        C:\Users\{username}\.config\opencode\opencode.json
        ```
      </Tab>
    </Tabs>

    Set the contents to the following:

    ```json theme={null}
    {
      "$schema": "https://opencode.ai/config.json",
      "provider": {
        "foxapi": {
          "npm": "@ai-sdk/anthropic",
          "name": "AihubMax",
          "options": {
            "baseURL": "https://api.aihubmax.com/v1",
            "apiKey": "sk-your-foxapi-api-key"
          },
          "models": {
            "claude-sonnet-4-20250514": { "name": "Claude Sonnet 4" },
            "claude-opus-4-20250514": { "name": "Claude Opus 4" },
            "gpt-4o": { "name": "GPT-4o" }
          }
        }
      }
    }
    ```

    Replace `sk-your-foxapi-api-key` with your actual AihubMax API key.
  </Step>

  <Step title="Start Using OpenCode">
    Launch OpenCode in your project directory:

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

    This opens the interactive TUI where you can chat with the AI about your codebase.
  </Step>
</Steps>

## Verify the Connection

After launching OpenCode, use the `/models` command inside the TUI to verify that the configured models are available:

```
/models
```

You should see the AihubMax models listed (e.g., Claude Sonnet 4, Claude Opus 4, GPT-4o). Then type a test message to confirm the connection:

```
Hello, please confirm you are working correctly.
```

A successful response confirms the AihubMax connection is active.

## Recommended Models

| Use Case             | Model                      | Description                                 |
| -------------------- | -------------------------- | ------------------------------------------- |
| **Complex Tasks**    | `claude-opus-4-20250514`   | Best for complex reasoning and architecture |
| **Balanced**         | `claude-sonnet-4-20250514` | Great balance of quality and speed          |
| **Fast & Efficient** | `gpt-4o`                   | Quick responses for everyday tasks          |

## Troubleshooting

<AccordionGroup>
  <Accordion title="Provider not recognized">
    * Make sure you have run `opencode auth login` and registered the `foxapi` provider before editing the config file.
    * Ensure the provider ID in the config matches exactly what you entered during registration.
    * Check that the configuration file syntax is valid JSON.
  </Accordion>

  <Accordion title="Authentication failed">
    * Verify your AihubMax API key is correct in the `options.apiKey` field.
    * Ensure the key has sufficient balance and model access.
  </Accordion>

  <Accordion title="Configuration file not found">
    * On macOS/Linux, the config file should be at `~/.config/opencode/opencode.json`.
    * On Windows, the config file should be at `C:\Users\{username}\.config\opencode\opencode.json`.
  </Accordion>

  <Accordion title="Models not showing up">
    * Use the `/models` command inside OpenCode to check available models.
    * Verify that the `models` section in your config lists the correct model IDs.
    * Ensure the `baseURL` is set to `https://api.aihubmax.com/v1`.
  </Accordion>
</AccordionGroup>
