# Anthropic integration

## Base URL

```
https://www.spendline.ai
```

**Without `/v1`.** The Anthropic SDK appends `/v1/messages` itself. If you add
`/v1` here you will get requests to `/v1/v1/messages` and a 404.

This is the single most common Spendline integration mistake. The OpenAI SDK
needs `/v1`; the Anthropic SDK does not. Both are correct.

## Auth

| Header | Value |
|---|---|
| `x-api-key` | The application's **own Anthropic key**. Forwarded upstream. |
| `x-spendline-key` | The **Spendline** key. Consumed by Spendline. |

Because Anthropic already owns `x-api-key`, the Spendline key **must** travel in
`x-spendline-key`. Putting it in `x-api-key` sends your Spendline key to
Anthropic, which rejects it.

## Python

```python
import os
from anthropic import Anthropic

client = Anthropic(
    base_url="https://www.spendline.ai",            # no /v1
    api_key=os.environ["ANTHROPIC_API_KEY"],
    default_headers={
        "x-spendline-key": os.environ["SPENDLINE_API_KEY"],
        "x-agent-id": "support-bot",
        "x-spendline-tags": '{"team":"support"}',
    },
)

msg = client.messages.create(
    model="claude-sonnet-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Draft a reply."}],
    extra_headers={"x-customer-id": customer_id},
)
```

## TypeScript

```ts
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "https://www.spendline.ai",              // no /v1
  apiKey: process.env.ANTHROPIC_API_KEY!,
  defaultHeaders: {
    "x-spendline-key": process.env.SPENDLINE_API_KEY!,
    "x-agent-id": "support-bot",
    "x-spendline-tags": '{"team":"support"}',
  },
});

await client.messages.create(
  {
    model: "claude-sonnet-5",
    max_tokens: 1024,
    messages: [{ role: "user", content: "Draft a reply." }],
  },
  { headers: { "x-customer-id": customerId } },
);
```

## curl

```bash
curl https://www.spendline.ai/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "x-spendline-key: $SPENDLINE_API_KEY" \
  -H "x-agent-id: smoke-test" \
  -H "x-customer-id: cus_123" \
  -H 'x-spendline-tags: {"team":"platform"}' \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-sonnet-5","max_tokens":64,"messages":[{"role":"user","content":"hello"}]}'
```

## Streaming

Supported. Pass `stream: true` as normal.

## LangChain / Vercel AI SDK

`ChatAnthropic` and `createAnthropic({ baseURL: "https://www.spendline.ai" })`, 
same rule, no `/v1`.
