Skip to main content

Overview

OpenCode is a fully open-source AI coding agent built with TypeScript and AI SDK, offering terminal TUI, IDE integration, and desktop applications. The project has 94.9k+ stars on GitHub with an active community. By configuring APIYI service, you can get:

🖥️ Multi-Platform Support

Terminal TUI, VS Code extension, and desktop apps

🔌 75+ Model Support

Supports 75+ LLM providers via Models.dev

🛠️ Built-in LSP

Language Server Protocol support for intelligent code understanding

🔄 Multi-Session Parallel

Parallel session processing and session sharing
Project Info: OpenCode is an actively maintained open-source project. Website: opencode.ai, Repository: github.com/anomalyco/opencode.

Prerequisites

Install OpenCode

Verify installation:

Quick Configuration

OpenCode uses JSON configuration files with multiple config locations (priority from low to high):
  1. Remote config (.well-known/opencode)
  2. Global config: ~/.config/opencode/opencode.json
  3. Custom config: path specified by OPENCODE_CONFIG environment variable
  4. Project config: opencode.json in project root
  5. .opencode directory config
  6. Inline config: OPENCODE_CONFIG_CONTENT environment variable
Create or edit the config file ~/.config/opencode/opencode.json:
Then set the environment variable:

Method 2: /connect Command Authentication

OpenCode provides the /connect command to quickly connect new providers:
  1. After starting OpenCode, type /connect
  2. Select “Other”
  3. Enter provider ID (e.g., apiyi)
  4. Enter API key
Then add the provider and models definition in the config file to use.

Method 3: Override Existing Provider

For quick setup, override the built-in OpenAI provider’s baseURL:

Method 4: Project-Level Configuration

Create opencode.json in your project root for project-specific settings:

Agent System

OpenCode has three built-in agents, each with specific purposes:

Agent Model Configuration

Configure different models for different agents:
OpenCode supports 400+ AI models through APIYI. Choose the right model for different tasks.

View Programming Model Recommendations

Check the latest programming model recommendations, performance comparisons, and usage suggestions. Includes top-tier models, cost-effective options, and reasoning-enhanced models.

Scenario-Based Model Recommendations

Core Features

Terminal Interactive Interface

Start OpenCode to enter the interactive TUI:

File Operations

OpenCode can read, search, and modify project files:

Command Execution

Execute commands in the terminal and view results:

Session Management

  • Multi-session parallel: Run multiple sessions simultaneously
  • Session sharing: Export and share sessions
  • Auto-save: All sessions are automatically persisted
  • Context retention: Maintain complete conversation context during sessions

Usage Tips

1. Keyboard Shortcuts

2. Common Commands

3. Invoke Sub-Agent

Use @general to invoke the search sub-agent for complex queries:

4. Incremental Development

Troubleshooting

  1. Check if environment variable is set correctly:
  1. Verify baseURL in configuration file:
  1. Test API connectivity:
Verify the model ID is correct. Check the APIYI console for supported models.Common model IDs:
  • claude-sonnet-4-20250514
  • gpt-4.1
  • deepseek-chat
  • gemini-2.5-pro-preview-05-06
Configuration file loading priority (from low to high):
  1. Remote config (.well-known/opencode)
  2. Global config: ~/.config/opencode/opencode.json
  3. OPENCODE_CONFIG environment variable
  4. Project config: opencode.json
  5. .opencode directory config
  6. OPENCODE_CONFIG_CONTENT environment variable
Ensure the config file is in the correct location with valid JSON format.
  1. Try using a lighter model (e.g., GPT-4.1 Mini)
  2. Reduce context length, start a new session
  3. Check network connection stability

Best Practices

1. Model Selection Strategy

2. Effective Prompts

3. Security Considerations

  • Don’t hardcode API keys in code
  • Use environment variables to manage sensitive information
  • Review AI-generated code, especially security-related parts
  • Be careful not to let AI execute dangerous system commands

4. Cost Control

  • Configure different models for different agents (strong models for build, lightweight for general)
  • Use lightweight models for simple tasks
  • Regularly check APIYI console to monitor usage

Alternatives

If OpenCode doesn’t meet your needs, consider these tools:

Claude Code

Anthropic’s official terminal programming assistant

Codex CLI

OpenAI’s official command-line tool

Gemini CLI

Google’s official terminal programming assistant

Roo Code

VS Code AI programming extension

APIYI Console

Manage API keys and view usage

Model Recommendations

View programming scenario model recommendations