Appearance
Architecture
AgentWatch is built on Cloudflare's global edge infrastructure to deliver sub-10ms budget enforcement with zero impact on your production traffic.
System Overview
System Overview (Detailed)
┌─────────────────────────────────────────────────────────────┐
│ Your Application │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Standard SDK (OpenAI / Anthropic / any provider) │ │
│ │ ├── HTTP Request formatting │ │
│ │ └── Base URL pointing to AgentWatch │ │
│ └─────────────────────────────────────────────────────┘ │
└───────────────────────────┬─────────────────────────────────┘
│ HTTPS
▼
┌─────────────────────────────────────────────────────────────┐
│ Cloudflare Edge Network │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ AgentWatch Worker │ │
│ │ ├── Authentication (Bearer token + BYOK) │ │
│ │ ├── Rate limiting (per-tenant, native binding) │ │
│ │ ├── Budget check (KV lookup + Durable Object) │ │
│ │ ├── Rule evaluation (custom anomaly rules) │ │
│ │ ├── Data residency routing (EU/US/APAC) │ │
│ │ ├── Proxy routing (10 providers) │ │
│ │ ├── Stream budget enforcement (mid-generation) │ │
│ │ └── Telemetry ingestion → Queue → Supabase │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Cloudflare │ │ Durable │ │ Cloudflare │ │
│ │ KV │ │ Objects │ │ Queues │ │
│ │ (session │ │ (atomic │ │ (telemetry │ │
│ │ state, │ │ counters, │ │ buffer) │ │
│ │ caching) │ │ budget) │ │ │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Supabase (Postgres) │
│ ├── llm_request_logs (telemetry) │
│ ├── developer_keys (API key management) │
│ ├── audit_logs (security audit trail) │
│ ├── sla_records (SLA monitoring) │
│ ├── tenant_rules (custom rules engine) │
│ └── tenant_settings (per-tenant configuration) │
└─────────────────────────────────────────────────────────────┘Request Flow
1. API Call Initiated
Your application initiates a standard completion request via any standard provider SDK (e.g., openai.chat.completions.create()). The SDK constructs the HTTP request and sends it to the AgentWatch proxy URL.
2. Edge Proxy Processing
The Worker receives the request and executes:
- Authentication — Validate Bearer token via KV lookup (primary) or static map fallback
- Rate limiting — Per-tenant rate limit check using native Cloudflare binding
- Rule evaluation — Custom anomaly rules from tenant configuration
- Data residency — Check
x-agentwatch-residencyheader and route to EU endpoints if needed - Proxy routing — Route to the correct upstream provider
- Response forwarding — Stream response back to SDK
- Stream monitoring — If streaming, monitor token usage and terminate if budget exceeded
3. Asynchronous Telemetry
After the response is returned:
- Queue dispatch — Log record sent to Cloudflare Queue
- KV update — Session token count incremented
- Durable Object update — Atomic budget counter updated
- Anomaly check — Rolling window growth ratio analysis
- Supabase write — Queue consumer writes to
llm_request_logs
Supported Providers
| Provider | Base URL | Auth Method |
|---|---|---|
| OpenAI | api.openai.com | Bearer token |
| Anthropic | api.anthropic.com | x-api-key |
| Groq | api.groq.com/openai | Bearer token |
| xAI | api.x.ai | Bearer token |
| Gemini | generativelanguage.googleapis.com | Bearer token |
| Azure OpenAI | {resource}.openai.azure.com | api-key |
| AWS Bedrock | bedrock-runtime.{region}.amazonaws.com | AWS SigV4 |
| Xiaomi MiMo | api.xiaomimimo.com | Bearer token |
| Mistral | api.mistral.ai | Bearer token |
| Cohere | api.cohere.com | Bearer token |
Key Design Decisions
BYOK (Bring Your Own Key)
AgentWatch never stores user API keys. The user combines their AgentWatch token with their provider key:
aw_live_token:sk-proj-real-openai-keyAgentWatch extracts the token for identification and forwards the provider key to the upstream API. This means:
- Zero liability for key storage
- Users pay their own provider bills
- AgentWatch only needs to know the token-to-tenant mapping
Tenant Isolation
All KV keys are namespaced by tenant ID: tenant:token:{token}, tenant:plan:{tenantId}, etc. Cross-tenant data access is impossible through the KV layer.
Timing-Safe Authentication
Token comparison uses crypto.subtle.timingSafeEqual to prevent timing attacks.
Fail-Open vs Fail-Closed
AgentWatch supports both policies:
- Fail-open (default): If AgentWatch infrastructure fails, requests proceed to the provider. Your production stays online.
- Fail-closed: If AgentWatch fails, requests are blocked. Budget is guaranteed, but availability may be impacted.
Enterprise customers can configure this per-tenant.
Telemetry & Reporting
Asynchronous Ingestion
Payload logging and risk scanning are offloaded to ctx.waitUntil() in the Worker. The client receives the provider's response immediately with zero added latency.
Data Collected
- Request metadata (provider, model, latency, status)
- Token counts (prompt, completion)
- Cost estimation
- PII risk tags (email, SSN, credit card, API keys detected)
- Anomaly flags
Data NOT Collected
- Prompt content
- Completion content
- User messages
Performance Characteristics
| Operation | Latency |
|---|---|
| Authentication (KV read) | 5-50ms |
| Budget check (KV read) | 5-50ms |
| Rate limiting (native binding) | <1ms |
| PII detection (100KB) | <50ms |
| Rule evaluation (50 rules) | <10ms |
| Stream budget monitoring | Non-blocking |
| Telemetry dispatch | Non-blocking (async) |
| Total proxy overhead | <100ms (excluding upstream) |
Security
- HSTS on all responses
- X-Content-Type-Options: nosniff on all responses
- X-Frame-Options: DENY on all responses
- Timing-safe token comparison prevents timing attacks
- Header stripping — dangerous headers (host, cookie, x-forwarded-for) are stripped before forwarding to upstream
- CORS configured for
agent-watch.devorigin only