Skip to content

Clients

The two top-level entry points. Construct one per API key and reuse it for the lifetime of your process — both classes hold an httpx connection pool and a rate limiter that need to live across requests.

ComplianceClient

ComplianceClient

Synchronous client for the Anthropic Compliance API.

Construct a single client per API key and reuse it across calls. The client holds a connection pool and a rate limiter, both of which need to live across requests for full benefit.

Parameters:

Name Type Description Default
api_key str | None

A Compliance Access Key (sk-ant-api01-...), created in claude.ai, which reaches every endpoint. An Admin API key (sk-ant-admin01-...) also works but reaches the Activity Feed only — every other endpoint returns 403. If omitted, ANTHROPIC_COMPLIANCE_ACCESS_KEY is read from the environment, falling back to the legacy ANTHROPIC_COMPLIANCE_API_KEY.

None
base_url str

Override the API host. Defaults to the Anthropic production host. Useful for testing against a recorded fixture server.

DEFAULT_BASE_URL
timeout float

Per-request timeout in seconds. Default 30.

DEFAULT_TIMEOUT_SECONDS
max_download_bytes int

Maximum size, in bytes, that the eager download() methods will load into memory. Larger files must be fetched through download_to_file() or download_stream(). Default 100 MiB.

DEFAULT_MAX_DOWNLOAD_BYTES
max_retries int

Maximum retry attempts for 429 and 5xx responses. Default 3. Set to 0 to disable retries.

DEFAULT_MAX_RETRIES
rate_limit_rpm int

Proactive client-side requests-per-minute cap. Defaults to 600. This is best-effort and per-client: it only smooths bursts from this client instance. The live API enforces 600 RPM per parent organisation, shared across every key and every /v1/compliance/* endpoint — a budget this limiter cannot see. If you run multiple clients under the same parent, set this to 600 / n_clients to avoid collectively exceeding it, or set it to 0 to disable and rely on server-side 429 handling.

DEFAULT_RATE_LIMIT_RPM

Raises:

Type Description
ValueError

If no API key is supplied through api_key or the environment variable.

Example
from claude_compliance_sdk import ComplianceClient

with ComplianceClient(api_key="sk-ant-api01-...") as client:
    for activity in client.activities.iter(limit=10):
        print(activity.id, activity.type)

rate_limit_status property

rate_limit_status: RateLimitSnapshot | None

The server's last reported request budget, or None.

Populated from the anthropic-ratelimit-* headers after the first response. Useful for pacing your own workers: the budget is 600 requests per minute shared across every key under the parent organisation, so remaining reflects traffic the client cannot see.

page = client.activities.list(limit=1)
status = client.rate_limit_status
if status and status.remaining is not None and status.remaining < 50:
    time.sleep(5)  # Back off before the shared budget runs out.

close

close() -> None

Close the underlying HTTP connection pool.

Safe to call multiple times. After close() is invoked, the client must not be reused.

AsyncComplianceClient

AsyncComplianceClient

Asynchronous client for the Anthropic Compliance API.

Construct a single client per API key and reuse it across awaits. Designed to be used as an async context manager so the underlying httpx.AsyncClient is closed cleanly on exit.

Parameters:

Name Type Description Default
api_key str | None

A Compliance Access Key (sk-ant-api01-...), created in claude.ai, which reaches every endpoint. An Admin API key (sk-ant-admin01-...) also works but reaches the Activity Feed only — every other endpoint returns 403. If omitted, ANTHROPIC_COMPLIANCE_ACCESS_KEY is read from the environment, falling back to the legacy ANTHROPIC_COMPLIANCE_API_KEY.

None
base_url str

Override the API host. Defaults to the Anthropic production host.

DEFAULT_BASE_URL
timeout float

Per-request timeout in seconds. Default 30.

DEFAULT_TIMEOUT_SECONDS
max_download_bytes int

Maximum size, in bytes, that the eager download() coroutines will load into memory. Larger files must be fetched through download_to_file() or download_stream(). Default 100 MiB.

DEFAULT_MAX_DOWNLOAD_BYTES
max_retries int

Maximum retry attempts for 429 and 5xx responses. Default 3. Set to 0 to disable retries.

DEFAULT_MAX_RETRIES
rate_limit_rpm int

Proactive client-side requests-per-minute cap. Defaults to 600. This is best-effort and per-client: it only smooths bursts from this client instance. The live API enforces 600 RPM per parent organisation, shared across every key and every /v1/compliance/* endpoint — a budget this limiter cannot see. If you run multiple clients under the same parent, set this to 600 / n_clients to avoid collectively exceeding it, or set it to 0 to disable and rely on server-side 429 handling.

DEFAULT_RATE_LIMIT_RPM

Raises:

Type Description
ValueError

If no API key is supplied through api_key or the environment variable.

Example
import asyncio

from claude_compliance_sdk import AsyncComplianceClient


async def main() -> None:
    async with AsyncComplianceClient(api_key="sk-ant-api01-...") as client:
        async for activity in client.activities.iter(limit=10):
            print(activity.id, activity.type)


asyncio.run(main())

rate_limit_status property

rate_limit_status: RateLimitSnapshot | None

The server's last reported request budget, or None.

Populated from the anthropic-ratelimit-* headers after the first response. Useful for pacing your own workers: the budget is 600 requests per minute shared across every key under the parent organisation, so remaining reflects traffic the client cannot see.

page = client.activities.list(limit=1)
status = client.rate_limit_status
if status and status.remaining is not None and status.remaining < 50:
    time.sleep(5)  # Back off before the shared budget runs out.

aclose async

aclose() -> None

Close the underlying async HTTP connection pool.

Safe to await multiple times. After aclose() is awaited, the client must not be reused.