Last updated: 2026-04-12
OpenAI Integration
Route OpenAI API calls through SpendLil for spend tracking.
SpendLil works with all OpenAI API endpoints. Swap api.openai.com for openai.gateway.spendlil.ai and pass your key via X-Provider-Key.
URL Pattern
diff Before → After
- POST https://api.openai.com/v1/chat/completions
+ POST https://openai.gateway.spendlil.ai/v1/chat/completions Supported Endpoints
- /v1/chat/completions — Chat models (GPT-4o, GPT-4o-mini, o1, o3-mini)
- /v1/embeddings — Embedding models
- /v1/images/generations — DALL-E
- /v1/audio/transcriptions — Whisper
- /v1/moderations — Content moderation
Node.js
javascript Using fetch
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: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is SpendLil?' },
],
}),
}
);
const data = await response.json();
console.log(data.choices[0].message.content); Python
python Using requests
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": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is SpendLil?"},
],
},
)
data = response.json()
print(data["choices"][0]["message"]["content"]) Cost Tracking
SpendLil extracts prompt_tokens and completion_tokens from OpenAI's response.usage object and calculates cost using current model pricing.
| Model | Input (per 1M tokens) | Output (per 1M tokens) |
|---|---|---|
| gpt-4o | $2.50 | $10.00 |
| gpt-4o-mini | $0.15 | $0.60 |
| o1 | $15.00 | $60.00 |
| o3-mini | $1.10 | $4.40 |
Key safety
SpendLil never stores your OpenAI API key. It passes through via X-Provider-Key directly to OpenAI. We store only a SHA-256 hash for identification and the last 4 characters as a visual hint in your dashboard.