Skip to content

Overview

DeepIntShield exposes an Anthropic-compatible route. Point a supported Anthropic SDK at it to retain native Messages API objects. Provider SDK exceptions own HTTP-error decoding, so inspect status and the structured gateway body rather than assuming upstream error text is unchanged.

You keep your Anthropic SDK-based architecture while gaining DeepIntShield features like governance, load balancing, semantic caching, and multi-provider support.

Endpoint: /anthropic

The Python shield.anthropic() builder also installs prompt-cache markers when it owns the HTTP client. See Python SDK providers and error codes.


Install with the Anthropic extra:

Terminal window
pip install "deepintshield[anthropic]"
from deepintshield import DeepintShield
shield = DeepintShield(virtual_key="sk-ds-your-virtual-key")
client = shield.anthropic() # pre-wired anthropic.Anthropic
response = client.messages.create(
model="anthropic/claude-sonnet-4-5",
max_tokens=1000,
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.content[0].text)

Use multiple providers through the same Anthropic SDK format by prefixing model names with the provider:

import anthropic
client = anthropic.Anthropic(
base_url="https://app.deepintshield.com/anthropic",
api_key="sk-ds-your-virtual-key",
default_headers={"x-deepintshield-vk": "sk-ds-your-virtual-key"},
)
# Anthropic models (default)
anthropic_response = client.messages.create(
model="claude-3-5-sonnet",
max_tokens=1000,
messages=[{"role": "user", "content": "Hello from Claude!"}]
)
# OpenAI models via Anthropic SDK format
openai_response = client.messages.create(
model="openai/gpt-4o-mini",
max_tokens=1000,
messages=[{"role": "user", "content": "Hello from OpenAI!"}]
)
# Google Vertex models via Anthropic SDK format
vertex_response = client.messages.create(
model="vertex/gemini-2.5-flash",
max_tokens=1000,
messages=[{"role": "user", "content": "Hello from Gemini!"}]
)
# Azure models
azure_response = client.messages.create(
model="azure/gpt-4o",
max_tokens=1000,
messages=[{"role": "user", "content": "Hello from Azure!"}]
)
# Local Ollama models
ollama_response = client.messages.create(
model="ollama/llama3.1:8b",
max_tokens=1000,
messages=[{"role": "user", "content": "Hello from Ollama!"}]
)

Pass custom headers required by DeepIntShield plugins (like governance, telemetry, etc.):

import anthropic
client = anthropic.Anthropic(
base_url="https://app.deepintshield.com/anthropic",
api_key="dummy-key",
default_headers={
"x-deepintshield-vk": "sk-ds-your-virtual-key", # Virtual key for governance
}
)
response = client.messages.create(
model="claude-3-5-sonnet",
max_tokens=1000,
messages=[{"role": "user", "content": "Hello with custom headers!"}]
)

Pass API keys directly in requests to bypass DeepIntShield’s load balancing. You can pass any provider’s API key (OpenAI, Anthropic, Mistral, etc.) since DeepIntShield only looks for Authorization or x-api-key headers. This requires the Allow Direct API keys option to be enabled in DeepIntShield configuration.

Learn more: See Key Management for enabling direct API key usage.

import anthropic
# Using Anthropic's API key directly
client_with_direct_key = anthropic.Anthropic(
base_url="https://app.deepintshield.com/anthropic",
api_key="sk-your-anthropic-key" # Anthropic's API key works
)
anthropic_response = client_with_direct_key.messages.create(
model="claude-3-5-sonnet",
max_tokens=1000,
messages=[{"role": "user", "content": "Hello from Claude!"}]
)
# or pass different provider keys per request using headers
client = anthropic.Anthropic(
base_url="https://app.deepintshield.com/anthropic",
api_key="dummy-key"
)
# Use Anthropic key for Claude
anthropic_response = client.messages.create(
model="claude-3-5-sonnet",
max_tokens=1000,
messages=[{"role": "user", "content": "Hello Claude!"}],
extra_headers={
"x-api-key": "sk-ant-your-anthropic-key"
}
)
# Use OpenAI key for GPT models
openai_response = client.messages.create(
model="openai/gpt-4o-mini",
max_tokens=1000,
messages=[{"role": "user", "content": "Hello GPT!"}],
extra_headers={
"Authorization": "Bearer sk-your-openai-key"
}
)

Submit inference requests asynchronously and poll for results later using the x-deepintshield-async header. This is useful for long-running requests where you don’t want to hold a connection open. See Async Inference for full details.

import anthropic
import time
client = anthropic.Anthropic(
base_url="https://app.deepintshield.com/anthropic",
api_key="sk-ds-your-virtual-key",
default_headers={"x-deepintshield-vk": "sk-ds-your-virtual-key"},
)
# Submit async request
initial = client.messages.create(
model="anthropic/claude-sonnet-4-20250514",
max_tokens=256,
messages=[{"role": "user", "content": "Tell me a short story."}],
extra_headers={"x-deepintshield-async": "true"}
)
# If content is present, the request completed synchronously
if initial.content:
print(initial.content[0].text)
else:
# Poll until completed
while True:
time.sleep(2)
poll = client.messages.create(
model="anthropic/claude-sonnet-4-20250514",
max_tokens=256,
messages=[{"role": "user", "content": "Tell me a short story."}],
extra_headers={"x-deepintshield-async-id": initial.id}
)
if poll.content:
print(poll.content[0].text)
break
HeaderDescription
x-deepintshield-async: trueSubmit the request as an async job. Returns immediately with a job ID.
x-deepintshield-async-id: <job-id>Poll for results of a previously submitted async job.
x-deepintshield-async-job-result-ttl: <seconds>Override the default result TTL (default: 3600s).

The Anthropic integration supports all features that are available in both the Anthropic SDK and DeepIntShield core functionality. If the Anthropic SDK supports a feature and DeepIntShield supports it, the integration will work seamlessly.