Quick Start
Get SpendLil tracking your AI spend in under 2 minutes.
SpendLil sits between your app and your AI provider. You keep your existing API keys, your existing code, your existing provider. You just swap the base URL for the provider-specific SpendLil gateway and add two headers.
Step 1: Create an Account
Sign up at app.spendlil.ai. You'll receive your SpendLil account key — a string starting with sl_ — which identifies your account.
sl_abc123def456 Step 2: Change Your Base URL
Each AI provider has its own SpendLil gateway subdomain. Swap your provider's base URL for the corresponding gateway. The path after the domain stays identical.
| Provider | Direct URL | SpendLil Gateway |
|---|---|---|
| OpenAI | api.openai.com | openai.gateway.spendlil.ai |
| Anthropic | api.anthropic.com | anthropic.gateway.spendlil.ai |
| generativelanguage.googleapis.com | google.gateway.spendlil.ai | |
| Mistral | api.mistral.ai | mistral.gateway.spendlil.ai |
- POST https://api.openai.com/v1/chat/completions
+ POST https://openai.gateway.spendlil.ai/v1/chat/completions
- POST https://api.anthropic.com/v1/messages
+ POST https://anthropic.gateway.spendlil.ai/v1/messages Step 3: Add the Headers
Add two headers: X-SpendLil-Key to identify your account, and X-Provider-Key to pass your provider API key. SpendLil uses X-Provider-Key instead of Authorization to avoid API Gateway intercepting the header.
| Header | Value | Purpose |
|---|---|---|
| X-SpendLil-Key | sl_abc123def456 | Identifies your SpendLil account |
| X-Provider-Key | Bearer sk-your-openai-key | Your provider API key — passed through to the provider |
curl https://openai.gateway.spendlil.ai/v1/chat/completions \
-H "X-SpendLil-Key: sl_abc123def456" \
-H "X-Provider-Key: Bearer sk-your-openai-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello"}]
}' Step 4: Check Your Dashboard
That's it. Your first request auto-discovers your API key and starts tracking spend immediately. Open your dashboard at app.spendlil.ai to see costs by key, provider, and model in real time.
You don't need to create agents, register API keys, or configure anything in the dashboard. SpendLil discovers your keys automatically from the first request.
What Happens Under the Hood
- Your account is validated via the X-SpendLil-Key header
- The provider is determined from the gateway subdomain (openai.gateway, anthropic.gateway, etc.)
- Your provider API key (from X-Provider-Key) is hashed (SHA-256) for identification — never stored
- If it's a new key, a record is created automatically
- The request is forwarded to the AI provider with X-Provider-Key reconstructed as Authorization
- Token usage is extracted from the provider's response
- Cost is calculated and logged
- The provider's response is returned to you with X-SpendLil-Route: governed and X-SpendLil-Request-Id headers
If SpendLil has any issues, you can fall back to calling your provider directly — just swap the URL back and use your normal Authorization header.
Language Examples
const response = await fetch(
'https://openai.gateway.spendlil.ai/v1/chat/completions',
{
method: 'POST',
headers: {
'X-SpendLil-Key': process.env.SPENDLIL_KEY,
'X-Provider-Key': `Bearer ${process.env.OPENAI_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello' }],
}),
}
);
const data = await response.json();
console.log(data.choices[0].message.content); import os
import requests
response = requests.post(
"https://openai.gateway.spendlil.ai/v1/chat/completions",
headers={
"X-SpendLil-Key": os.environ["SPENDLIL_KEY"],
"X-Provider-Key": f"Bearer {os.environ['OPENAI_API_KEY']}",
"Content-Type": "application/json",
},
json={
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello"}],
},
)
data = response.json()
print(data["choices"][0]["message"]["content"]) curl https://openai.gateway.spendlil.ai/v1/chat/completions \
-H "X-SpendLil-Key: $SPENDLIL_KEY" \
-H "X-Provider-Key: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Hello"}]}' Next Steps
- Read the provider-specific guide for OpenAI, Anthropic, Google Gemini, or Mistral
- Learn how auto-discovery works
- Set up spend alerts and budgets
- Understand the resilience model