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

# OpenCode Integration

> Complete guide to integrating Morpheus AI with OpenCode - a powerful AI coding assistant - using custom provider configuration

# Integrate Morpheus AI with OpenCode

<iframe width="560" height="315" src="https://www.youtube.com/embed/nVLs0j2vimE" title="OpenCode Integration Tutorial" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen style={{ width: '100%', borderRadius: '0.5rem' }} />

<br />

Learn how to set up Morpheus AI as a custom provider in OpenCode, giving you access to powerful AI models for coding assistance. This guide walks you through credential setup, provider configuration, and model selection.

## What is OpenCode?

[OpenCode](https://opencode.ai/) is an open-source AI coding agent that helps you write code in your terminal, IDE, or desktop application. It's a powerful alternative to proprietary coding assistants like Claude Code, offering complete flexibility and privacy for developers.

<CardGroup cols={2}>
  <Card title="Open Source & Free" icon="code-branch">
    Over **41,000 GitHub stars** and **450 contributors** building the future of AI-powered coding.
  </Card>

  <Card title="Privacy First" icon="shield-check">
    OpenCode doesn't store any of your code or context data, making it ideal for sensitive projects.
  </Card>

  <Card title="Any Model, Any Provider" icon="plug">
    Connect to **75+ LLM providers** including Claude, GPT, Gemini, local models, and now Morpheus AI.
  </Card>

  <Card title="Multi-Platform" icon="window-maximize">
    Available as terminal interface, desktop app (macOS, Windows, Linux), and IDE extensions.
  </Card>
</CardGroup>

### Key Features

* **LSP Enabled**: Automatically loads the right Language Server Protocols for enhanced LLM understanding
* **Multi-Session**: Run multiple AI agents in parallel on the same project
* **Share Links**: Share session links for collaboration and debugging
* **Claude Pro Support**: Use your existing Claude Pro or Max subscription
* **400,000 Monthly Users**: Trusted by developers worldwide for production use

<Info>
  By integrating Morpheus AI with OpenCode, you get access to powerful open-source models with OpenCode's privacy-first architecture.
</Info>

## Overview

OpenCode supports multiple AI providers. By integrating Morpheus AI, you gain access to models optimized for code generation, reasoning, and development tasks.

<Info>
  **Base URL:** `https://api.mor.org/api/v1`
</Info>

## Prerequisites

Before you begin, ensure you have:

* **OpenCode** installed on your system [opencode.ai/docs](https://opencode.ai/docs#install)
* A **Morpheus AI account** at [app.mor.org](https://app.mor.org)
* Basic familiarity with **JSON configuration files**
* Access to your system's **terminal or command line**

<Steps>
  <Step title="Get Your Morpheus AI API Key">
    Visit [app.mor.org](https://app.mor.org) and create your API key.

    1. On the main page (API Keys) Click **Create New Key**
    2. Provide a descriptive name for the key
    3. Copy the generated API key (starts with `sk-`)

    <Warning>
      Store your API key securely. You won't be able to view it again after the initial creation. Never commit API keys to version control.
    </Warning>
  </Step>

  <Step title="Install OpenCode">
    If you haven't already, install OpenCode on your system:

    <Tabs>
      <Tab title="macOS">
        ```bash theme={null}
        brew install opencode
        ```
      </Tab>

      <Tab title="Linux">
        ```bash theme={null}
        curl -fsSL https://opencode.ai/install.sh | sh
        ```
      </Tab>

      <Tab title="Windows">
        ```powershell theme={null}
        irm https://opencode.ai/install.ps1 | iex
        ```
      </Tab>
    </Tabs>

    <Check>
      Verify installation by running `opencode --version` in your terminal.
    </Check>
  </Step>

  <Step title="Launch OpenCode">
    Start OpenCode for the first time:

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

    You're now ready to configure Morpheus AI as a provider.
  </Step>
</Steps>

## Configuring the Provider

Create your OpenCode configuration file to define the Morpheus AI provider and available models.

### Create the Configuration File

<Tabs>
  <Tab title="Global Configuration (Recommended)">
    Create the global configuration directory and file. This makes Morpheus AI available across all your projects.

    ```bash theme={null}
    # Create the config directory if it doesn't exist
    mkdir -p ~/.config/opencode

    # Create and open the config file
    nano ~/.config/opencode/opencode.json
    ```

    <Tip>
      You can use any text editor instead of `nano` (e.g., `vim`, `code`, or your preferred editor).
    </Tip>
  </Tab>

  <Tab title="Project Configuration">
    Create an `opencode.json` file in your project root. This makes Morpheus AI available only for the specific project.

    ```bash theme={null}
    # Navigate to your project directory
    cd /path/to/your/project

    # Create the config file
    nano opencode.json
    ```
  </Tab>
</Tabs>

### Full Provider Configuration

Copy and paste the following configuration into your `opencode.json` file:

```json opencode.json theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "morpheus-ai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Morpheus AI",
      "options": {
        "baseURL": "https://api.mor.org/api/v1"
      },
      "models": {
        "glm-4.7": {
          "name": "GLM 4.7",
          "limit": {
            "context": 198000,
            "output": 65536
          }
        },
        "glm-4.7:web": {
          "name": "GLM 4.7 (Web)",
          "limit": {
            "context": 198000,
            "output": 65536
          }
        },
        "glm-4.7-thinking": {
          "name": "GLM 4.7 Thinking",
          "limit": {
            "context": 198000,
            "output": 65536
          }
        },
        "glm-4.7-thinking:web": {
          "name": "GLM 4.7 Thinking (Web)",
          "limit": {
            "context": 198000,
            "output": 65536
          }
        },
        "gpt-oss-120b": {
          "name": "GPT OSS 120B",
          "limit": {
            "context": 128000,
            "output": 8192
          },
          "options": {
            "timeout": 600000
          }
        },
        "gpt-oss-120b:web": {
          "name": "GPT OSS 120B (Web)",
          "limit": {
            "context": 128000,
            "output": 8192
          },
          "options": {
            "timeout": 600000
          }
        },
        "qwen3-coder-480b-a35b-instruct": {
          "name": "Qwen3 Coder 480B",
          "limit": {
            "context": 256000,
            "output": 16384
          },
          "options": {
            "timeout": 600000
          }
        },
        "qwen3-coder-480b-a35b-instruct:web": {
          "name": "Qwen3 Coder 480B (Web)",
          "limit": {
            "context": 256000,
            "output": 16384
          },
          "options": {
            "timeout": 600000
          }
        },
        "glm-5.1": {
          "name": "GLM 5.1",
          "limit": {
            "context": 200000,
            "output": 65536
          }
        },
        "glm-5.1:web": {
          "name": "GLM 5.1 (Web)",
          "limit": {
            "context": 200000,
            "output": 65536
          }
        },
        "glm-5.1-non-thinking": {
          "name": "GLM 5.1 Non-Thinking",
          "limit": {
            "context": 200000,
            "output": 65536
          }
        },
        "glm-5.1-non-thinking:web": {
          "name": "GLM 5.1 Non-Thinking (Web)",
          "limit": {
            "context": 200000,
            "output": 65536
          }
        },
        "kimi-k2.6": {
          "name": "Kimi K2.6",
          "limit": {
            "context": 256000,
            "output": 16384
          }
        },
        "kimi-k2.6:web": {
          "name": "Kimi K2.6 (Web)",
          "limit": {
            "context": 256000,
            "output": 16384
          }
        },
        "glm-5.2": {
          "name": "GLM 5.2",
          "limit": {
            "context": 200000,
            "output": 65536
          }
        },
        "glm-5.2:web": {
          "name": "GLM 5.2 (Web)",
          "limit": {
            "context": 200000,
            "output": 65536
          }
        },
        "kimi-k2.7-code": {
          "name": "Kimi K2.7 Code",
          "limit": {
            "context": 256000,
            "output": 16384
          }
        },
        "kimi-k2.7-code:web": {
          "name": "Kimi K2.7 Code (Web)",
          "limit": {
            "context": 256000,
            "output": 16384
          }
        },
        "MiniMax-M2.7": {
          "name": "MiniMax M2.7",
          "limit": {
            "context": 198000,
            "output": 16384
          }
        },
        "MiniMax-M2.7:web": {
          "name": "MiniMax M2.7 (Web)",
          "limit": {
            "context": 198000,
            "output": 16384
          }
        },
        "deepseek-v4-pro": {
          "name": "DeepSeek V4 Pro",
          "limit": {
            "context": 1000000,
            "output": 16384
          }
        },
        "deepseek-v4-pro:web": {
          "name": "DeepSeek V4 Pro (Web)",
          "limit": {
            "context": 1000000,
            "output": 16384
          }
        },
        "deepseek-v4-flash": {
          "name": "DeepSeek V4 Flash",
          "limit": {
            "context": 1000000,
            "output": 16384
          }
        },
        "deepseek-v4-flash:web": {
          "name": "DeepSeek V4 Flash (Web)",
          "limit": {
            "context": 1000000,
            "output": 16384
          }
        }
      }
    }
  }
}
```

<Info>
  **Save the file:** If using `nano`, press `Ctrl+O` to save, then `Ctrl+X` to exit. If using `vim`, press `Esc` then type `:wq` and press Enter.
</Info>

### Understanding the Configuration

<AccordionGroup>
  <Accordion title="Provider Settings">
    * **npm**: The AI SDK package used (`@ai-sdk/openai-compatible` for OpenAI-compatible APIs)
    * **name**: Display name shown in the OpenCode UI
    * **options.baseURL**: The Morpheus AI API endpoint (`https://api.mor.org/api/v1`)
  </Accordion>

  <Accordion title="Model Configuration">
    Each model includes:

    * **name**: Human-readable model name displayed in the UI
    * **limit.context**: Maximum input tokens the model accepts
    * **limit.output**: Maximum tokens the model can generate
    * **options.timeout**: Optional timeout in milliseconds (used for large models)
  </Accordion>

  <Accordion title="Web Model Variants">
    Models with the `:web` suffix have enhanced capabilities:

    * Web search integration
    * Current information access
    * Browser-optimized responses

    Standard models without `:web` are optimized for pure reasoning and code generation tasks.
  </Accordion>
</AccordionGroup>

### Minimal Configuration

If you prefer a simpler setup with just one model to start:

```json opencode.json theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "morpheus-ai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Morpheus AI",
      "options": {
        "baseURL": "https://api.mor.org/api/v1"
      },
      "models": {
        "glm-4.7": {
          "name": "GLM 4.7"
        }
      }
    }
  }
}
```

<Tip>
  Start with a minimal configuration and add more models as needed. See the [Available Models](/documentation/models) page for the full list of models you can add.
</Tip>

## Adding Morpheus AI Credentials

OpenCode stores API credentials securely in `~/.local/share/opencode/auth.json`. Use the `/connect` command to add your Morpheus AI API key.

### Using the `/connect` Command

<Steps>
  <Step title="Launch OpenCode">
    Open your terminal and start OpenCode:

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

    This will open the OpenCode TUI (terminal user interface).
  </Step>

  <Step title="Execute the connect command">
    Inside OpenCode, run the connect command:

    ```
    /connect
    ```
  </Step>

  <Step title="Select Morpheus AI">
    Type `morpheus` to filter the providers, then select **Morpheus AI** from the list:

    ```
    ┌  Connect a provider
    │
    │  morpheus
    │
    │  Other
    │  Morpheus AI
    └
    ```
  </Step>

  <Step title="Enter your API key">
    Paste your Morpheus AI API key when prompted:

    ```
    ┌  Add credential
    │
    │ ◇  Enter your API key
    │  sk-xxxxxxxxxxxxx
    └
    ```
  </Step>

  <Step title="Select a model">
    Choose the model you want to use from the list. All models from your configuration will appear:

    ```
    ┌  Morpheus AI
    │
    │  Search
    │
    │  Morpheus AI
    │  GLM 4.7
    │  GLM 4.7 (Web)
    │  ● GLM 4.7 Thinking
    │  GLM 4.7 Thinking (Web)
    │  GPT OSS 120B
    └
    ```

    <Check>
      You're now connected to Morpheus AI and ready to start coding!
    </Check>
  </Step>
</Steps>

## Start Coding

With Morpheus AI configured, you can now:

* **Generate code** - Ask for implementations, algorithms, or functions
* **Debug issues** - Get help troubleshooting errors and bugs
* **Refactor code** - Request improvements and optimizations
* **Explain code** - Understand complex codebases
* **Write tests** - Generate test cases and test suites

```
> Create a Python function that validates email addresses using regex

> Debug this TypeScript error: Type 'number' is not assignable to type 'string'

> Refactor this code to use async/await instead of callbacks

> Explain how this binary search algorithm works
```

## Available Models

The following models are included in the configuration above:

| Model                    | Context | Output | Best For                                         |
| ------------------------ | ------- | ------ | ------------------------------------------------ |
| **GLM 5.2**              | 200K    | 65K    | Next-gen agentic engineering, complex reasoning  |
| **GLM 5.1**              | 200K    | 65K    | Agentic engineering, complex reasoning           |
| **GLM 5.1 Non-Thinking** | 200K    | 65K    | High-throughput inference, tool-use              |
| **GLM 4.7**              | 198K    | 65K    | General purpose, long context, documentation     |
| **GLM 4.7 Thinking**     | 198K    | 65K    | Extended thinking, analysis, reasoning           |
| **Kimi K2.7 Code**       | 256K    | 16K    | Code generation, agentic coding, parallel agents |
| **Kimi K2.6**            | 256K    | 16K    | Visual reasoning, agent workflows, math          |
| **MiniMax M2.7**         | 198K    | 16K    | Cost-efficient agents, tool orchestration        |
| **GPT OSS 120B**         | 128K    | 8K     | GPT-style responses, function calling            |
| **Qwen3 Coder 480B**     | 256K    | 16K    | Complex code generation, architecture design     |
| **Kimi K2 Thinking**     | 256K    | 16K    | Complex problem solving, multi-step reasoning    |

<Info>
  For additional models, see the [Available Models](/documentation/models) page. You can add any model from that page to your configuration by following the same format shown above.
</Info>

## Verifying Your Setup

### Check Authentication Status

Verify that your Morpheus AI credentials are stored correctly:

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

You should see `morpheus-ai` in the list of configured credentials.

<Check>
  If `morpheus-ai` appears in the list, your credentials are configured correctly.
</Check>

### Test the Connection

Start a conversation in OpenCode and ask a simple question:

```
> What is Python?
```

If you receive a response from the selected Morpheus AI model, your integration is working correctly!

## Troubleshooting

<AccordionGroup>
  <Accordion title="Models not appearing in OpenCode">
    **Cause**: Provider ID mismatch, configuration syntax error, or OpenCode not restarted.

    **Solution**:

    1. Verify the provider ID in both `/connect` and `opencode.json` exactly matches `morpheus-ai`
    2. Check that your JSON configuration is valid (no missing commas, brackets)
    3. Restart OpenCode completely
    4. Verify credentials with `opencode auth list`

    ```bash theme={null}
    # Validate JSON syntax
    cat ~/.config/opencode/opencode.json | python -m json.tool

    # Check credentials
    opencode auth list
    ```
  </Accordion>

  <Accordion title="Authentication errors when using models">
    **Cause**: Invalid or expired API key, or incorrect provider configuration.

    **Solution**:

    1. Ensure your API key is valid and active at [app.mor.org](https://app.mor.org)
    2. Verify the provider ID matches what you used in `/connect`
    3. Try regenerating your API key if needed
    4. Reconfigure credentials using `/connect` command

    ```bash theme={null}
    # Remove old credentials and reconfigure
    opencode auth remove morpheus-ai
    opencode
    /connect
    ```
  </Accordion>

  <Accordion title="Connection errors or timeouts">
    **Cause**: Network connectivity issues, firewall blocking, or service unavailability.

    **Solution**:

    1. Check your internet connection
    2. Verify the baseURL is correct: `https://api.mor.org/api/v1`
    3. Ensure your firewall allows HTTPS connections
    4. Check the Morpheus AI service status

    For large models like Qwen3 Coder 480B and Hermes 3 Llama 405B, timeouts are pre-configured to 600000ms (10 minutes). If you still experience timeouts, consider using a smaller model or checking your network connection.
  </Accordion>

  <Accordion title="Slow response times">
    **Cause**: Large model selected, high marketplace demand, or network latency.

    **Solution**:

    * Use smaller models for quick tasks (e.g., `llama-3.3-70b`, `hermes-4-14b`)
    * Configure a `small_model` in your `opencode.json` for rapid iterations
    * Try different models to find the best balance of performance and speed
    * Check your network latency to the Morpheus API

    ```json theme={null}
    {
      "model": "morpheus-ai/qwen3-coder-480b-a35b-instruct",
      "small_model": "morpheus-ai/hermes-4-14b"
    }
    ```
  </Accordion>

  <Accordion title="Configuration file not found or ignored">
    **Cause**: Wrong file location or OpenCode not looking in the right directory.

    **Solution**:

    1. For global configuration: `~/.config/opencode/opencode.json`
    2. For project-specific: `./opencode.json` in your project root
    3. Ensure the file has correct permissions
    4. Verify JSON syntax is valid

    ```bash theme={null}
    # Create config directory if missing
    mkdir -p ~/.config/opencode

    # Set proper permissions
    chmod 644 ~/.config/opencode/opencode.json
    ```
  </Accordion>
</AccordionGroup>

## Security Notes

<Warning>
  Follow these security best practices to protect your API credentials:
</Warning>

* **Local storage**: Your API key is stored locally in `~/.local/share/opencode/auth.json`
* **Never commit keys**: Don't commit API keys or configuration files with credentials to public repositories
* **Rotate compromised keys**: If your API key is compromised, immediately rotate it via the Morpheus AI dashboard

## Additional Resources

<CardGroup cols={2}>
  <Card title="Morpheus AI Portal" icon="portal" href="https://app.mor.org">
    Manage your API keys, view usage, and access your Morpheus AI account.
  </Card>

  <Card title="API Documentation" icon="book" href="/api-reference/introduction">
    Complete reference documentation for the Morpheus Inference API.
  </Card>

  <Card title="OpenCode Documentation" icon="code" href="https://opencode.ai/docs/providers">
    Learn more about OpenCode provider configuration and advanced features.
  </Card>

  <Card title="Available Models" icon="sparkles" href="/documentation/models">
    See all available models and their capabilities.
  </Card>
</CardGroup>

## Summary

You've successfully integrated Morpheus AI with OpenCode! Here's what you've accomplished:

<Check>
  **Credentials configured**: Added your Morpheus AI API key securely to OpenCode
</Check>

<Check>
  **Provider setup**: Configured the Morpheus AI provider with access to powerful coding models
</Check>

<Check>
  **Model selection**: Learned how to choose and switch between models for different tasks
</Check>

Happy coding with Morpheus AI!
