Last updated: 2026-04-20
Google Gemini Integration
Route Google Gemini API calls through SpendLil.
SpendLil proxies Google's Generative AI API. Swap generativelanguage.googleapis.com for google.gateway.spendlil.ai and add X-SpendLil-Key. Your existing x-goog-api-key header passes through unchanged.
URL Pattern
diff Before → After
- POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent
+ POST https://google.gateway.spendlil.ai/v1beta/models/gemini-2.0-flash:generateContent Google SDK base URL
Google's official SDKs don't currently expose a base URL override. Use the REST API directly (shown below) or set up an HTTP client that supports custom base URLs.
cURL
bash Direct HTTP request
curl https://google.gateway.spendlil.ai/v1beta/models/gemini-2.0-flash:generateContent \
-H "x-goog-api-key: $GOOGLE_API_KEY" \
-H "X-SpendLil-Key: $SPENDLIL_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{"parts": [{"text": "Hello"}]}]
}' Python (httpx)
python Direct REST call
import os
import httpx
response = httpx.post(
'https://google.gateway.spendlil.ai/v1beta/models/gemini-2.0-flash:generateContent',
headers={
'x-goog-api-key': os.environ['GOOGLE_API_KEY'],
'X-SpendLil-Key': os.environ['SPENDLIL_KEY'],
},
json={'contents': [{'parts': [{'text': 'Hello'}]}]},
)
data = response.json()
print(data['candidates'][0]['content']['parts'][0]['text']) Node.js (fetch)
javascript Direct REST call
const response = await fetch(
'https://google.gateway.spendlil.ai/v1beta/models/gemini-2.0-flash:generateContent',
{
method: 'POST',
headers: {
'x-goog-api-key': process.env.GOOGLE_API_KEY,
'X-SpendLil-Key': process.env.SPENDLIL_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
contents: [{ parts: [{ text: 'Hello' }] }],
}),
}
);
const data = await response.json();
console.log(data.candidates[0].content.parts[0].text); Cost Tracking
SpendLil extracts usageMetadata.promptTokenCount and usageMetadata.candidatesTokenCount from Google's response and calculates cost using current model pricing.
| Model | Input (per 1M tokens) | Output (per 1M tokens) |
|---|---|---|
| gemini-2.0-flash | $0.10 | $0.40 |
| gemini-2.0-pro | $1.25 | $10.00 |