chain-rdeveloper portal
build

API Interfaces

Overview

The platform exposes two categories of API surface:

  1. External API — the interface the browser (and developer API keys) calls, fronted by nginx and svc-bff

  2. 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 hostDestinationAuth required
app.dev.datachainr.com/api/*svc-bff → svc-coreYes (nginx auth_request)
app.dev.datachainr.comfe-coreYes (nginx auth_request)
dev.datachainr.comfe-publicNo

svc-bff Proxy

svc-bff is a thin proxy. It:

  1. Reads the session cookie, retrieves the access token from Redis

  2. Injects Authorization: Bearer <token>, X-User-Id, X-User-Email, X-User-Name headers

  3. Mints a short-lived, audience-bound internal JWT (X-Internal-Token, aud=svc-core) that svc-core verifies

  4. Forwards 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 actionsvc-ai endpoint called
Prompt an agentPOST /agents/execute/stream (type=agent)
Execute a skillPOST /agents/execute/stream (type=skill)
Resolve model metadataGET /models/lookup
List available modelsGET /models/available
List built-in toolsGET /tools/available
List skill templatesGET /skills/available
List worker definitionsGET /skills/agents
Knowledge graph node typesGET /knowledge/node-types
MCP server templatesGET /mcp/servers/templates
Token usage statsGET /stats/usage, GET /stats/traces

API Reference

Full auto-generated endpoint documentation:

ServiceReference
svc-aispec/api/svc-ai.md
svc-authspec/api/svc-auth.md
svc-bffspec/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:

HeaderValue
X-Internal-TokenShort-lived, audience-bound internal JWT (HS256, aud=svc-core) verified by svc-core
X-User-Idsvc-core user UUID
X-User-EmailUser's email address
X-User-NameUser's display name

Identity is taken from the verified X-Internal-Token, not trusted from the raw X-User-* headers. svc-core mints its own aud=svc-ai token for outbound calls to svc-ai, which svc-ai verifies. Enforced whenever INTERNAL_JWT_SECRET is 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.