API Documentation
Complete REST API reference for AgentWatch. The gateway exposes an OpenAI-compatible LLM API and a separate admin REST API.
Two Authentication Methods
API Key (Bearer) — For LLM endpoints (/v1/*), pass your tenant API key as Authorization: Bearer <api-key>.
JWT Token — For Admin endpoints (/api/*), login via POST /api/auth/login to receive a JWT valid for 24 hours.
Authenticate a user and receive a JWT token. Include the token in subsequent admin API requests as Authorization: Bearer <token>.
Request Body
| Field | Type | Description |
|---|---|---|
| email* | string | User's email address |
| password* | string | User's password |
curl -X POST http://localhost:8787/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "admin@example.com", "password": "your-password"}'
Returns the authenticated user's profile, organization, and role information.
Sliding Window Algorithm
Default: 1,000 tokens/minute with a refill rate of 100 tokens/second.
Configurable per tenant. Rate limit headers: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset.
When exceeded: HTTP 429 Too Many Requests with a Retry-After header.
| Code | Meaning | Common Cause |
|---|---|---|
| 400 | Bad Request | Invalid request body or DLP policy violation |
| 401 | Unauthorized | Missing or invalid API key / JWT token |
| 403 | Forbidden | Insufficient role permissions |
| 404 | Not Found | Resource doesn't exist |
| 423 | Locked | Account locked due to failed login attempts |
| 429 | Too Many Requests | Rate limit exceeded for this tenant |
| 402 | Payment Required | Budget exceeded for this tenant/team |
| 502 | Bad Gateway | Upstream LLM provider error |
Lists all available models across configured providers. Results are cached for 30 seconds.
curl http://localhost:8787/v1/models \
-H "Authorization: Bearer sk-tenant-your-api-key"
Admin API Authentication
All /api/* endpoints require a valid JWT token from POST /api/auth/login. Pass it as Authorization: Bearer <token>. Tokens expire after 24 hours.
Invalidates the current JWT session token.
Returns all LLM providers with status, health information, and configuration. Scoped to the authenticated user's organization.
Adds a new LLM provider. Types: openai, anthropic, openrouter, google, custom.
Request Body
| Field | Type | Description |
|---|---|---|
| name* | string | Display name |
| kind* | string | openai | anthropic | openrouter | google | custom |
| base_url* | string | Provider API base URL |
| priority | integer | Routing priority (default: 100) |
| enabled | boolean | Active state (default: true) |
Tests connectivity to a provider's API and returns latency and status.
Encrypted at Rest
All provider API keys are stored encrypted using AES-256-GCM. Keys are never returned in full from the API — only the first/last 4 characters are shown after creation.
Returns all API keys configured for the given provider (masked — first/last 4 chars only).
Adds and encrypts a new API key for a provider. Set concurrency and RPM limits.
Request Body
| Field | Type | Description |
|---|---|---|
| key* | string | The plaintext API key (encrypted on write) |
| label | string | Friendly label for this key |
| concurrency_limit | integer | Max concurrent requests (default: 10) |
| rpm_limit | integer | Max requests per minute |
Returns all API consumer entities (tenants) with their keys and usage stats. Optionally filter by team or status.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
| team_id | integer | Filter by team |
| status | string | active | inactive | suspended |
Creates a new tenant with auto-generated API key, budget limits, and optional team assignment.
Request Body
| Field | Type | Description |
|---|---|---|
| name* | string | Tenant display name |
| team_id | integer | Assign to a team |
| daily_budget | number | Daily spending limit in USD |
| monthly_budget | number | Monthly spending limit in USD |
| rate_limit | integer | Requests per minute limit |
Returns usage records with tokens, costs, latencies, and DLP events. Paginated. Scoped to the organization.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
| start_date | string | ISO 8601 start date filter |
| end_date | string | ISO 8601 end date filter |
| tenant_id | integer | Filter by specific tenant |
| team_id | integer | Filter by team |
| page | integer | Page number (default: 1) |
| limit | integer | Records per page (default: 50, max: 1000) |
Returns aggregated totals: total requests, tokens, costs, and DLP events for the current period. Used by the dashboard.
Returns overall system health including database connectivity, provider statuses, memory, and uptime. No authentication required.
curl http://localhost:8787/health
Prometheus-format metrics: request counts by tenant/model, latency histograms (P50/P95/P99), error rates, cache hit rates, and provider health gauges.
MCP Server — Port 4000
The knowledge extraction server runs on port 4000 and exposes repository indexing, semantic search, and security scanning via the Model Context Protocol (MCP) and REST API.
Submits a repository for indexing. AgentWatch clones the repo, parses it with Tree-sitter, builds a symbol/dependency graph, and stores vectors in LanceDB for semantic search.
Request Body
| Field | Type | Description |
|---|---|---|
| url* | string | Git repository URL (HTTPS) |
| branch | string | Branch to index (default: main) |
| run_security_scan | boolean | Run Semgrep + Trivy scan after index |
Returns the current indexing status, progress percentage, file count, node/edge counts in the symbol graph, and any errors.
Triggers a security scan on the indexed repository using Semgrep (SAST) and Trivy (infrastructure vulnerabilities). Returns findings with severity, file path, and rule IDs.