Last updated: 2026-04-12

Anthropic Integration

Route Anthropic Claude API calls through SpendLil.

SpendLil proxies Anthropic's Messages API. Swap api.anthropic.com for anthropic.gateway.spendlil.ai.

URL Pattern

diff Before → After
- POST https://api.anthropic.com/v1/messages
+ POST https://anthropic.gateway.spendlil.ai/v1/messages

Node.js

javascript Using fetch
const response = await fetch(
  'https://anthropic.gateway.spendlil.ai/v1/messages',
  {
    method: 'POST',
    headers: {
      'X-SpendLil-Key': process.env.SPENDLIL_KEY,
      'X-Provider-Key': `Bearer ${process.env.ANTHROPIC_API_KEY}`,
      'Content-Type': 'application/json',
      'anthropic-version': '2023-06-01',
    },
    body: JSON.stringify({
      model: 'claude-sonnet-4-5-20250514',
      max_tokens: 1024,
      messages: [{ role: 'user', content: 'What is SpendLil?' }],
    }),
  }
);

const data = await response.json();
console.log(data.content[0].text);

Python

python Using requests
import os
import requests

response = requests.post(
    "https://anthropic.gateway.spendlil.ai/v1/messages",
    headers={
        "X-SpendLil-Key": os.environ["SPENDLIL_KEY"],
        "X-Provider-Key": f"Bearer {os.environ['ANTHROPIC_API_KEY']}",
        "Content-Type": "application/json",
        "anthropic-version": "2023-06-01",
    },
    json={
        "model": "claude-sonnet-4-5-20250514",
        "max_tokens": 1024,
        "messages": [{"role": "user", "content": "What is SpendLil?"}],
    },
)

data = response.json()
print(data["content"][0]["text"])

Cost Tracking

ModelInput (per 1M tokens)Output (per 1M tokens)
claude-opus-4-5$15.00$75.00
claude-sonnet-4-5$3.00$15.00
claude-haiku-4-5$0.80$4.00

Prompt Caching

Anthropic's prompt caching headers and cache_control blocks pass through SpendLil unmodified. Cached token pricing is tracked when Anthropic includes cache read/write token counts in the response.