Last updated: 2026-04-20

Anthropic Integration

Route Anthropic Claude API calls through SpendLil.

SpendLil proxies Anthropic's Messages API. Swap api.anthropic.com for anthropic.gateway.spendlil.ai and add X-SpendLil-Key. Your existing x-api-key header (or Authorization: Bearer) passes through unchanged — the official Anthropic SDKs work without modification.

URL Pattern

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

Anthropic SDK (Python)

python pip install anthropic
import os
from anthropic import Anthropic

client = Anthropic(
    api_key=os.environ['ANTHROPIC_API_KEY'],
    base_url='https://anthropic.gateway.spendlil.ai',
    default_headers={
        'X-SpendLil-Key': os.environ['SPENDLIL_KEY'],
        'X-SpendLil-Tag': 'my-chatbot',  # optional
    },
)

message = client.messages.create(
    model='claude-sonnet-4-5',
    max_tokens=1024,
    messages=[{'role': 'user', 'content': 'Hello'}],
)
print(message.content[0].text)

Anthropic SDK (Node.js)

javascript npm install @anthropic-ai/sdk
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
  baseURL: 'https://anthropic.gateway.spendlil.ai',
  defaultHeaders: {
    'X-SpendLil-Key': process.env.SPENDLIL_KEY,
    'X-SpendLil-Tag': 'my-chatbot', // optional
  },
});

const message = await client.messages.create({
  model: 'claude-sonnet-4-5',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Hello' }],
});
console.log(message.content[0].text);

cURL

bash Direct HTTP request
curl https://anthropic.gateway.spendlil.ai/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "X-SpendLil-Key: $SPENDLIL_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello"}]
  }'
Auth header options

Anthropic accepts either x-api-key (native) or Authorization: Bearer. SpendLil passes both through unchanged. Use whichever your SDK or tooling prefers.

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.