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 SDK code, your existing provider. You just swap the base URL for the provider-specific SpendLil gateway and add one header.
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 |
| Groq | api.groq.com | groq.gateway.spendlil.ai |
| DeepSeek | api.deepseek.com | deepseek.gateway.spendlil.ai |
| xAI (Grok) | api.x.ai | xai.gateway.spendlil.ai |
| Together | api.together.xyz | together.gateway.spendlil.ai |
| Fireworks | api.fireworks.ai | fireworks.gateway.spendlil.ai |
| Perplexity | api.perplexity.ai | perplexity.gateway.spendlil.ai |
| OpenRouter | openrouter.ai/api | openrouter.gateway.spendlil.ai |
| Cohere | api.cohere.com | cohere.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 X-SpendLil-Key
Add one new header: X-SpendLil-Key, set to your account key. Keep your existing provider auth header (Authorization: Bearer, x-api-key, or x-goog-api-key) exactly as it is — SpendLil passes it through unchanged. The official provider SDKs all work without modification.
| Header | Value | Purpose |
|---|---|---|
| X-SpendLil-Key | sl_abc123def456 | Identifies your SpendLil account (required) |
| Authorization | Bearer sk-your-key | Your provider API key — OpenAI, Mistral, Groq, DeepSeek, xAI, Together, Fireworks, Perplexity, OpenRouter, Cohere |
| x-api-key | sk-ant-your-key | Anthropic native auth (Authorization: Bearer also accepted) |
| x-goog-api-key | AIza-your-key | Google Gemini |
| X-SpendLil-Tag | chatbot | Optional label for filtering spend by workload (max 64 chars) |
curl https://openai.gateway.spendlil.ai/v1/chat/completions \
-H "Authorization: Bearer sk-your-openai-key" \
-H "X-SpendLil-Key: sl_abc123def456" \
-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, groq.gateway, etc.)
- Your provider API 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 your auth header intact
- 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 to the real provider. Your existing auth header is already correct; nothing else needs to change.
Language Examples
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: 'https://openai.gateway.spendlil.ai/v1',
defaultHeaders: {
'X-SpendLil-Key': process.env.SPENDLIL_KEY,
},
});
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello' }],
});
console.log(response.choices[0].message.content); import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ['OPENAI_API_KEY'],
base_url='https://openai.gateway.spendlil.ai/v1',
default_headers={'X-SpendLil-Key': os.environ['SPENDLIL_KEY']},
)
response = client.chat.completions.create(
model='gpt-4o',
messages=[{'role': 'user', 'content': 'Hello'}],
)
print(response.choices[0].message.content) curl https://openai.gateway.spendlil.ai/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "X-SpendLil-Key: $SPENDLIL_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Hello"}]}' Next Steps
- Read the provider-specific guide for the AI service you use
- Learn how auto-discovery works
- Set up spend alerts and budgets
- Understand the resilience model