Reference

API overview

Tiyi exposes one ConnectRPC API. The same proto schema serves the Vben Admin UI (JSON over HTTP), the tiyi CLI (JSON over HTTP), and the agent stream (gRPC bidi). One source of truth at proto/tiyi/v1/*.proto means the CLI and API stay in lockstep by construction.

Transport

Authentication

Three auth surfaces, picked by deployment context:

SurfaceMechanismUsed by
Local admin socket OS file permissions on admin.sock tiyi CLI on the same host as the server.
HS256 JWT Authorization: Bearer <jwt> over HTTP Vben Admin UI, remote CLI, anything driving the API from off-host. Issued by AuthService.Login; refreshed by RefreshToken.
Agent stream token One-use enrollment token → long-lived stream token Agents on the bidi AgentStream. Tokens are issued through AgentService.IssueEnrollmentToken.

Login example

$ curl -sS http://primary:8080/tiyi.v1.AuthService/Login \
    -H "Content-Type: application/json" \
    -d '{"username":"admin","password":"..."}'
{
  "accessToken": "<jwt>",
  "refreshToken": "<refresh>",
  "user": { "id": "<uuid>", "role": "Administrator" }
}

The 14 services

ServiceScope
SystemServiceHealth, version, dashboard rollups, settings, releases, replication, promote/demote.
AuthServiceLogin, logout, refresh, current user, OIDC redirect, access codes.
UserServiceUser CRUD, lock/unlock, password reset.
RoleServiceRole + permission lookup. RBAC table is built-in.
SiteServiceSite CRUD, enable/disable, preview, per-site policy override.
UpstreamServiceUpstream pool CRUD; deletion refused while in use.
CertServiceUpload, ACME issue/renew, DNS provider CRUD.
PolicyServiceWAF policy CRUD, layer updates, version snapshots, SecLang preview, test lab.
RuleOverrideServicePer-rule overrides, custom rules, IP lists, rate-limit endpoints.
CrsServiceCRS catalog browse + ingest + exclusion-package install/attach.
AgentServiceAgent CRUD, enrollment tokens, install scripts, commands, agent groups, AgentStream.
TrustServiceClient-IP trust profile (tenant + site overrides), CDN snapshot list/refresh, explain.
AlertServiceAlert rule + channel CRUD, active alert ack/resolve, channel test send.
LogServiceSecurity/access/error/audit query, get, export, live tail.

Error codes

Tiyi returns standard ConnectRPC error codes mapped from gRPC. The CLI and UI surface localized messages on top of the canonical code:

CodeHTTPTypical cause
invalid_argument400Bad input shape or value rejected by the validator.
unauthenticated401Missing or invalid JWT.
permission_denied403JWT lacks the required RBAC permission.
not_found404Resource id does not exist or is soft-deleted.
already_exists409Unique constraint violated (site name, policy name, etc.).
failed_precondition412Revision conflict, UPSTREAM_IN_USE, replication-lag gate, etc.
unimplemented501RPC not yet wired (rare — the 2026-05-26 changelog entry closed the last batch).
internal500Server-side bug or infrastructure failure. Audit chain receives a row when relevant.

RBAC

Each RPC declares a required permission like site:read, policy:write, log:read, system:write. The middleware checks the JWT subject's roles against the permission table; the canonical mapping lives in internal/api/middleware.go. There are 52 fine-grained permissions in v3.0.0-rc.1.

Streaming RPCs

Canonical spec

The PRD-API document in the source tree is the canonical per-RPC spec. It enumerates every method's request/response shape, RBAC permission, error codes, and audit-row contract. These docs cover the operator surface; that doc covers the API contract. They should agree — file an issue if they don't.

For a generated reference, regenerate Connect Go and Protobuf Go from proto/:

$ make proto
$ ls internal/api/gen/tiyi/v1/
# <service>.pb.go and <service>.connect.go for each .proto file