API Reference
Complete REST and WebSocket API reference for AGTerm.
Base URL
http://localhost:3000/apiAll endpoints return JSON with this structure:
{
"success": true,
"data": { ... }
}Or on error:
{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Human-readable message"
}
}Sessions API
List Sessions
GET /api/sessionsReturns all active sessions.
Response:
{
"success": true,
"data": {
"sessions": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "My Session",
"agent": "agterm",
"createdAt": "2024-01-15T10:30:00Z",
"lastActiveAt": "2024-01-15T11:45:00Z",
"workspaceDir": "/home/user/.agterm/workspaces/550e8400...",
"pid": 12345,
"modelConfig": {
"provider": "anthropic",
"model": "claude-sonnet-4-20250514"
}
}
]
}
}Create Session
POST /api/sessions
Content-Type: application/json
{
"name": "My Session",
"agent": "agterm",
"provider": "groq",
"model": "llama-3.3-70b-versatile"
}Parameters:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | No | Session display name |
agent | string | Yes | Agent type: agterm, claude, gemini, codex, shell |
provider | string | No | LLM provider override |
model | string | No | Model name override |
Response: 201 Created
{
"success": true,
"data": {
"session": { ... }
}
}Get Session
GET /api/sessions/:idDelete Session
DELETE /api/sessions/:idTerminates the session and cleans up workspace.
Switch Agent
POST /api/sessions/:id/switch-agent
Content-Type: application/json
{
"agent": "claude"
}Send Input
POST /api/sessions/:id/input
Content-Type: application/json
{
"data": "Hello, world!\n"
}Send terminal input to a session. Useful for programmatic interaction.
Resize Terminal
POST /api/sessions/:id/resize
Content-Type: application/json
{
"cols": 120,
"rows": 40
}Get Git Status
GET /api/sessions/:id/gitReturns git status for the session’s workspace:
{
"success": true,
"data": {
"status": {
"isRepo": true,
"branch": "main",
"ahead": 2,
"behind": 0,
"staged": 1,
"unstaged": 3,
"untracked": 0
},
"formatted": "main ↑2 +1 ~3",
"workspaceDir": "/home/user/.agterm/workspaces/..."
}
}Agents API
List Agents
GET /api/agentsReturns all available agents with their status:
{
"success": true,
"data": {
"agents": [
{
"id": "agterm",
"name": "AGTerm",
"icon": "agterm",
"color": "#58a6ff",
"welcome": "AGTerm agent ready.",
"command": "agterm-agent",
"available": true,
"cliExists": true,
"cliPath": "/usr/local/bin/agterm-agent",
"hasCredentials": true,
"keySource": "env"
},
{
"id": "claude",
"name": "Claude Code",
"available": false,
"cliExists": true,
"hasCredentials": false,
"missingEnvVars": ["ANTHROPIC_API_KEY"]
}
]
}
}Get Agent
GET /api/agents/:idModels API
List All Models
GET /api/modelsReturns all providers and their available models:
{
"success": true,
"data": {
"providers": [
{
"id": "anthropic",
"name": "Anthropic",
"configured": true,
"models": [
{
"id": "claude-opus-4-20250514",
"name": "Claude Opus 4",
"description": "Most capable reasoning model"
}
]
}
],
"profiles": [...],
"configuredProviders": ["anthropic", "groq"]
}
}List Profiles
GET /api/models/profilesList Configured Providers
GET /api/models/providersGet Agent Models
GET /api/models/agent/:agentReturns models available for a specific agent type.
Files API
List Directory
GET /api/files/list?path=/home/user&hidden=trueQuery Parameters:
| Param | Type | Default | Description |
|---|---|---|---|
path | string | cwd | Directory to list |
hidden | boolean | false | Include hidden files |
Read File
GET /api/files/read?path=/home/user/file.txtMaximum file size: 1MB.
Write File
POST /api/files/write
Content-Type: application/json
{
"path": "/home/user/file.txt",
"content": "File contents here"
}Create Directory
POST /api/files/mkdir
Content-Type: application/json
{
"path": "/home/user/new-dir"
}Delete File
DELETE /api/files/delete?path=/home/user/file.txtRename/Move
POST /api/files/rename
Content-Type: application/json
{
"oldPath": "/home/user/old.txt",
"newPath": "/home/user/new.txt"
}Recordings API
List Recordings
GET /api/recordingsGet Recording
GET /api/recordings/:idDelete Recording
DELETE /api/recordings/:idStart Recording
POST /api/recordings/start/:sessionIdStop Recording
POST /api/recordings/stop/:sessionIdGet Recording Status
GET /api/recordings/status/:sessionIdCosts API
Cost Dashboard
GET /api/costs/dashboard?startDate=2024-01-01&endDate=2024-01-31Session Costs
GET /api/costs/sessions
GET /api/costs/sessions/:sessionIdProvider Breakdown
GET /api/costs/providersDaily Costs
GET /api/costs/daily?days=30Health API
GET /api/healthResponse:
{
"status": "ok",
"version": "1.0.0",
"uptime": 3600,
"timestamp": "2024-01-15T12:00:00Z"
}WebSocket API
Connect to the WebSocket server:
ws://localhost:3000/ws?token=<jwt_token>Message Format
All messages are JSON:
{
"type": "message_type",
"sessionId": "optional-session-id",
"payload": { ... }
}Session Messages
Attach to Session
{
"type": "session:attach",
"payload": {
"sessionId": "550e8400-e29b-41d4-a716-446655440000",
"cols": 120,
"rows": 40
}
}Response: session:attached
Detach from Session
{
"type": "session:detach"
}Response: session:detached
Terminal Messages
Send Input
{
"type": "terminal:input",
"payload": {
"data": "ls -la\n"
}
}Receive Output
{
"type": "terminal:output",
"sessionId": "...",
"payload": {
"data": "total 48\ndrwxr-xr-x 12 user staff 384 Jan 15 10:30 .\n..."
}
}Resize Terminal
{
"type": "terminal:resize",
"payload": {
"cols": 120,
"rows": 40
}
}Agent Messages
Switch Agent
{
"type": "agent:switch",
"payload": {
"agent": "claude"
}
}Response: agent:switched with updated session data.
Utility Messages
Ping/Pong
{ "type": "ping" }Response: { "type": "pong" }
Error
{
"type": "error",
"payload": {
"code": "SESSION_NOT_FOUND",
"message": "Session not found"
}
}Common Error Codes
| Code | Description |
|---|---|
INVALID_MESSAGE | Malformed JSON |
INVALID_REQUEST | Missing required field |
SESSION_NOT_FOUND | Session doesn’t exist |
AGENT_NOT_FOUND | Invalid agent type |
AGENT_DISABLED | Agent is disabled (e.g., shell) |
NO_SESSION | Not attached to any session |
ATTACH_FAILED | Failed to attach to session |
Rate Limiting
Default limits:
- Window: 15 minutes
- Max requests: 100 per window
Configure via environment variables:
AGTERM_RATE_LIMIT_WINDOW(ms)AGTERM_RATE_LIMIT_MAX