OpenCode

Tutorial for configuring OpenCode to use Cast AI Serverless Endpoints for AI-assisted coding with models like Qwen 3 Coder.

This tutorial walks you through using Cast AI's Serverless Endpoints with OpenCode, an agentic coding tool. You'll configure OpenCode to use Qwen 3 Coder for code execution while using Claude for planning, giving you a cost-effective setup for AI-assisted development.

Overview

By the end of this tutorial, you'll be able to:

  • Configure OpenCode to recognize AI Enabler as a model provider
  • Use Qwen 3 Coder Next for code generation and execution tasks
  • Set up a multi-model workflow that uses different models for different tasks

This tutorial is intended for developers familiar with command-line tools and JSON configuration files. It assumes basic knowledge of how LLM-based coding assistants work.

Prerequisites

Before starting, ensure you have:

  1. A Cast AI API key — Generate one from the Cast AI console under AI Enabler > Overview

  2. OpenCode installed — Install from opencode.ai or run the following in your terminal:

    curl -fsSL https://opencode.ai/install | bash
📘

Note

Claude Code integration is coming soon. This tutorial focuses on OpenCode, but Serverless Endpoints work with any OpenAI-compatible client.

Step 1: Create the OpenCode configuration file

OpenCode needs a configuration file to recognize AI Enabler as a provider. Create or edit the config file at ~/.config/opencode/opencode.json. There are other, more granular options for working with OpenCode config files. You can find more details in OpenCode documentation.

New to terminal and config files? Start here.

OpenCode stores its configuration in a JSON file at a specific location on your system. If this is your first time using OpenCode, neither the folder nor the file will exist yet — you need to create both manually.

1. Create the config directory

The directory ~/.config/opencode/ is where OpenCode looks for its config. The ~ is shorthand for your home folder (for example, /Users/yourname on macOS). Run this command to create the directory:

  mkdir -p ~/.config/opencode

The -p flag tells mkdir to create any missing parent folders along the way, so this works even if ~/.config/ doesn't exist yet.

2. Create the config file

Once the directory exists, create an empty JSON file inside it:

  touch ~/.config/opencode/opencode.json

3. Open the file for editing

Open the file in a text editor. If you're comfortable in the terminal, use nano or vim:

  nano ~/.config/opencode/opencode.json

If you prefer a graphical editor, you can open the file from your editor's File > Open menu and navigate to ~/.config/opencode/opencode.json, or run:

  open -a "Visual Studio Code" ~/.config/opencode/opencode.json

4. Paste the configuration

Copy the JSON configuration from the step below and paste it into the file. Save and close when done (Ctrl+O, then Ctrl+X in nano).

5. Verify the file exists

Confirm everything is in place:

  ls ~/.config/opencode

You should see opencode.json listed.

The following configuration sets up two providers: Anthropic (for planning tasks) and AI Enabler (for code execution). This lets you use Claude for high-level reasoning while using Qwen 3 Coder for the actual code generation, which is more cost-effective for high-volume coding tasks.

{
  "$schema": "https://opencode.ai/config.json",
  "permission": {
    "*": "ask"
  },
  "model": "ai-enabler/qwen3-coder-next-fp8",
  "mode": {
    "plan": {
      "model": "anthropic/claude-opus-4-5-20251101"
    },
    "build": {
      "model": "ai-enabler/qwen3-coder-next-fp8"
    }
  },
  "provider": {
    "anthropic": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Anthropic through AI Enabler",
      "options": {
        "baseURL": "https://llm.cast.ai/openai/v1",
        "apiKey": "$YOUR_CASTAI_API_KEY"
      },
      "models": {
        "claude-opus-4-5-20251101": {
          "name": "claude-opus-4-5-20251101",
          "tool_call": true
        }
      }
    },
     "ai-enabler": {
       "npm": "@ai-sdk/openai-compatible",
       "name": "AI Enabler by Cast AI",
       "options": {
         "baseURL": "https://llm.cast.ai/openai/v1",
         "apiKey": "$YOUR_CASTAI_API_KEY"
       },
       "models": {
         "qwen3-coder-next-fp8": {
           "name": "qwen3-coder-next-fp8",
           "tool_call": true,
           "reasoning": false,
           "limit": {
             "context": 200000,
             "output": 45760
           }
         }
       }
     }
  }
}

