Skip to main content

Overview

Type: Coding ToolPrimary Path: OpenAI-compatibleSupport Confidence: Supported path
OpenCode is an open-source AI coding assistant that runs in your terminal. It supports multiple LLM providers and can be configured to use AI Sonar’s API for access to hundreds of models.

Installation

Verify installation:

Configuration

Step 1: Set Environment Variables

For permanent configuration, add to ~/.bashrc or ~/.zshrc:

Step 2: Configure OpenCode

OpenCode’s current docs recommend configuring providers through opencode.json or opencode.jsonc. For AI Sonar, use a custom provider instead of overloading the built-in openai provider:
Use @ai-sdk/openai-compatible for chat-completions style compatibility. If you specifically need a provider path built on /v1/responses, OpenCode’s provider docs recommend switching the package to @ai-sdk/openai.

Basic Usage

Start interactive mode:
Run with a prompt:
Specify model:

Available Models

Common Commands

Analyze code:
Generate code:
Review changes:
Fix errors:

Interactive Commands

Troubleshooting

  • Verify options.baseURL is set to https://api.aisonar.dev/v1
  • Check network connectivity
  • Try curl https://api.aisonar.dev/v1/models to test
  • Verify OPENAI_API_KEY environment variable is set
  • Verify options.apiKey references {env:OPENAI_API_KEY} or another valid secret source
  • Check that the key starts with sk-
  • Ensure the key is active in AI Sonar dashboard

Best Practices

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