Skip to content

Tham Chiếu HTTP REST API

GoClaw cung cấp HTTP REST API đầy đủ song song với WebSocket RPC. Tất cả endpoint được phục vụ trên cùng một cổng với gateway server.

Tài liệu tương tác có tại /docs (Swagger UI), spec raw tại /docs/openapi.json.


Tổng Quan

  • Base URL: http://<host>:<port> (mặc định port 18790 đối với Desktop, cấu hình qua gateway.port)
  • Versioning: Tất cả endpoint bắt đầu bằng /v1/
  • Protocol: HTTP/1.1, JSON request/response
  • Content-Type: application/json cho request body
  • Encoding: UTF-8

Xác Thực (Authentication)

Tất cả endpoint (trừ /health) yêu cầu xác thực qua Bearer token trong header Authorization:

Authorization: Bearer <token>

Hai loại token được chấp nhận:

LoạiĐịnh dạngPhạm vi
Gateway tokenCấu hình trong config.json (trường gateway.token)Admin toàn quyền
API keygoclaw_ + 32 ký tự hexPhạm vi giới hạn bởi scope của key

API key được hash SHA-256 trước khi tra cứu — raw key không bao giờ được lưu trữ. Một số endpoint chấp nhận token qua query parameter ?token=<token> (dùng cho <img><audio> tags).

Headers Thường Gặp

HeaderMục đích
AuthorizationBearer token xác thực
X-GoClaw-User-IdUser ID bên ngoài cho context multi-tenant
X-GoClaw-Agent-IdAgent identifier cho tác vụ có phạm vi
X-GoClaw-Tenant-IdTenant scope — UUID hoặc slug
Accept-LanguageLocale (en, vi, zh) cho thông báo lỗi i18n
Content-Typeapplication/json cho request body

Agents

CRUD quản lý agent. Yêu cầu header X-GoClaw-User-Id cho context multi-tenant.

MethodPathMô tảAuth
GET/v1/agentsLiệt kê agents mà user truy cập đượcBearer
POST/v1/agentsTạo agent mớiBearer
GET/v1/agents/{id}Lấy agent theo ID hoặc keyBearer
PUT/v1/agents/{id}Cập nhật agent (chỉ owner)Bearer
DELETE/v1/agents/{id}Xóa agent (chỉ owner)Bearer

Agent Actions

MethodPathMô tả
POST/v1/agents/{id}/wakeKích hoạt agent từ bên ngoài (n8n, orchestrators)
POST/v1/agents/{id}/regenerateTạo lại cấu hình agent bằng LLM
POST/v1/agents/{id}/resummonThử lại quá trình summoning ban đầu

Agent Files và Instances

MethodPathMô tả
GET/v1/agents/{id}/instancesLiệt kê user instances
GET/v1/agents/{id}/instances/{userID}/filesLiệt kê context files của user
PUT/v1/agents/{id}/instances/{userID}/files/{fileName}Cập nhật user file (chỉ USER.md)

Agent Sharing

MethodPathMô tả
GET/v1/agents/{id}/sharingLiệt kê shares của agent
POST/v1/agents/{id}/sharingChia sẻ agent với user
DELETE/v1/agents/{id}/sharing/{userID}Thu hồi quyền truy cập

Sessions

MethodPathMô tả
GET/v1/sessionsLiệt kê sessions (có phân trang)

Chi tiết session được quản lý chủ yếu qua WebSocket RPC (xem sessions.* methods).


Providers

MethodPathMô tả
GET/v1/providersLiệt kê LLM providers
POST/v1/providersTạo provider mới
GET/v1/providers/{id}Lấy chi tiết provider
PUT/v1/providers/{id}Cập nhật cấu hình provider
DELETE/v1/providers/{id}Xóa provider

Tools

Custom Tools

MethodPathMô tả
GET/v1/tools/customLiệt kê tools (lọc theo ?agent_id=)
POST/v1/tools/customTạo custom tool
GET/v1/tools/custom/{id}Lấy chi tiết tool
PUT/v1/tools/custom/{id}Cập nhật tool
DELETE/v1/tools/custom/{id}Xóa tool
POST/v1/tools/invokeGọi trực tiếp tool không qua agent loop

MCP Servers

MethodPathMô tả
GET/v1/mcp/serversLiệt kê MCP servers đã đăng ký
POST/v1/mcp/serversĐăng ký MCP server mới
GET/v1/mcp/servers/{id}Lấy chi tiết server
PUT/v1/mcp/servers/{id}Cập nhật cấu hình server
DELETE/v1/mcp/servers/{id}Xóa MCP server
POST/v1/mcp/servers/{id}/grants/agentCấp quyền truy cập cho agent
DELETE/v1/mcp/servers/{id}/grants/agent/{agentID}Thu hồi quyền agent
GET/v1/mcp/grants/agent/{agentID}Liệt kê MCP grants của agent
POST/v1/mcp/servers/{id}/grants/userCấp quyền truy cập cho user
DELETE/v1/mcp/servers/{id}/grants/user/{userID}Thu hồi quyền user
POST/v1/mcp/requestsYêu cầu cấp quyền (user tự phục vụ)
GET/v1/mcp/requestsLiệt kê yêu cầu đang chờ
POST/v1/mcp/requests/{id}/reviewChấp nhận hoặc từ chối yêu cầu

