> ## Documentation Index
> Fetch the complete documentation index at: https://www.aptible.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Secure Anthropic-compatible SDKs with the LLM Gateway

> Point any Anthropic-compatible SDK at Aptible's LLM Gateway for a compliant, audited path to your models.

## Overview

This guide walks through creating an LLM Key and configuring an Anthropic-compatible SDK to call Aptible's LLM Gateway instead of Anthropic directly, so every request is authenticated, audited, and covered by your organization's [Model Access Policy](https://www.aptible.com/docs/llm-gateway/model-access-policies.md) and [Spend Limit](https://www.aptible.com/docs/llm-gateway/cost-control.md).

## Create an LLM Key

**1. Start your trial or sign in**

[Sign up](https://app.aptible.com/signup) for or [sign in](https://app.aptible.com/login) to your Aptible account. Then navigate to [LLM Gateway](https://app.aptible.com/llm-gateway) to activate your trial. If you signed up with a business email, you'll receive \$100 of LLM credits to get started. You can use them with any models your organization allows.

> [!WARNING]
>
> **For those processing PHI:** you'll need to execute a BAA before you can start processing PHI using the LLM Gateway. Go to **Settings > [Agreements](https://app.aptible.com/settings/legal/agreements)** to execute one.

**2. Create an LLM key**

Click **Create Key** on the [LLM Gateway](https://app.aptible.com/llm-gateway) page and give it a descriptive name so you can identify its usage later when reviewing costs and request history.

LLM Keys are scoped to your whole organization — any member can create and manage them, and a single key gives you access to every model your organization's [model access policy](https://www.aptible.com/docs/llm-gateway/model-access-policies.md) allows.

Once created, copy the key's token and endpoint URL. You won't be able to see the token again after you close this window.

> [!TIP]
>
> If a key's token is ever lost or compromised, revoke it from [LLM Gateway](https://app.aptible.com/llm-gateway) and create a new one — see [LLM Keys](https://www.aptible.com/docs/llm-gateway/llm-keys.md) for details.

## Configure your SDK

Point your SDK's base URL at the LLM Gateway's Anthropic-compatible endpoint, `https://llm-gateway.aptible.com/anthropic`, and use your LLM Key as the API key. See [Supported APIs](https://www.aptible.com/docs/llm-gateway/supported-apis.md) for the full list of Anthropic-compatible endpoints.

```python Python theme={null}
import anthropic

client = anthropic.Anthropic(
    api_key="<YOUR_LLM_KEY>",
    base_url="https://llm-gateway.aptible.com/anthropic",
)

message = client.messages.create(
    model="claude-sonnet-5",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Tell me a joke about cloud security"}
    ],
)

print(message.content[0].text)
```

```javascript Node.js theme={null}
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: "<YOUR_LLM_KEY>",
  baseURL: "https://llm-gateway.aptible.com/anthropic",
});

const message = await client.messages.create({
  model: "claude-sonnet-5",
  max_tokens: 1024,
  messages: [
    { role: "user", content: "Tell me a joke about cloud security" },
  ],
});

console.log(message.content[0].text);
```

```bash curl theme={null}
curl https://llm-gateway.aptible.com/anthropic/v1/messages \
  -H "x-api-key: <YOUR_LLM_KEY>" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Tell me a joke about cloud security"}
    ]
  }'
```

Replace `"claude-sonnet-5"` with any model ID from [Supported Models](https://www.aptible.com/docs/llm-gateway/supported-models.md) that your organization's [Model Access Policy](https://www.aptible.com/docs/llm-gateway/model-access-policies.md) allows.

> [!TIP]
>
> Environment variables also work, if your SDK or framework reads them: set `ANTHROPIC_API_KEY` (or `ANTHROPIC_AUTH_TOKEN`) to your LLM Key and `ANTHROPIC_BASE_URL` to `https://llm-gateway.aptible.com/anthropic`.

> [!TIP]
>
> Using prompt caching? Send a `session-id` header that stays the same for each conversation, so its requests keep hitting the same cache. See [Prompt caching](https://www.aptible.com/docs/llm-gateway/supported-apis.md#prompt-caching).

## Verify it's working

Run the snippet above. If you get a response back, requests are flowing through the LLM Gateway. You can confirm this by checking the key’s request history in [LLM Gateway](https://app.aptible.com/llm-gateway) to confirm, or see [Audit Logging](https://www.aptible.com/docs/llm-gateway/audit-logging.md) for more ways to review your request.

## Troubleshooting

> [accordion] 401 Unauthorized
>
> Double-check your API key is set to a valid, unrevoked LLM Key, and that the base URL points at `https://llm-gateway.aptible.com/anthropic`.

> [accordion] 400 for an unrecognized or blocked model
>
> Check that the model you're requesting is a valid model ID from [Supported Models](https://www.aptible.com/docs/llm-gateway/supported-models.md), and that it's allowed by your organization's [Model Access Policy](https://www.aptible.com/docs/llm-gateway/model-access-policies.md).

> [accordion] 402 Payment Required
>
> Your organization has reached its monthly spend limit. See [Cost Visibility & Control](https://www.aptible.com/docs/llm-gateway/cost-control.md).
