Skip to content

CodeBuddy Code HTTP API Beta

Beta: This API is in Beta. Interfaces may be adjusted. Feedback is welcome.

CodeBuddy Code provides two public interface sets for developers building Agent applications:

  • REST API (/api/v1/*) — Stateless HTTP request/response, suitable for webhook integration, management operations, and simple queries
  • ACP (/api/v1/acp) — Stateful streaming protocol (JSON-RPC over SSE), suitable for building full Agent client applications

Quick Start

Starting the HTTP Service

bash
codebuddy --serve --port 8080 --session-id my-session

API Documentation (Swagger UI)

Once the service is running, visit:

  • Interactive docs: http://127.0.0.1:8080/api/docs
  • OpenAPI spec: http://127.0.0.1:8080/api/openapi.json

Swagger UI provides an interactive testing interface for all public endpoints.

Verify the Service

bash
curl http://127.0.0.1:8080/api/v1/health
# {"data":{"status":"ok","uptime":12.3,"platforms":["generic","wecom","wechat-kf"]}}

API Layers

LayerRoute PrefixCompatibility PromiseDescription
Public REST API/api/v1/*Semantic versioning, no breaking changesCovered in this document
Public ACP Protocol/api/v1/acpFollows ACP specificationFull conversation capabilities, see ACP Documentation
Internal RPC/internal/*No compatibility guaranteeFor internal CLI use, not publicly available

Authentication

Two modes are supported (controlled by environment variable CODEBUDDY_GATEWAY_AUTH):

ModeValueDescription
No authenticationnone (default)For local development, no authentication required
Password authenticationpasswordAutomatically enabled for remote access

Password authentication supports the following methods (any one passing is sufficient):

bash
# Bearer Token
curl -H "Authorization: Bearer YOUR_PASSWORD" http://host:port/api/v1/sessions

# URL parameter
curl http://host:port/api/v1/sessions?password=YOUR_PASSWORD

Response Format

All /api/v1/* endpoints use a unified envelope format:

jsonc
// Success
{
    "data": { ... }
}

// Error
{
    "error": {
        "code": "AUTH_REQUIRED",      // Machine-readable error code
        "message": "Authentication required"  // Human-readable description
    }
}

Endpoint Overview

System

MethodEndpointDescription
GET/api/v1/healthHealth check
GET/api/v1/infoEnvironment info (version, OS, CWD, etc.)
GET/api/v1/metricsSystem resource metrics + instance process metrics
GET/api/v1/envsEnvironment variables (aligned with E2B envd)

Authentication

MethodEndpointDescription
GET/api/v1/auth/statusGet authentication status
POST/api/v1/auth/loginPassword login, returns token

Runs (Agent Execution)

MethodEndpointDescription
POST/api/v1/runsInitiate Agent execution (async, returns runId)
GET/api/v1/runs/:runIdQuery execution status
GET/api/v1/runs/:runId/streamSSE streaming of execution results
POST/api/v1/runs/:runId/cancelCancel execution

Webhooks (Third-party Platform Integration)

MethodEndpointDescription
GET/api/v1/webhooks/:platformPlatform URL verification (WeCom, etc.)
POST/api/v1/webhooks/:platformPlatform message webhook entry

Supported platforms: generic, wecom (WeCom), wechat-kf (WeChat Customer Service)

Sessions

MethodEndpointDescription
GET/api/v1/sessionsGet session list (supports cwd query parameter)
DELETE/api/v1/sessions/:idDelete session
POST/api/v1/sessions/:id/renameRename session
GET/api/v1/sessions/across-projects⚠️ Deprecated, use GET /api/v1/sessions?cwd=* instead
GET/api/v1/sessions/workspaces⚠️ Deprecated

PTY (Terminal)

MethodEndpointDescription
POST/api/v1/ptyCreate PTY session
GET/api/v1/ptyList PTY sessions
GET/api/v1/pty/:idQuery PTY session
DELETE/api/v1/pty/:idDestroy PTY session
GET/api/v1/pty/:id/outputSSE streaming of PTY output (replaces WebSocket)
POST/api/v1/pty/:id/input/sendSend PTY input (aligned with E2B Process.SendInput)
POST/api/v1/pty/:id/resizeResize PTY (aligned with E2B Process.Update)
WebSocket/api/v1/pty/:id/wsPTY bidirectional data transport (legacy compatible)

Workers & Daemon

A Worker is a running CLI process (interactive / bg / daemon), managed through a PID file registry.

MethodEndpointDescription
GET/api/v1/workersGet all active Worker list
POST/api/v1/workersManually add remote Worker
GET/api/v1/workers/:idGet Worker details (by PID or name)
GET/api/v1/workers/:id/logsGet Worker logs (supports multiple types)
DELETE/api/v1/workers/:idTerminate Worker process
GET/api/v1/daemon/statusQuery Daemon status
POST/api/v1/daemon/startStart Daemon
POST/api/v1/daemon/stopStop Daemon
POST/api/v1/daemon/restartRestart Daemon

Workers query parameters:

  • ?kind=bg — Filter by type (interactive / bg / daemon / daemon-worker)
  • ?local=true — Return local Workers only (used for remote proxy calls)

Log type parameters (GET /api/v1/workers/:id/logs):

  • ?type=telemetry — Telemetry logs (~/.codebuddy/logs/{date}/)
  • ?type=process — Process stdout/stderr (bg/daemon logs)
  • ?type=debug — Debug logs (~/.codebuddy/debug/, requires --debug)
  • ?type=transcript — Conversation history summary
  • ?tail=200 — Return only the last N lines
  • When type is omitted, the best source is automatically selected (telemetry > process > debug > transcript)

Channels (Remote Control)

MethodEndpointDescription
GET/api/v1/channelsGet client list
POST/api/v1/channels/:type/:id/startStart client
POST/api/v1/channels/:type/:id/stopStop client
POST/api/v1/channels/wechatCreate WeChat instance
POST/api/v1/channels/wecomCreate WeCom instance

Filesystem (E2B Compatible)

File content operations (aligned with E2B envd HTTP endpoints):

MethodEndpointDescription
GET/api/v1/files/download?path=...Download file (aligned with E2B envd GET /files)
POST/api/v1/files/upload?path=...Upload file (aligned with E2B envd POST /files)
POST/api/v1/files/composeCompose multiple files (aligned with E2B envd POST /files/compose)

File operations (aligned with E2B filesystem.proto):

MethodEndpointDescription
POST/api/v1/fs/statGet file/directory info (aligned with Filesystem.Stat)
POST/api/v1/fs/listList directory contents (aligned with Filesystem.ListDir)
POST/api/v1/fs/mkdirCreate directory (aligned with Filesystem.MakeDir)
POST/api/v1/fs/removeRemove file/directory (aligned with Filesystem.Remove)
POST/api/v1/fs/moveMove/rename (aligned with Filesystem.Move)

File watching (aligned with E2B filesystem.proto):

MethodEndpointDescription
POST/api/v1/fs/watchStreaming directory watch SSE (aligned with Filesystem.WatchDir)
POST/api/v1/fs/watcher/createCreate watcher (aligned with Filesystem.CreateWatcher)
POST/api/v1/fs/watcher/eventsGet watcher events (aligned with Filesystem.GetWatcherEvents)
POST/api/v1/fs/watcher/removeRemove watcher (aligned with Filesystem.RemoveWatcher)

CBC enhancements:

MethodEndpointDescription
GET/api/v1/fs/search?query=...Fuzzy file search (based on ripgrep, no E2B equivalent)

Process Management (E2B Compatible)

Aligned with E2B process.proto, mapping gRPC methods to REST endpoints:

MethodEndpointDescription
POST/api/v1/process/startStart process (aligned with Process.Start, supports SSE/JSON)
GET/api/v1/process/listList running processes (aligned with Process.List)
POST/api/v1/process/connectConnect to process SSE stream (aligned with Process.Connect)
POST/api/v1/process/input/sendSend stdin (aligned with Process.SendInput)
POST/api/v1/process/input/streamStream stdin (aligned with Process.StreamInput)
POST/api/v1/process/signal/sendSend signal (aligned with Process.SendSignal)
POST/api/v1/process/stdin/closeClose stdin (aligned with Process.CloseStdin)
POST/api/v1/process/updateUpdate process config such as PTY resize (aligned with Process.Update)

ACP (Agent Client Protocol)

MethodEndpointDescription
POST/api/v1/acp/connectEstablish ACP connection, returns connectionId and sessionToken
GET/api/v1/acpSSE notification subscription (requires acp-connection-id Header)
POST/api/v1/acpSend JSON-RPC requests (newSession, prompt, cancelRun, etc.)
DELETE/api/v1/acpDisconnect

File Changes (Checkpoint)

MethodEndpointDescription
GET/api/v1/file-changes/diff?path=...Get diff content for a single file
GET/api/v1/file-changes/checkpointsList checkpoints available for rollback
POST/api/v1/file-changes/revertRevert file changes or rollback to a checkpoint

Plugin Management

MethodEndpointDescription
GET/api/v1/pluginsList installed plugins
POST/api/v1/pluginsInstall plugin
POST/api/v1/plugins/validateValidate plugin/marketplace manifest file
POST/api/v1/plugins/enableEnable plugin
POST/api/v1/plugins/disableDisable plugin
POST/api/v1/plugins/uninstallUninstall plugin
GET/api/v1/plugins/marketplacesList configured plugin marketplaces
POST/api/v1/plugins/marketplacesAdd plugin marketplace
POST/api/v1/plugins/marketplaces/browseBrowse available plugins in marketplace
DELETE/api/v1/plugins/marketplaces/:nameDelete plugin marketplace

Settings Management

MethodEndpointDescription
GET/api/v1/settingsList all settings
GET/api/v1/settings/:keyGet a single setting value
PUT/api/v1/settings/:keySet a setting value
POST/api/v1/settings/:key/itemsAppend values to an array-type setting
POST/api/v1/settings/:key/removeRemove values from an array-type setting

Task Templates

MethodEndpointDescription
GET/api/v1/tasks/templatesGet task templates
POST/api/v1/tasks/templates/refreshRefresh (trigger AI recommendations)

Usage Examples

Health Check

bash
curl http://127.0.0.1:8080/api/v1/health

Initiate Agent Execution

bash
# Send message
curl -X POST http://127.0.0.1:8080/api/v1/runs \
  -H "Content-Type: application/json" \
  -d '{"text": "Help me analyze code performance", "sender": {"id": "dev", "name": "Developer"}}'

# Response: {"data": {"runId": "uuid-xxx", "status": "accepted"}}

# Get results via SSE stream
curl http://127.0.0.1:8080/api/v1/runs/uuid-xxx/stream

PTY Terminal Management

bash
# Create terminal
curl -X POST http://127.0.0.1:8080/api/v1/pty \
  -H "Content-Type: application/json" \
  -d '{"cols": 120, "rows": 40}'

# List terminals
curl http://127.0.0.1:8080/api/v1/pty

# SSE streaming output (replaces WebSocket)
curl http://127.0.0.1:8080/api/v1/pty/SESSION_ID/output

# Send input
curl -X POST http://127.0.0.1:8080/api/v1/pty/SESSION_ID/input/send \
  -H "Content-Type: application/json" \
  -d '{"data": "ls -la\n"}'

# Resize
curl -X POST http://127.0.0.1:8080/api/v1/pty/SESSION_ID/resize \
  -H "Content-Type: application/json" \
  -d '{"cols": 200, "rows": 50}'

# Destroy terminal
curl -X DELETE http://127.0.0.1:8080/api/v1/pty/SESSION_ID

Filesystem Operations (E2B Compatible)

bash
# Download file
curl "http://127.0.0.1:8080/api/v1/files/download?path=/tmp/test.txt"

# Upload file
curl -X POST "http://127.0.0.1:8080/api/v1/files/upload?path=/tmp/upload.txt" \
  -H "Content-Type: application/octet-stream" \
  --data-binary @local-file.txt

# Get file info
curl -X POST http://127.0.0.1:8080/api/v1/fs/stat \
  -H "Content-Type: application/json" \
  -d '{"path": "/tmp"}'

# List directory
curl -X POST http://127.0.0.1:8080/api/v1/fs/list \
  -H "Content-Type: application/json" \
  -d '{"path": "/tmp", "depth": 2}'

# Create directory
curl -X POST http://127.0.0.1:8080/api/v1/fs/mkdir \
  -H "Content-Type: application/json" \
  -d '{"path": "/tmp/new-dir"}'

# Fuzzy file search (CBC enhancement)
curl "http://127.0.0.1:8080/api/v1/fs/search?query=component&limit=10"

Process Management (E2B Compatible)

bash
# Start process (JSON mode)
curl -X POST http://127.0.0.1:8080/api/v1/process/start \
  -H "Content-Type: application/json" \
  -d '{"process": {"cmd": "python3", "args": ["script.py"]}, "tag": "my-script"}'

# Start process (SSE streaming output)
curl -X POST http://127.0.0.1:8080/api/v1/process/start \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -d '{"process": {"cmd": "python3", "args": ["script.py"]}}'

# List running processes
curl http://127.0.0.1:8080/api/v1/process/list

# Send stdin
curl -X POST http://127.0.0.1:8080/api/v1/process/input/send \
  -H "Content-Type: application/json" \
  -d '{"process": {"pid": 12345}, "input": {"stdin": "hello\n"}}'

# Send signal (SIGTERM)
curl -X POST http://127.0.0.1:8080/api/v1/process/signal/send \
  -H "Content-Type: application/json" \
  -d '{"process": {"tag": "my-script"}, "signal": 15}'

# System metrics + instance process metrics
curl http://127.0.0.1:8080/api/v1/metrics
# Response: { data: { ts, cpuCount, cpuUsedPct, memTotalMib, memUsedMib, diskUsed, diskTotal, instances: [{ id, cwd, pid, rssMib, heapUsedMib, heapTotalMib, uptimeSeconds, ... }] } }

Session Management

bash
# Get session list for the current workspace
curl http://127.0.0.1:8080/api/v1/sessions

# Get session list across all workspaces
curl http://127.0.0.1:8080/api/v1/sessions?cwd=*

# Get session list for a specific working directory
curl http://127.0.0.1:8080/api/v1/sessions?cwd=/path/to/workspace

# Get session list for a specific project (filter by compressed working directory name)
curl http://127.0.0.1:8080/api/v1/sessions?cwd=*&projectId=workspace-hash

# Rename session
curl -X POST http://127.0.0.1:8080/api/v1/sessions/SESSION_ID/rename \
  -H "Content-Type: application/json" \
  -d '{"name": "Performance Optimization Discussion"}'

cwd query parameter reference:

cwd ValueDescription
Not providedReturns sessions for the current workspace
*Returns sessions across all workspaces
/path/to/workspaceReturns sessions for the specified working directory

File Change Management

bash
# Get file diff (requires file to be tracked in a checkpoint)
curl "http://127.0.0.1:8080/api/v1/file-changes/diff?path=/path/to/file.ts"
# Response: {"path": "/path/to/file.ts", "oldText": "...", "newText": "..."}

# List checkpoints available for rollback
curl http://127.0.0.1:8080/api/v1/file-changes/checkpoints
# Response: {"checkpoints": [{"id": "xxx", "label": "...", "createdAt": 1234567890, "files": [...], "additions": 5, "deletions": 2}]}

# Revert changes by file
curl -X POST http://127.0.0.1:8080/api/v1/file-changes/revert \
  -H "Content-Type: application/json" \
  -d '{"paths": ["/path/to/file.ts"]}'
# Response: {"success": true, "revertedFiles": ["/path/to/file.ts"]}

# Rollback to a specific checkpoint
curl -X POST http://127.0.0.1:8080/api/v1/file-changes/revert \
  -H "Content-Type: application/json" \
  -d '{"checkpointId": "checkpoint-uuid", "scope": "CodeAndConversation"}'
# scope options: "Code" (revert files only), "Conversation" (revert conversation only), "CodeAndConversation" (revert all)

# Revert all changes (rollback to the earliest checkpoint)
curl -X POST http://127.0.0.1:8080/api/v1/file-changes/revert \
  -H "Content-Type: application/json" \
  -d '{}'

Plugin Management

bash
# List installed plugins
curl http://127.0.0.1:8080/api/v1/plugins

# Install plugin ("name@marketplace" format)
curl -X POST http://127.0.0.1:8080/api/v1/plugins \
  -H "Content-Type: application/json" \
  -d '{"plugin": "my-plugin@my-marketplace"}'

# Enable plugin
curl -X POST http://127.0.0.1:8080/api/v1/plugins/enable \
  -H "Content-Type: application/json" \
  -d '{"plugin": "my-plugin@my-marketplace"}'

# Disable plugin
curl -X POST http://127.0.0.1:8080/api/v1/plugins/disable \
  -H "Content-Type: application/json" \
  -d '{"plugin": "my-plugin@my-marketplace"}'

# Uninstall plugin
curl -X POST http://127.0.0.1:8080/api/v1/plugins/uninstall \
  -H "Content-Type: application/json" \
  -d '{"plugin": "my-plugin@my-marketplace"}'

# List plugin marketplaces
curl http://127.0.0.1:8080/api/v1/plugins/marketplaces

# Add plugin marketplace
curl -X POST http://127.0.0.1:8080/api/v1/plugins/marketplaces \
  -H "Content-Type: application/json" \
  -d '{"source": "https://example.com/marketplace", "name": "my-marketplace"}'

# Browse plugins in marketplace
curl -X POST http://127.0.0.1:8080/api/v1/plugins/marketplaces/browse \
  -H "Content-Type: application/json" \
  -d '{"marketplace": "my-marketplace"}'

# Delete plugin marketplace
curl -X DELETE http://127.0.0.1:8080/api/v1/plugins/marketplaces/my-marketplace

Settings Management

bash
# List all settings
curl http://127.0.0.1:8080/api/v1/settings

# List settings by scope
curl "http://127.0.0.1:8080/api/v1/settings?scope=user"

# Get a single setting
curl http://127.0.0.1:8080/api/v1/settings/model

# Set a setting value
curl -X PUT http://127.0.0.1:8080/api/v1/settings/theme \
  -H "Content-Type: application/json" \
  -d '{"value": "dark"}'

# Append values to an array-type setting
curl -X POST http://127.0.0.1:8080/api/v1/settings/permissions/items \
  -H "Content-Type: application/json" \
  -d '{"values": ["Allow: Read(**)"]}'

# Remove values from an array-type setting
curl -X POST http://127.0.0.1:8080/api/v1/settings/permissions/remove \
  -H "Content-Type: application/json" \
  -d '{"values": ["Allow: Read(**)"]}'

Error Codes

Error CodeHTTP StatusDescription
AUTH_REQUIRED401Authentication required
AUTH_INVALID401Invalid authentication
AUTH_RATE_LIMITED429Too many login attempts
NOT_FOUND404Resource not found
BAD_REQUEST400Invalid request parameters
RATE_LIMITED429Request rate too high
INTERNAL_ERROR500Internal server error
SESSION_NOT_FOUND404Session not found
SESSION_DELETE_CURRENT400Cannot delete current session
TERMINAL_NOT_FOUND404PTY not found
PROCESS_NOT_FOUND404Process not found
PATH_REQUIRED400Missing path parameter
PATH_NOT_DIRECTORY400Path is not a directory
INSUFFICIENT_STORAGE507Insufficient disk space
RUN_NOT_FOUND404Run not found
PLATFORM_UNSUPPORTED400Unsupported webhook platform
SIGNATURE_INVALID403Signature verification failed