Multi-Tenant AI Content Generation Gateway and Quota Orchestration Plan
Design a resilient, cost-controlled backend proxy and API gateway for high-throughput AI copywriting applications.
Use this template when developing a dedicated backend gateway for generative AI copywriting tools that manage multi-tenant billing, model failover, semantic caching, and strict quota allocations across tiers.
Role: Lead API Platform Engineer specialized in resilient proxy gateways, rate-limiting algorithms, and high-concurrency LLM routing.
Context
- Multi-tenant tier categorization: {{tenant_tier_structure}}
- Upstream LLM provider targets: {{llm_provider_endpoints}}
- Per-tier token and cost allocations: {{token_budget_per_tier}}
- Semantic caching persistence and TTL: {{cache_ttl_strategy}}
- Failover and fallback model rules: {{failover_routing_policy}}
- Analytical and cost-tracking destination: {{analytics_sink}}
Task
Draft a comprehensive implementation plan for an intelligent AI routing and caching API gateway that services copywriting microservices across {{tenant_tier_structure}}, enforces {{token_budget_per_tier}}, and minimizes latency via {{cache_ttl_strategy}}.
Method
- Design the token bucket and leaky bucket rate-limiting algorithms applied across {{tenant_tier_structure}}.
- Specify the vector-based semantic cache lookup layer using {{cache_ttl_strategy}} to short-circuit identical copy prompts.
- Architect the provider abstraction router to load-balance traffic across {{llm_provider_endpoints}}.
- Map dynamic failover cascades according to {{failover_routing_policy}} when upstream providers return 429 or 5xx status codes.
- Establish streaming response handling using Server-Sent Events (SSE) while computing real-time token usage.
- Detail the asynchronous usage accounting pipeline reporting exact token costs to {{analytics_sink}}.
- Formulate safety filters, prompt injection guards, and output sanitization interceptors.
Constraints
- MUST calculate and deduct estimated token costs prior to upstream dispatch to prevent quota overages.
- MUST NOT persist raw proprietary copywriting outputs in unencrypted semantic cache stores.
- Upstream failover transitions must occur within 250ms of receiving a 5xx response from any provider in {{llm_provider_endpoints}}.
- Gateway routing logic must include zero provider-specific SDK lock-in, relying purely on standardized HTTP interfaces.
Output format
-
- Gateway Pipeline Architecture (Middleware execution order and proxy layers)
-
- Rate-Limiting & Quota Management Plan (Algorithm design and distributed Redis key scheme)
-
- Semantic Caching Subsystem (Vector store indexing, distance thresholds, TTL enforcement)
-
- Dynamic Failover & Model Routing Engine (State-machine rules and fallback chains)
-
- Streaming & Cost Ledger Implementation (SSE pipe model and {{analytics_sink}} ingestion schema)
Self-review
- Are all rate-limiting edge cases (e.g., streaming disconnects mid-generation) accounted for in {{token_budget_per_tier}} calculations?
- Does the failover mechanism avoid cascading thundering herd problems across {{llm_provider_endpoints}}?
- Are vector embeddings for semantic cache lookups evaluated with strict similarity thresholds?
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.