{"openapi":"3.1.0","info":{"title":"Edge AI Guardrail & Cost-Circuit Breaker Proxy","version":"0.2.0","description":"Ultra-low-latency Cloudflare Workers reverse proxy for OpenAI, Anthropic, and Gemini with 50ms Fail-Open (or opt-in Fail-Closed) SLA, near-loop protection, RPM & hourly/daily/monthly spend caps, edge secret/PII redaction, and Remote Streamable HTTP MCP."},"servers":[{"url":"https://guardrail.fyi","description":"Edge Gateway"}],"components":{"securitySchemes":{"GuardKeyAuth":{"type":"apiKey","in":"header","name":"x-guard-key","description":"Customer Edge Guardrail API key."},"AdminKeyAuth":{"type":"apiKey","in":"header","name":"x-admin-key","description":"Operator admin API key for provisioning and managing customer keys."}},"schemas":{"CircuitBreakerError":{"type":"object","required":["error"],"properties":{"error":{"type":"string","enum":["circuit_breaker_loop_detected","circuit_breaker_budget_exceeded","circuit_breaker_rate_limit_exceeded"]}}},"CustomerSettings":{"type":"object","properties":{"keyId":{"type":"string"},"tier":{"type":"string","enum":["free","starter","pro","scale","enterprise"]},"active":{"type":"boolean"},"hourlyCapMicroUsd":{"type":"integer"},"dailyCapMicroUsd":{"type":"integer"},"monthlyCapMicroUsd":{"type":"integer"},"rpmLimit":{"type":"integer"},"failMode":{"type":"string","enum":["open","closed"]},"redactPii":{"type":"boolean"},"alertOnRedaction":{"type":"boolean"},"alertWebhookUrl":{"type":["string","null"],"format":"uri"}}},"PatchSettingsRequest":{"type":"object","properties":{"alertWebhookUrl":{"type":["string","null"],"format":"uri","description":"Public HTTPS Slack/Discord/custom webhook URL, or null to clear."},"hourlyCapMicroUsd":{"type":"integer","minimum":1,"description":"Optional stricter hourly spend cap in micro-USD (<= monthlyCapMicroUsd)."},"dailyCapMicroUsd":{"type":"integer","minimum":1,"description":"Optional stricter daily spend cap in micro-USD (<= monthlyCapMicroUsd)."},"failMode":{"type":"string","enum":["open","closed"]},"redactPii":{"type":"boolean"},"alertOnRedaction":{"type":"boolean"}}},"UsageResponse":{"type":"object","properties":{"keyId":{"type":"string"},"tier":{"type":"string","enum":["free","starter","pro","scale","enterprise"]},"spendUsd":{"type":"object","properties":{"hourly":{"type":"number"},"daily":{"type":"number"},"monthly":{"type":"number"}}},"capsUsd":{"type":"object","properties":{"hourly":{"type":"number"},"daily":{"type":"number"},"monthly":{"type":"number"}}},"remainingUsd":{"type":"object","properties":{"hourly":{"type":"number"},"monthly":{"type":"number"}}},"counters":{"type":"object","properties":{"requestsToday":{"type":"integer"},"inputTokensToday":{"type":"integer"},"outputTokensToday":{"type":"integer"},"redactions":{"type":"integer"},"blockedLoops":{"type":"integer"},"blockedBudget":{"type":"integer"},"blockedRateLimit":{"type":"integer"}}}}}}},"paths":{"/health":{"get":{"summary":"Health check","responses":{"200":{"description":"Worker is healthy"}}}},"/v1/trial":{"post":{"summary":"Provision an instant free trial x-guard-key ($2/hr, $5/mo BYOK spend cap, 20 RPM, max 3 per IP/24h)","responses":{"201":{"description":"Newly generated gk_live_* trial key and quickstart URLs"},"429":{"description":"Daily trial rate limit exceeded for caller IP"}}}},"/.well-known/mcp.json":{"get":{"summary":"MCP server discovery descriptor and client config snippet","responses":{"200":{"description":"MCP discovery metadata"}}}},"/llms-full.txt":{"get":{"summary":"Full Markdown documentation and copy-paste examples for AI coding agents","responses":{"200":{"description":"Markdown agent playbook"}}}},"/v1/chat/completions":{"post":{"summary":"Transparent OpenAI Chat Completions Proxy (JSON & SSE)","security":[{"GuardKeyAuth":[]}],"parameters":[{"name":"Authorization","in":"header","required":true,"schema":{"type":"string"},"description":"Native OpenAI Bearer token forwarded upstream."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["model","messages"],"properties":{"model":{"type":"string"},"stream":{"type":"boolean"},"messages":{"type":"array","items":{"type":"object"}}}}}}},"responses":{"200":{"description":"Upstream response or SSE stream","headers":{"X-Guardrail-Status":{"schema":{"type":"string","enum":["passed","fail-open"]}},"X-Guardrail-Provider":{"schema":{"type":"string"}},"X-Guardrail-Redacted":{"schema":{"type":"string"}}}},"429":{"description":"Circuit breaker tripped (loop, budget, or RPM limit)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CircuitBreakerError"}}}},"503":{"description":"Returned only when failMode=\"closed\" and guardrail state is unreachable"}}}},"/v1/messages":{"post":{"summary":"Transparent Anthropic Messages Proxy (JSON & SSE)","security":[{"GuardKeyAuth":[]}],"responses":{"200":{"description":"Upstream Anthropic response or SSE stream"},"429":{"description":"Circuit breaker tripped"}}}},"/v1beta/models/{model}:generateContent":{"post":{"summary":"Transparent Google Gemini Proxy (JSON & SSE)","security":[{"GuardKeyAuth":[]}],"parameters":[{"name":"model","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Upstream Gemini response or SSE stream"},"429":{"description":"Circuit breaker tripped"}}}},"/v1/usage":{"get":{"summary":"Get real-time spend, budget caps, and guardrail counters","security":[{"GuardKeyAuth":[]}],"responses":{"200":{"description":"Usage metrics snapshot","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UsageResponse"}}}}}}},"/v1/settings":{"get":{"summary":"Get customer guardrail policy and alert webhook configuration","security":[{"GuardKeyAuth":[]}],"responses":{"200":{"description":"Active customer settings","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CustomerSettings"}}}}}},"patch":{"summary":"Configure HTTPS alertWebhookUrl, PII redaction, failMode, or tighten caps","security":[{"GuardKeyAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatchSettingsRequest"}}}},"responses":{"200":{"description":"Updated customer settings","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CustomerSettings"}}}},"400":{"description":"Invalid webhook URL or cap exceeds plan limit"}}}},"/v1/key/rotate":{"post":{"summary":"Rotate customer x-guard-key and revoke the previous key atomically","security":[{"GuardKeyAuth":[]}],"responses":{"200":{"description":"New gk_live_* API key issued","content":{"application/json":{"schema":{"type":"object","required":["apiKey","keyId","rotatedAt"],"properties":{"apiKey":{"type":"string"},"keyId":{"type":"string"},"rotatedAt":{"type":"string","format":"date-time"}}}}}}}}},"/mcp":{"get":{"summary":"Remote Streamable HTTP MCP discovery metadata and tool list","responses":{"200":{"description":"MCP server metadata and client config"}}},"post":{"summary":"Remote Streamable HTTP MCP JSON-RPC 2.0 endpoint","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["jsonrpc","method"],"properties":{"jsonrpc":{"type":"string","const":"2.0"},"id":{"type":["string","integer","null"]},"method":{"type":"string","enum":["initialize","ping","tools/list","tools/call"]},"params":{"type":"object"}}}}}},"responses":{"200":{"description":"JSON-RPC 2.0 response"},"204":{"description":"Notification acknowledged"}}}},"/demo/simulate":{"post":{"summary":"Public IP-rate-limited sandbox testing secret redaction and 6x loop detection","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"model":{"type":"string"},"messages":{"type":"array","items":{"type":"object"}}}}}}},"responses":{"200":{"description":"Sanitized payload and current loop count"},"429":{"description":"Loop tripped or demo IP rate limit reached"}}}},"/admin/keys":{"get":{"summary":"List provisioned customer guard keys","security":[{"AdminKeyAuth":[]}],"responses":{"200":{"description":"List of key records"}}},"post":{"summary":"Provision a new customer guard key","security":[{"AdminKeyAuth":[]}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CustomerSettings"}}}},"responses":{"201":{"description":"Provisioned key and policy"}}}},"/admin/keys/{keyId}":{"patch":{"summary":"Update a customer key tier, caps, active status, failMode, or alertWebhookUrl","security":[{"AdminKeyAuth":[]}],"parameters":[{"name":"keyId","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PatchSettingsRequest"}}}},"responses":{"200":{"description":"Updated key record"}}},"delete":{"summary":"Immediately revoke a customer key (active: false)","security":[{"AdminKeyAuth":[]}],"parameters":[{"name":"keyId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Key revoked"}}}},"/admin/keys/{keyId}/rotate":{"post":{"summary":"Issue a replacement gk_live_* key for a customer while preserving Stripe mappings","security":[{"AdminKeyAuth":[]}],"parameters":[{"name":"keyId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Rotated key issued"}}}},"/webhooks/stripe":{"post":{"summary":"Stripe webhook for idempotent key provisioning, upgrades, and revocations","responses":{"200":{"description":"Webhook processed"},"401":{"description":"Invalid Stripe-Signature"}}}}}}