Skip to main content

Overview

OpenCode is an open-source AI coding assistant that runs in your terminal. It supports multiple LLM providers and can be configured to use LemonData’s API for access to 300+ models.

Installation

curl -fsSL https://opencode.ai/install | bash
Verify installation:
opencode --version

Configuration

Step 1: Set Environment Variables

export OPENAI_API_KEY="sk-your-lemondata-key"
export LOCAL_ENDPOINT="https://api.lemondata.cc/v1"
For permanent configuration, add to ~/.bashrc or ~/.zshrc:
echo 'export OPENAI_API_KEY="sk-your-lemondata-key"' >> ~/.zshrc
echo 'export LOCAL_ENDPOINT="https://api.lemondata.cc/v1"' >> ~/.zshrc
source ~/.zshrc

Step 2: Configure OpenCode

Create or edit ~/.config/opencode/opencode.json (global) or opencode.json in your project root:
{
  "provider": {
    "openai": {
      "options": {
        "apiKey": "sk-your-lemondata-key",
        "baseURL": "https://api.lemondata.cc/v1"
      }
    }
  },
  "model": "gpt-4o",
  "agent": {
    "coder": {
      "model": "gpt-4o"
    }
  }
}

Basic Usage

Start interactive mode:
opencode
Run with a prompt:
opencode "Explain this codebase"
Specify model:
opencode --model gpt-4o "Fix the bugs in main.py"

Available Models

ModelBest For
gpt-4oComplex tasks, code architecture
gpt-4o-miniQuick fixes, simple queries
claude-sonnet-4-5Code review, documentation
claude-opus-4-5Complex reasoning
gemini-2.5-flashFast responses
deepseek-r1Algorithm design

Common Commands

Analyze code:
opencode "What does this function do?" < src/utils.ts
Generate code:
opencode "Create a REST API with Express"
Review changes:
git diff | opencode "Review these changes"
Fix errors:
opencode "Fix the TypeScript errors in this project"

Interactive Commands

CommandDescription
/helpShow available commands
/model <name>Switch to a different model
/clearClear conversation history
/exitExit OpenCode

Troubleshooting

  • Verify LOCAL_ENDPOINT is set to https://api.lemondata.cc/v1
  • Check network connectivity
  • Try curl https://api.lemondata.cc/v1/models to test
  • Verify OPENAI_API_KEY environment variable is set
  • Check that the key starts with sk-
  • Ensure the key is active in LemonData dashboard

Best Practices

Run OpenCode from your project root for better understanding of your codebase.
Use faster models (gpt-4o-mini) for simple tasks, powerful models (gpt-4o, claude) for complex ones.
Always review AI-generated code before applying changes to your project.