Replace $YOUR_CASTAI_API_KEY with the API key you generated from the Cast AI console.

Step 2: Verify your configuration

Open a terminal, navigate to a project directory, and start OpenCode:

cd ~/your-project
opencode

Try a simple prompt to verify the connection is working:

What security risks can you identify in this project?

OpenCode will use Claude for planning the analysis and Qwen 3 Coder for code review.

Advanced: Multi-agent orchestration with GSD

For more complex workflows, you can use the Get Shit Done (GSD) framework to orchestrate multiple agents with different models assigned to each task type.

Install GSD:

npx gsd-opencode

Then update your opencode.json to include agent-specific model assignments:

{
  "$schema": "https://opencode.ai/config.json",
  "permission": {
    "*": "ask"
  },
  "model": "ai-enabler/qwen3-coder-next-fp8",
  "mode": {
    "plan": {
      "model": "anthropic/claude-opus-4-5-20251101"
    },
    "build": {
      "model": "ai-enabler/qwen3-coder-next-fp8"
    }
  },
  "provider": {
    "anthropic": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Anthropic through AI Enabler",
      "options": {
        "baseURL": "https://llm.cast.ai/openai/v1",
        "apiKey": "$YOUR_CASTAI_API_KEY"
      },
      "models": {
        "claude-opus-4-5-20251101": {
          "name": "claude-opus-4-5-20251101",
          "tool_call": true
        }
      }
    },
     "ai-enabler": {
       "npm": "@ai-sdk/openai-compatible",
       "name": "AI Enabler by Cast AI",
       "options": {
         "baseURL": "https://llm.cast.ai/openai/v1",
         "apiKey": "$YOUR_CASTAI_API_KEY"
       },
       "models": {
         "qwen3-coder-next-fp8": {
           "name": "qwen3-coder-next-fp8",
           "tool_call": true,
           "reasoning": false,
           "limit": {
             "context": 200000,
             "output": 45760
          }
        }
      }
    }
  },
  "agent": {
    "gsd-planner": { "model": "anthropic/claude-sonnet-4-5-20250929" },
    "gsd-plan-checker": { "model": "anthropic/claude-sonnet-4-5-20250929" },
    "gsd-phase-researcher": { "model": "anthropic/claude-sonnet-4-5-20250929" },
    "gsd-roadmapper": { "model": "anthropic/claude-sonnet-4-5-20250929" },
    "gsd-project-researcher": { "model": "anthropic/claude-sonnet-4-5-20250929" },
    "gsd-research-synthesizer": { "model": "anthropic/claude-sonnet-4-5-20250929" },
    "gsd-codebase-mapper": { "model": "anthropic/claude-sonnet-4-5-20250929" },
    "gsd-executor": { "model": "ai-enabler/qwen3-coder-next-fp8" },
    "gsd-debugger": { "model": "ai-enabler/qwen3-coder-next-fp8" },
    "gsd-verifier": { "model": "anthropic/claude-sonnet-4-5-20250929" },
    "gsd-integration-checker": { "model": "anthropic/claude-sonnet-4-5-20250929" },
    "gsd-set-profile": { "model": "anthropic/claude-sonnet-4-5-20250929" },
    "gsd-settings": { "model": "anthropic/claude-sonnet-4-5-20250929" },
    "gsd-set-model": { "model": "anthropic/claude-sonnet-4-5-20250929" }
  }
}

This configuration uses Claude for planning, research, and verification tasks, while Qwen 3 Coder handles actual code execution and debugging. This balances cost efficiency with quality. Reasoning-heavy tasks go to Claude, while high-volume code generation uses the more economical Qwen model.

You can also configure GSD interactively by running /gsd-settings within OpenCode.

Next steps