Anthropic¶
Use the Anthropic Python SDK to call Claude models through Adastra LLMGW. LLMGW routes requests to Claude models hosted on AWS Bedrock or Azure, depending on the configured model group. This approach provides the native Anthropic Messages API experience — no cloud provider credentials or SDK setup required on the client side.
Installation¶
Install the Anthropic Python package:
Basic Setup¶
Configure your Anthropic client to point at LLMGW:
from anthropic import Anthropic
client = Anthropic(
base_url="https://<llmgw-deployment-url>/anthropic",
api_key="<YOUR_LLMGW_API_KEY>",
default_headers={
"llmgw-project": "your-project",
"llmgw-user": "your-user"
}
)
base_urlpoints to the LLMGW Anthropic endpoint. The SDK appends/v1/messagesautomatically.api_keyis your LLMGW API key — no cloud provider credentials are needed. LLMGW authenticates with the underlying provider (AWS Bedrock or Azure) on your behalf.default_headersassociates project and user metadata with each request. Check with your administrator if these are required.
Creating a Message¶
Generate a response using Claude:
message = client.messages.create(
model="anthropic.claude-sonnet-4-5-20250929-v1:0",
max_tokens=1024,
messages=[
{
"role": "user",
"content": "What is the weather like?"
}
]
)
print(message.content[0].text)
The model parameter refers to the model group configured in LLMGW. To find available models, see the configuration page and look for deployment_name.
Streaming¶
Get responses in real-time as they are generated:
with client.messages.stream(
model="anthropic.claude-sonnet-4-5-20250929-v1:0",
max_tokens=1024,
messages=[{"role": "user", "content": "Tell me a story"}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
LLMGW handles streaming transparently regardless of the underlying provider — for AWS Bedrock models it converts the EventStream format into standard Anthropic SSE events, and for Azure models it passes through native Anthropic SSE events directly. Streaming works exactly as it would with the Anthropic API.
Accessing Response Metadata¶
Track costs, request IDs, and which model was used:
import json
response = client.messages.with_raw_response.create(
model="anthropic.claude-sonnet-4-5-20250929-v1:0",
max_tokens=1024,
messages=[{"role": "user", "content": "What is the weather like?"}]
)
# Extract LLMGW headers
llmgw_headers = {
key: value
for key, value in response.headers.items()
if key.startswith('x-llmgw')
}
print(json.dumps(llmgw_headers, indent=2))
# Parse the message as usual
message = response.parse()
print(message.content[0].text)
For full details on available headers, see Response Headers.