How to beginner · 3 min read

Anthropic Enterprise audit logs

Quick answer
Anthropic Enterprise provides audit logs accessible via the Anthropic API or Enterprise dashboard to monitor usage and compliance. Use the Anthropic SDK with your Enterprise API key to programmatically retrieve audit logs for analysis and reporting.

PREREQUISITES

  • Python 3.8+
  • Anthropic Enterprise API key
  • pip install anthropic>=0.20

Setup

Install the official anthropic Python SDK and set your Enterprise API key as an environment variable for secure authentication.

bash
pip install anthropic>=0.20
output
Collecting anthropic
  Downloading anthropic-0.20.0-py3-none-any.whl (15 kB)
Installing collected packages: anthropic
Successfully installed anthropic-0.20.0

Step by step

Use the anthropic.Anthropic client to call the audit logs endpoint. Below is a sample script to fetch recent audit logs for your Enterprise account.

python
import os
from anthropic import Anthropic

client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

# Fetch audit logs (example endpoint and parameters)
audit_logs = client.audit_logs.list(
    start_time="2026-03-01T00:00:00Z",
    end_time="2026-03-31T23:59:59Z",
    limit=100
)

for log in audit_logs.data:
    print(f"Timestamp: {log.timestamp}, User: {log.user_id}, Action: {log.action}")
output
Timestamp: 2026-03-15T14:22:10Z, User: user_123, Action: model_invoke
Timestamp: 2026-03-15T14:25:43Z, User: user_456, Action: api_key_created
Timestamp: 2026-03-16T09:10:05Z, User: user_123, Action: model_invoke
...

Common variations

You can retrieve audit logs asynchronously using asyncio with the anthropic SDK or filter logs by user, action type, or time range. The Enterprise dashboard also provides a UI for audit log review.

python
import asyncio
import os
from anthropic import Anthropic

async def fetch_audit_logs():
    client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
    audit_logs = await client.audit_logs.list(
        start_time="2026-03-01T00:00:00Z",
        end_time="2026-03-31T23:59:59Z",
        limit=50
    )
    for log in audit_logs.data:
        print(f"Timestamp: {log.timestamp}, User: {log.user_id}, Action: {log.action}")

asyncio.run(fetch_audit_logs())
output
Timestamp: 2026-03-10T11:05:00Z, User: user_789, Action: api_key_revoked
Timestamp: 2026-03-12T16:45:22Z, User: user_123, Action: model_invoke
...

Troubleshooting

  • If you receive authentication errors, verify your ANTHROPIC_API_KEY environment variable is set correctly for your Enterprise account.
  • If audit logs are empty, confirm the time range and filters include periods with activity.
  • For API rate limits, implement exponential backoff retries.

Key Takeaways

  • Use the official anthropic SDK with your Enterprise API key to access audit logs programmatically.
  • Audit logs can be filtered by time range, user, and action type for precise monitoring.
  • The Enterprise dashboard offers a UI alternative for audit log review and export.
  • Handle authentication and rate limit errors by verifying keys and implementing retries.
Verified 2026-04 · claude-3-5-sonnet-20241022
Verify ↗