Skip to main content

Anthropic SDK Integration

Integrate Proxy with the Anthropic SDK to automatically capture telemetry. Demonstrated with Anthropic’s Python SDK but should work in most languages.

Base URL

https://gateway.adaline.ai/v1/anthropic/

Chat Completions

Complete Chat

import anthropic

client = anthropic.Anthropic(
    api_key="your-anthropic-api-key",
    base_url="https://gateway.adaline.ai/v1/anthropic/"
)

headers = {
    "adaline-api-key": "your-adaline-api-key",
    "adaline-project-id": "your-project-id",
    "adaline-prompt-id": "your-prompt-id"
}

response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1000,
    messages=[
        {"role": "user", "content": "What is artificial intelligence?"}
    ],
    extra_headers=headers
)

print(response.content[0].text)

Stream Chat

import anthropic

client = anthropic.Anthropic(
    api_key="your-anthropic-api-key",
    base_url="https://gateway.adaline.ai/v1/anthropic/"
)

headers = {
    "adaline-api-key": "your-adaline-api-key",
    "adaline-project-id": "your-project-id",
    "adaline-prompt-id": "your-prompt-id"
}

stream = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1000,
    messages=[
        {"role": "user", "content": "Explain the theory of relativity in simple terms."}
    ],
    stream=True,
    extra_headers=headers
)

for event in stream:
    if event.type == "content_block_delta":
        print(event.delta.text, end="")

Next Steps