OpenCode

OpenCode is an open-source AI coding agent with terminal, IDE, and desktop interfaces. It supports custom OpenAI-compatible providers via the @ai-sdk/openai-compatible package, so it works with private-gpt out of the box.

Compatibility

FeatureStatusNotes
Chat & streaming
Tool use / function callingModel-dependent
File tools (read, write, edit)Managed by OpenCode
MCP serversConfigured in OpenCode
Multi-session agents
ImagesNot supported

Prerequisites


Run

private-gpt run generates a config file at ~/.config/opencode/private-gpt.json, sets OPENCODE_CONFIG to point at it, and launches OpenCode:

$private-gpt run opencode

The server is started automatically if it is not already running. Pass --no-server to skip that check when the server is managed externally.

With a specific model:

$private-gpt run opencode --model my-model

On first launch, press Ctrl+PSwitch Model → select the model under PrivateGPT.


Manual setup

If you prefer to manage the configuration yourself:

1. Create the config file

Create ~/.config/opencode/private-gpt.json (a separate file to avoid overriding your default OpenCode config):

1{
2 "$schema": "https://opencode.ai/config.json",
3 "provider": {
4 "private-gpt": {
5 "npm": "@ai-sdk/openai-compatible",
6 "name": "PrivateGPT",
7 "options": {
8 "baseURL": "http://localhost:8080/v1",
9 "apiKey": "secret-key"
10 },
11 "models": {
12 "default": {
13 "name": "PrivateGPT - default",
14 "limit": {
15 "context": 8096,
16 "output": 1024
17 }
18 }
19 }
20 }
21 }
22}

Replace secret-key with the value of server.auth.secret from your private-gpt settings. If auth is disabled, any non-empty string works.

2. Launch with the custom config

$export OPENCODE_CONFIG=~/.config/opencode/private-gpt.json
$opencode

On first launch, press Ctrl+PSwitch Model → select the model under PrivateGPT.