Channels

MethodPathMô tả
GET/v1/channel-instancesLiệt kê channel instances
POST/v1/channel-instancesTạo channel instance mới
GET/v1/channel-instances/{id}Lấy chi tiết instance
PUT/v1/channel-instances/{id}Cập nhật cấu hình instance
DELETE/v1/channel-instances/{id}Xóa channel instance

Skills

MethodPathMô tả
GET/v1/skillsLiệt kê tất cả skills
POST/v1/skills/uploadUpload ZIP chứa SKILL.md (tối đa 20 MB)
GET/v1/skills/{id}Lấy chi tiết skill
PUT/v1/skills/{id}Cập nhật metadata skill
DELETE/v1/skills/{id}Xóa skill (không áp dụng với system skills)
POST/v1/skills/{id}/toggleBật/tắt skill
GET/v1/skills/{id}/versionsLiệt kê phiên bản có sẵn
GET/v1/skills/{id}/filesLiệt kê files trong skill
POST/v1/skills/{id}/grants/agentCấp skill cho agent
DELETE/v1/skills/{id}/grants/agent/{agentID}Thu hồi skill khỏi agent
GET/v1/agents/{agentID}/skillsLiệt kê skills với trạng thái grant của agent

Files

MethodPathMô tả
GET/v1/filesLiệt kê workspace files
GET/v1/files/{path}Phục vụ nội dung file
DELETE/v1/storage/{path}Xóa workspace file
POST/v1/media/uploadUpload media file
GET/v1/media/{id}Phục vụ media file

Config, Usage, Traces, Audit

MethodPathMô tả
GET/v1/usageLấy metrics sử dụng
GET/v1/usage/summaryLấy tổng hợp sử dụng
GET/v1/tracesLiệt kê traces (lọc theo agent, user, status, ngày)
GET/v1/traces/{id}Lấy chi tiết trace với tất cả spans
GET/v1/activityLiệt kê audit logs hoạt động
GET/v1/api-keysLiệt kê API keys (đã che)
POST/v1/api-keysTạo API key mới
DELETE/v1/api-keys/{id}Thu hồi API key
GET/v1/delegationsLiệt kê lịch sử delegation (phân trang)
GET/v1/delegations/{id}Lấy chi tiết delegation
GET/v1/memoryLấy memory entries
POST/v1/memoryTạo memory entry
DELETE/v1/memory/{id}Xóa memory entry

OpenAI-Compatible Endpoint

POST /v1/chat/completions

Tương thích với OpenAI Chat API để truy cập agent theo chương trình.

Request:

json
{
  "model": "goclaw:agent-id-hoac-key",
  "messages": [
    {"role": "user", "content": "Xin chào"}
  ],
  "stream": false,
  "user": "user-id-tuy-chon"
}

Quy tắc phân giải agent: trường model với prefix goclaw: hoặc agent:, sau đó header X-GoClaw-Agent-Id, sau đó agent "default".

Response (non-streaming):

json
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "choices": [{
    "index": 0,
    "message": {"role": "assistant", "content": "..."},
    "finish_reason": "stop"
  }],
  "usage": {"prompt_tokens": 10, "completion_tokens": 20, "total_tokens": 30}
}

Streaming: Đặt "stream": true để nhận Server-Sent Events (SSE) với data: {...} chunks, kết thúc bằng data: [DONE].

POST /v1/responses

Alternative protocol tương thích với OpenAI Responses API. Cung cấp xác thực tương tự, trả về response objects có cấu trúc (response.started, response.delta, response.done).


Rate Limiting

Token bucket rate limiting theo user hoặc IP. Cấu hình qua gateway.rate_limit_rpm (0 = tắt, > 0 = bật).

  • Burst: 5 requests
  • HTTP 429 khi vượt giới hạn, kèm header Retry-After: 60
  • Cleanup: mỗi 5 phút, xóa entries không hoạt động quá 10 phút

Mã Lỗi (Error Codes)

CodeMô tả
UNAUTHORIZEDXác thực thất bại hoặc không đủ quyền
INVALID_REQUESTTrường thiếu hoặc không hợp lệ trong request
NOT_FOUNDTài nguyên không tồn tại
ALREADY_EXISTSTài nguyên đã tồn tại (conflict)
UNAVAILABLEDịch vụ tạm thời không khả dụng
RESOURCE_EXHAUSTEDVượt giới hạn rate limit
FAILED_PRECONDITIONĐiều kiện tiên quyết chưa được đáp ứng
AGENT_TIMEOUTAgent run vượt quá giới hạn thời gian
INTERNALLỗi server không mong đợi

Response lỗi bao gồm trường retryable (boolean) và retryAfterMs (integer) để hướng dẫn client retry.


Xem Thêm