AAnvio
API

REST APIs

Every REST endpoint exposed by the Anvio API app, pulled directly from apps/api/src controllers.

5 min read

The Anvio REST API is an optional surface (apps/api, a NestJS app). It is not required to use Anvio — the CLI (anvio chat) talks to the same platform directly. The API exists for Level 2+ deployments: gateways, dashboards, and channel webhooks that need an HTTP entry point.

Global prefix: every route below is mounted under /api (app.setGlobalPrefix('api') in apps/api/src/main.ts). So sessions becomes POST /api/sessions. Default port: process.env.API_PORT or 3000.

This page lists only endpoints found in real controllers under apps/api/src. Each controller is listed with its source file.

Health

Source: apps/api/src/health.controller.ts

GET /api/health

Liveness check. No auth, no dependencies checked.

{ "status": "ok", "service": "anvio-api", "timestamp": "2026-07-03T10:00:00.000Z" }

Metrics

Source: apps/api/src/metrics.controller.ts

GET /api/metrics

Prometheus text-format metrics (Content-Type: text/plain; version=0.0.4), served from getMetricsRegistry().toPrometheusText() in @anvio/observability. Scrape this with Prometheus directly — there is no JSON variant.

Agents

Source: apps/api/src/agents.controller.ts

GET /api/agents

Lists every agent definition available in the workspace (workspace/agents/*.md or .yaml), loaded via appService.platform.workspace.loader.

[
  { "name": "architect", "description": "...", "spec": { "...": "..." } }
]

GET /api/agents/:name

Loads a single agent definition by name. Returns { "error": "Not found" } (HTTP 200, not 404 — see Error Codes) if the agent doesn't exist.

TODO: verify this endpoint against apps/api/src — docs/15-api-reference.md mentions POST /agents (create agent, admin-only), but no such route exists in agents.controller.ts. Agent creation happens by writing files to workspace/agents/, not via the API.

Sessions

Source: apps/api/src/sessions.controller.ts

POST /api/sessions

Creates a new session for an agent and publishes anvio.session.started.v1 on the event bus.

Request body:

{
  "agentName": "architect",
  "channel": "rest",
  "detached": false,
  "channelThreadId": "optional-external-thread-id"
}
  • agentName is required; the endpoint 404s (soft — returns { error: 'Agent not found' }) if workspace.loader.loadAgent() throws.
  • channel defaults to 'rest' if omitted.
  • Reads Authorization: Bearer <token> if auth is enabled (see Authentication).

Response:

{ "id": "b3f1...", "agentName": "architect", "channel": "rest" }

GET /api/sessions/:id

Fetches a stored session. If auth is enabled and the session's userId doesn't match the caller's resolved identity, returns { "error": "Not found" } — the API does not leak other users' sessions, but it also does not return a distinct 403.

POST /api/sessions/:id/messages

Sends a user message into an existing session. This does not run the agent synchronously — it publishes anvio.agent.run.requested.v1 and returns immediately with a queued status. The actual agent turn is picked up asynchronously by whatever is subscribed to that event (the worker, or an in-process handler when running on the local event bus).

Request body:

{ "content": "What's the status of the migration?" }

Response:

{ "status": "queued", "sessionId": "b3f1..." }

To see the reply, poll GET /api/sessions/:id or subscribe to anvio.agent.run.completed.v1 / anvio.agent.run.chunk.v1 — see Event Model.

Rendering diagram…

Channel webhooks

These controllers receive inbound messages from external chat platforms and hand them to the matching ChannelAdapter registered on the ChannelHub. See Channel Adapters for the adapter architecture.

WhatsApp

Source: apps/api/src/whatsapp.controller.ts

GET /api/channels/whatsapp/webhook

Meta's webhook verification handshake. Reads hub.mode, hub.verify_token, hub.challenge query params and echoes hub.challenge back if whatsapp.verifyWebhook() accepts the token. Returns 404 if the WhatsApp channel isn't enabled, 403 if verification fails.

POST /api/channels/whatsapp/webhook

Receives inbound WhatsApp messages/events; delegates to whatsapp.handleWebhook(body). Returns 404 if the channel isn't enabled, otherwise 200 OK.

Microsoft Teams

Source: apps/api/src/teams.controller.ts

POST /api/channels/teams/webhook

Receives a Bot Framework Activity payload, forwarded to TeamsChannel.handleActivity(). Returns 404 if the teams adapter isn't registered on the ChannelHub, otherwise 200 {}.

Matrix

Source: apps/api/src/matrix.controller.ts

POST /api/channels/matrix/webhook

Receives { roomId, senderId, body } and forwards to MatrixChannel.handleRoomMessage(). Returns 400 if any of the three fields are missing, 404 if the matrix adapter isn't registered, otherwise 200 { ok: true }.

Other channels documented elsewhere (Slack, Telegram, Discord, Signal, Google Chat, Feishu, SMS, Mattermost, Email) do not have dedicated NestJS webhook controllers in apps/api/src as of this writing — they connect via their own transport (bot polling, WebSocket, SMTP/IMAP, signal-cli REST) rather than an inbound HTTP webhook on the API app. See packages/channels/src/create-channels.ts for how each adapter is wired, and Channel Adapters for the full list.

Endpoints referenced in older docs but not found in source

docs/15-api-reference.md (an internal doc, not this site) lists POST /auth/login and POST /auth/register. No AuthController exists in apps/api/src.

TODO: verify against apps/api/src — if these endpoints are added later, update this page. Until then, treat the API as auth-optional per Authentication.

Controller registration

All controllers are wired in apps/api/src/app.module.ts:

@Module({
  controllers: [
    HealthController,
    MetricsController,
    AgentsController,
    SessionsController,
    WhatsAppController,
    TeamsController,
    MatrixController,
  ],
  providers: [AppService],
})
export class AppModule {}

AppService (apps/api/src/app.service.ts) is the single composition point — it calls createPlatform() from @anvio/platform on module init, giving every controller access to this.appService.platform.* (workspace, event bus, channel hub, auth).

Edit on GitHub

Last updated on

On this page