openapi: 3.0.3 info: title: AgentFlow API description: | Enterprise observability platform for AI agents. Provides real-time trace ingestion, security monitoring, alerting, and analytics powered by Timeplus Proton streaming SQL. version: "1.0.0" contact: name: AgentFlow Support email: support@agentflow.io license: name: MIT servers: - url: http://localhost:3000 description: Development - url: https://agentflow.example.com description: Production tags: - name: Ingest description: Trace ingestion from AI agent SDKs - name: Traces description: Query and filter traces - name: Stats description: Dashboard aggregates and analytics - name: Health description: System health and readiness - name: Alerts description: Security alert management - name: Admin description: Administrative endpoints (admin role required) - name: Auth description: Authentication security: - BearerAuth: [] - ApiKeyAuth: [] - SessionAuth: [] paths: /api/ingest: post: operationId: ingestTrace tags: [Ingest] summary: Ingest a trace event from an AI agent description: | Receives a trace event and processes it through the security engine. Supports idempotent ingestion via the Idempotency-Key header. security: - ApiKeyAuth: [] - BearerAuth: [] parameters: - in: header name: Idempotency-Key schema: type: string description: Prevents duplicate processing on SDK retries (cached for 5 minutes) - in: header name: X-Request-ID schema: type: string description: Request correlation ID (auto-generated if not provided) requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/TraceInput' responses: '200': description: Trace ingested successfully headers: X-Request-ID: schema: { type: string } X-RateLimit-Limit: schema: { type: integer } X-RateLimit-Remaining: schema: { type: integer } X-RateLimit-Reset: schema: { type: integer } content: application/json: schema: $ref: '#/components/schemas/IngestResponse' '400': description: Invalid payload or missing required fields '401': description: Missing or invalid API key '413': description: Payload exceeds 64KB limit '429': description: Rate limit exceeded (300 requests/minute per agent) headers: Retry-After: schema: { type: integer } /api/traces: get: operationId: getTraces tags: [Traces] summary: Query traces with optional filtering parameters: - in: query name: agent_id schema: { type: string } - in: query name: malicious schema: { type: boolean } - in: query name: action schema: { type: string } - in: query name: limit schema: { type: integer, default: 200, maximum: 1000 } - in: query name: offset schema: { type: integer, default: 0 } responses: '200': description: Filtered traces content: application/json: schema: $ref: '#/components/schemas/TraceListResponse' /api/stats: get: operationId: getStats tags: [Stats] summary: Consolidated dashboard data responses: '200': description: Dashboard stats, agents, alerts, time series content: application/json: schema: $ref: '#/components/schemas/StatsResponse' /api/health: get: operationId: getHealth tags: [Health] summary: System health check security: [] responses: '200': description: System is healthy or degraded content: application/json: schema: $ref: '#/components/schemas/HealthResponse' '503': description: System is unhealthy or draining /api/metrics: get: operationId: getMetrics tags: [Health] summary: Prometheus metrics endpoint security: [] responses: '200': description: Prometheus exposition format content: text/plain: schema: { type: string } /api/alerts/acknowledge: post: operationId: acknowledgeAlert tags: [Alerts] summary: Acknowledge a security alert description: Requires alerts:acknowledge permission (operator or admin) requestBody: required: true content: application/json: schema: type: object required: [alert_id] properties: alert_id: type: string responses: '200': description: Alert acknowledged '403': description: Insufficient permissions '404': description: Alert not found /api/admin/audit: get: operationId: getAuditLog tags: [Admin] summary: Query audit logs description: Requires audit:read permission (admin only) parameters: - in: query name: user_id schema: { type: string } - in: query name: action schema: { type: string } - in: query name: limit schema: { type: integer, default: 100, maximum: 500 } - in: query name: offset schema: { type: integer, default: 0 } responses: '200': description: Audit log entries '403': description: Insufficient permissions /api/admin/export: get: operationId: exportData tags: [Admin] summary: Export traces as JSON or CSV description: Requires admin:access permission parameters: - in: query name: format schema: type: string enum: [json, csv] default: json - in: query name: limit schema: { type: integer, default: 1000, maximum: 10000 } - in: query name: agent_id schema: { type: string } - in: query name: malicious schema: { type: boolean } responses: '200': description: Downloaded file content: application/json: {} text/csv: {} '403': description: Insufficient permissions /api/admin/dlq: get: operationId: getDLQ tags: [Admin] summary: View webhook dead letter queue description: Requires admin:access permission responses: '200': description: DLQ entries post: operationId: retryDLQ tags: [Admin] summary: Retry all failed webhook deliveries description: Requires admin:access permission responses: '200': description: Retry results components: securitySchemes: BearerAuth: type: http scheme: bearer description: API key as Bearer token for ingest endpoints ApiKeyAuth: type: apiKey in: header name: X-API-Key description: API key header for ingest endpoints SessionAuth: type: apiKey in: cookie name: next-auth.session-token description: NextAuth session cookie for dashboard endpoints schemas: TraceInput: type: object required: [agent_id, details] properties: agent_id: type: string maxLength: 128 description: Unique identifier for the AI agent agent_name: type: string maxLength: 128 session_id: type: string maxLength: 128 action: type: string maxLength: 64 enum: [agent_start, agent_stop, agent_thought, tool_call, tool_result, llm_request, llm_response, error, checkpoint] status: type: string enum: [success, warning, failed, pending] default: success details: type: string maxLength: 2048 description: Free-text description (analyzed by security engine) is_malicious: type: boolean description: Override flag — security engine also detects automatically token_usage: type: integer minimum: 0 maximum: 1000000 latency_ms: type: integer minimum: 0 model: type: string maxLength: 64 tags: type: array items: { type: string } maxItems: 20 timestamp: type: string format: date-time IngestResponse: type: object properties: success: type: boolean trace_id: type: string total: type: integer TraceListResponse: type: object properties: traces: type: array items: $ref: '#/components/schemas/Trace' total: type: integer has_more: type: boolean Trace: type: object properties: id: { type: string } timestamp: { type: string, format: date-time } agent_id: { type: string } agent_name: { type: string } session_id: { type: string } action: { type: string } status: { type: string } details: { type: string } is_malicious: { type: boolean } token_usage: { type: integer } cost: { type: number } latency_ms: { type: integer } model: { type: string } tags: { type: array, items: { type: string } } StatsResponse: type: object properties: dashboard: type: object agents: type: array items: { type: object } security_metrics: type: array items: { type: object } alerts: type: array items: { type: object } time_series: type: array items: { type: object } traces: type: array items: $ref: '#/components/schemas/Trace' HealthResponse: type: object properties: status: type: string enum: [healthy, degraded, unhealthy, draining] service: { type: string } version: { type: string } uptime_seconds: { type: integer } traces_stored: { type: integer } store: { type: object } memory: { type: object } timestamp: { type: string, format: date-time }