API Interfaces
Overview
The platform exposes two categories of API surface:
External API — the interface the browser (and developer API keys) calls, fronted by nginx and svc-bff
Internal APIs — service-to-service calls on private Docker networks, not reachable from the internet
External Interface
All external traffic enters through nginx on port 8000 and is routed by virtual host:
| Virtual host | Destination | Auth required |
|---|---|---|
app.dev.datachainr.com/api/* | svc-bff → svc-core | Yes (nginx auth_request) |
app.dev.datachainr.com | fe-core | Yes (nginx auth_request) |
dev.datachainr.com | fe-public | No |
svc-bff Proxy
svc-bff is a thin proxy. It:
Reads the session cookie, retrieves the access token from Redis
Injects
Authorization: Bearer <token>,X-User-Id,X-User-Email,X-User-NameheadersMints a short-lived, audience-bound internal JWT (
X-Internal-Token,aud=svc-core) that svc-core verifiesForwards the request to svc-core at the same path
WebSocket connections follow the same pattern via /ws/*.
Internal APIs
svc-core → svc-ai
svc-core calls svc-ai on the backend-network for all AI operations. svc-core does not call LLM providers directly.
Key call patterns:
| svc-core action | svc-ai endpoint called |
|---|---|
| Prompt an agent | POST /agents/execute/stream (type=agent) |
| Execute a skill | POST /agents/execute/stream (type=skill) |
| Resolve model metadata | GET /models/lookup |
| List available models | GET /models/available |
| List built-in tools | GET /tools/available |
| List skill templates | GET /skills/available |
| List worker definitions | GET /skills/agents |
| Knowledge graph node types | GET /knowledge/node-types |
| MCP server templates | GET /mcp/servers/templates |
| Token usage stats | GET /stats/usage, GET /stats/traces |
API Reference
Full auto-generated endpoint documentation:
| Service | Reference |
|---|---|
| svc-ai | spec/api/svc-ai.md |
| svc-auth | spec/api/svc-auth.md |
| svc-bff | spec/api/svc-bff.md |
SSE Streaming Protocol
LLM inference is streamed token-by-token over Server-Sent Events. The browser opens an EventSource connection; svc-bff tunnels it to svc-core which tunnels to svc-ai.
SSE frame format:
data: {"type": "status", "message": "Starting..."}
data: {"type": "token", "token": "Hello"}
data: {"type": "done", "output": "...", "usage": {"input_tokens": 10, "output_tokens": 42}}
data: {"type": "error", "message": "..."}
For multi-agent skill/worker/graph execution, additional frames indicate node transitions:
data: {"type": "node_start", "node_id": "analyzer"}
data: {"type": "token", "token": "...", "node_id": "analyzer"}
data: {"type": "node_end", "node_id": "analyzer"}
Graph executions announce their whole pipeline up-front in a single graph_plan frame — the first frame of the stream — so a client can render every stage (CI-style) before the first node runs rather than growing the view one node at a time. Stages are ordered; a stage holds several node_ids when only a subset of them runs (retrieval), and optional marks a stage routing may legitimately bypass. The retrieval stage is a fork and a join: fork starts its branches side by side (a lane per kind of knowledge the agent holds, the web, the tools) and they meet in join:
data: {"type": "graph_plan", "stages": [
{"id": "gate", "node_ids": ["__gate__"], "optional": false, "is_system_stage": true},
{"id": "retrieval", "node_ids": ["__knowledge_plan__", "__domain_retrieval__",
"__external_retrieval__", "__tool_retrieval__",
"__retrieval_join__"],
"fork": "__knowledge_plan__",
"branches": ["__domain_retrieval__", "__external_retrieval__", "__tool_retrieval__"],
"join": "__retrieval_join__",
"optional": true, "is_system_stage": true},
{"id": "skill:analyzer", "node_ids": ["analyzer"], "optional": true, "is_system_stage": false}
]}
Every node_start and node_end frame carries t_ms (milliseconds from the stream's start), and node_start the graph pass it runs on (0, then one more per revision), so branches that ran side by side can be drawn as they ran.
The plan is a prediction — routers decide the real path at runtime, so a client reconciles it against the node_start / node_end frames that follow. It is persisted with the rest of the trace, so a stored conversation renders the same pipeline after a reload.
Human-in-the-loop interrupts emit a hitl_pause trace frame (the node that stopped and what it asked) followed by a hitl_interrupt frame; the client resumes via POST /agents/execute/stream/resume (type agent, skill or graph). svc-core validates and governs the answer first, answers the chat with hitl_invalid when it does not fit, and records a hitl_resume trace frame. See Human in the Loop.
Authentication Headers
Internal identity propagation from svc-bff to svc-core:
| Header | Value |
|---|---|
X-Internal-Token | Short-lived, audience-bound internal JWT (HS256, aud=svc-core) verified by svc-core |
X-User-Id | svc-core user UUID |
X-User-Email | User's email address |
X-User-Name | User's display name |
Identity is taken from the verified
X-Internal-Token, not trusted from the rawX-User-*headers. svc-core mints its ownaud=svc-aitoken for outbound calls to svc-ai, which svc-ai verifies. Enforced wheneverINTERNAL_JWT_SECRETis set (required outside local/dev). See security/auth-flow.md.
Resource Ownership
All resource endpoints accept optional resource_owner_type and resource_owner_id query parameters to filter by owner scope (user / organisation / project). When resource_owner_type=user, the resource_owner_id is always derived from the authenticated session — the client-supplied value is ignored.