Last updated: 2026-04-20

How the Proxy Works

Understanding SpendLil's transparent proxy architecture.

SpendLil operates as a transparent proxy between your application and your AI provider. It observes and logs every request without modifying, storing, or blocking anything.

Provider Gateways

Each AI provider has its own gateway subdomain. You swap your provider's base URL for the corresponding gateway — the path stays identical.

ProviderGatewayUpstream
OpenAIopenai.gateway.spendlil.aiapi.openai.com
Anthropicanthropic.gateway.spendlil.aiapi.anthropic.com
Googlegoogle.gateway.spendlil.aigenerativelanguage.googleapis.com
Mistralmistral.gateway.spendlil.aiapi.mistral.ai
Groqgroq.gateway.spendlil.aiapi.groq.com
DeepSeekdeepseek.gateway.spendlil.aiapi.deepseek.com
xAI (Grok)xai.gateway.spendlil.aiapi.x.ai
Togethertogether.gateway.spendlil.aiapi.together.xyz
Fireworksfireworks.gateway.spendlil.aiapi.fireworks.ai
Perplexityperplexity.gateway.spendlil.aiapi.perplexity.ai
OpenRouteropenrouter.gateway.spendlil.aiopenrouter.ai/api
Coherecohere.gateway.spendlil.aiapi.cohere.com

The Request Flow

  1. Your request hits the provider-specific gateway (e.g., openai.gateway.spendlil.ai/v1/chat/completions)
  2. The X-SpendLil-Key header is validated against DynamoDB to identify your account
  3. The provider is determined from the gateway subdomain
  4. Your provider API key (extracted from Authorization / x-api-key / x-goog-api-key) is hashed with SHA-256 — the key itself is never stored
  5. If this is a new key hash, a record is created automatically (auto-discovery)
  6. The request is forwarded to the upstream provider with your original auth header intact
  7. The provider processes the request and returns a response
  8. SpendLil extracts token usage counts from the response body
  9. Cost is calculated using the model pricing table and your account's currency
  10. A usage record is written to DynamoDB (fire-and-forget)
  11. Your daily spend counter is atomically incremented
  12. The provider's response is returned to your app with X-SpendLil-Route and X-SpendLil-Request-Id headers
💡 Fire-and-forget logging

Usage logging is non-blocking. If the DynamoDB write fails, you still get your AI response.

Headers

HeaderDirectionDescription
X-SpendLil-KeyRequestYour SpendLil account key (sl_...). Required.
AuthorizationRequestYour provider API key for OpenAI, Mistral, Cohere, Groq, DeepSeek, xAI, Together, Fireworks, Perplexity, OpenRouter. Passed through unchanged.
x-api-keyRequestAnthropic native auth. Passed through unchanged.
x-goog-api-keyRequestGoogle Gemini auth. Passed through unchanged.
X-SpendLil-TagRequestOptional label for filtering spend by workload (max 64 chars)
X-SpendLil-RouteResponsegoverned (tracked) or bypassed (tracking failed)
X-SpendLil-Request-IdResponseUnique ID for this proxied request

What SpendLil Does NOT Do

  • Does not store your API keys — passthrough only
  • Does not modify your request body
  • Does not modify the provider's response body
  • Does not block or rate-limit any requests
  • Does not read or store the content of your prompts or completions

Infrastructure

The proxy runs on AWS Lambda behind API Gateway in eu-west-2 (London). Each provider subdomain has its own API Gateway custom domain with Route 53 health checks and UptimeRobot monitoring. All gateways report to status.spendlil.ai.