Overview
Theserve command starts a headless HTTP server that provides API access to OpenCode functionality without the TUI interface. This is ideal for:
- Programmatic API access
- Running on remote servers
- Integrating with other tools
- Avoiding MCP server cold boot times
Usage
127.0.0.1:0 (random port) by default. Use flags to customize the network settings.
Options
Port to listen on. Default is
0 (random available port).Hostname to listen on. Use
0.0.0.0 to allow external connections.Enable mDNS service discovery. When enabled, defaults hostname to
0.0.0.0.Custom domain name for mDNS service.
Additional browser origins to allow for CORS. Can be specified multiple times.
Examples
Basic Server
Start a local server on a random port:Fixed Port
Start server on port 4096:Network-Accessible Server
Allow connections from other machines:With mDNS Discovery
Enable service discovery on local network:Custom CORS Origins
Allow specific origins for web access:Authentication
Enable HTTP basic authentication by setting environment variables:opencode):
Using with Run Command
You can attach to a runningserve instance to avoid MCP server cold boot times:
API Access
The server exposes a full HTTP API. See the Server API documentation for details on available endpoints. Basic example using the JavaScript SDK:Configuration
You can set default server options in your global configuration file (~/.config/opencode/config.json):
Related Commands
web
Start server with web interface
attach
Attach TUI to running server
run
Run commands non-interactively
Server API
View full HTTP API documentation