Quickstart: Anthropic
Anonymize Anthropic requests in under 10 lines
Prerequisites
rdakt-aiandanthropicinstalledANTHROPIC_API_KEYenvironment variable set
Async Usage
import httpx
from anthropic import AsyncAnthropic
from rdakt_ai import RdaktMiddleware
client = AsyncAnthropic(
http_client=httpx.AsyncClient(
transport=RdaktMiddleware(inner=httpx.AsyncHTTPTransport()),
),
)
response = await client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[
{"role": "user", "content": "Summarize the case for John Smith (SSN 123-45-6789)"}
],
)
print(response.content[0].text)Streaming
async with client.messages.stream(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[
{"role": "user", "content": "Write a report about Jane Doe, email jane@acme.com"}
],
) as stream:
async for text in stream.text_stream:
print(text, end="", flush=True)Anthropic-Specific Notes
Anthropic's API compresses streaming responses with gzip. Rdakt AI handles this transparently — it decompresses the stream, deanonymizes tokens, and re-streams the result. No configuration needed.
What Just Happened?
- Detection — PII detected in the outbound message
- Anonymization — Real values replaced with tokens before reaching Anthropic
- Deanonymization — Gzip-compressed SSE stream decompressed and deanonymized in real-time