Skip to content

Anthropic SDK

ai& exposes Anthropic-compatible endpoints alongside its OpenAI surface. Use the official anthropic SDKs by overriding the base URL.

Terminal window
pip install anthropic
from anthropic import Anthropic
client = Anthropic(
base_url="https://api.aiand.com",
api_key="sk-your-aiand-api-key",
)
response = client.messages.create(
model="...",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(response.content[0].text)
with client.messages.stream(
model="...",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
) as stream:
for text in stream.text_stream:
print(text, end="")

The Anthropic Files API works too — selected by the SDK’s anthropic-version header:

file = client.beta.files.upload(file=open("cat.png", "rb"))

See OpenAI vs Anthropic shape for how the dual-emit works.