Features
- Type-safe API: Full TypeScript support with auto-generated types from OpenAPI specification
- Server Management: Start and manage OpenCode server instances programmatically
- Session Control: Create, manage, and interact with AI coding sessions
- Real-time Events: Subscribe to server-sent events for live updates
- File Operations: Search, read, and manage project files
- Configuration: Programmatically configure models, agents, and providers
- Plugin Development: Build custom tools and extensions
Installation
Install the SDK from npm:Quick Start
Server + Client
Create a complete OpenCode instance with both server and client:Client Only
Connect to an existing OpenCode server:Architecture
The SDK is organized into several namespaces:- global: Server health and global events
- session: Session management and AI interactions
- project: Project information and navigation
- config: Configuration management
- file/find: File operations and search
- app: Application-level operations
- tui: Terminal UI control
- auth: Authentication management
- event: Real-time event subscriptions
Common Use Cases
Build Integrations
Connect OpenCode to other tools, CI/CD pipelines, or custom workflows:Automate Testing
Generate tests programmatically:Custom Dashboards
Build monitoring dashboards with real-time updates:Extract Structured Data
Use structured output to extract information:Type Safety
All API responses and request parameters are fully typed:Error Handling
Handle errors gracefully:Next Steps
Client API
Learn about client creation and configuration
Configuration
Configure OpenCode programmatically
Types
Explore TypeScript types and interfaces
Plugin Development
Build custom tools and extensions