Mastering Claude API Company Endpoints: A Practical Guide to Organizational AI Management
Learn how to use Claude API Company endpoints to manage organizational AI usage, monitor costs, and control access across teams with practical code examples.
This guide teaches you how to leverage Claude API Company endpoints for managing organizational AI usage, including creating API keys, monitoring team consumption, setting usage limits, and auditing activity logs.
Introduction
As organizations scale their use of Claude AI across multiple teams and projects, managing API access, monitoring costs, and ensuring security become critical challenges. Anthropic's Company endpoints provide a powerful administrative layer that allows organizations to control how Claude is used at scale. This guide walks through everything you need to know to set up, manage, and optimize your organizational Claude deployment.
What Are Company Endpoints?
Company endpoints are administrative API routes that allow organizations to:
- Create and manage multiple API keys for different teams or projects
- Monitor usage and costs across the entire organization
- Set granular permissions and usage limits
- Audit API activity for compliance and security
- Automate user provisioning and deprovisioning
Prerequisites
Before diving into Company endpoints, ensure you have:
- An Anthropic Enterprise account with administrative privileges
- An organization-level API key (not a user-level key)
- Python 3.8+ or Node.js 16+ installed
- The
anthropicPython SDK or@anthropic-ai/sdkfor TypeScript
Setting Up Your Environment
Python Setup
import anthropic
import os
Initialize with your organization-level API key
client = anthropic.Anthropic(
api_key=os.environ.get("ANTHROPIC_ORG_API_KEY")
)
TypeScript Setup
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_ORG_API_KEY,
});
Managing API Keys at Scale
One of the most powerful features of Company endpoints is the ability to create and manage multiple API keys with different permissions.
Creating Team-Specific API Keys
# Create a new API key for the engineering team
new_key = client.admin.api_keys.create(
name="Engineering Team Key",
permissions=["messages:write", "messages:read"],
max_tokens_per_month=10000000 # 10M tokens/month limit
)
print(f"Created key: {new_key.id}")
print(f"Key value: {new_key.key}") # Store securely!
Listing and Revoking Keys
# List all active API keys
keys = client.admin.api_keys.list()
for key in keys:
print(f"{key.id}: {key.name} (Created: {key.created_at})")
Revoke a compromised key
client.admin.api_keys.revoke(
key_id="key_abc123"
)
Monitoring Usage and Costs
Understanding how your organization consumes Claude API resources is essential for budgeting and optimization.
Retrieving Organization Usage
# Get usage summary for the current month
usage = client.admin.usage.retrieve(
start_date="2024-01-01",
end_date="2024-01-31"
)
print(f"Total input tokens: {usage.total_input_tokens}")
print(f"Total output tokens: {usage.total_output_tokens}")
print(f"Estimated cost: ${usage.estimated_cost:.2f}")
Per-Key Usage Breakdown
# Get usage broken down by API key
key_usage = client.admin.usage.by_key(
start_date="2024-01-01",
end_date="2024-01-31"
)
for entry in key_usage:
print(f"Key {entry.key_name}: {entry.total_tokens} tokens used")
Setting Usage Limits and Alerts
Prevent unexpected costs by implementing usage limits and alerts.
Creating a Usage Alert
# Set an alert when a key reaches 80% of its monthly limit
alert = client.admin.alerts.create(
name="Engineering Team 80% Alert",
key_id="key_abc123",
threshold_percent=80,
notification_email="[email protected]"
)
print(f"Alert created: {alert.id}")
Implementing Hard Limits
# Update a key with a hard monthly limit
client.admin.api_keys.update(
key_id="key_abc123",
max_tokens_per_month=50000000, # 50M tokens hard limit
hard_limit=True # API calls will fail when limit is reached
)
Auditing and Compliance
For organizations with compliance requirements, audit logs are essential.
Retrieving Audit Logs
# Get audit logs for the last 7 days
audit_logs = client.admin.audit_logs.list(
start_date="2024-01-24",
end_date="2024-01-31",
event_types=["key_created", "key_revoked", "permission_changed"]
)
for log in audit_logs:
print(f"{log.timestamp}: {log.event_type} by {log.user_email}")
print(f" Details: {log.description}")
Best Practices for Organizational Claude Management
1. Implement Least Privilege Access
Create separate API keys for each team or project with only the permissions they need. Never share a single key across multiple teams.
# Example: Creating keys with minimal permissions
research_key = client.admin.api_keys.create(
name="Research Team",
permissions=["messages:read"], # Read-only access
max_tokens_per_month=5000000
)
production_key = client.admin.api_keys.create(
name="Production App",
permissions=["messages:write", "messages:read"],
max_tokens_per_month=100000000
)
2. Automate Key Rotation
Set up a cron job or scheduled task to rotate API keys regularly.
import schedule
import time
def rotate_keys():
# Get all keys older than 90 days
old_keys = client.admin.api_keys.list(created_before="2023-10-31")
for old_key in old_keys:
# Create new key with same permissions
new_key = client.admin.api_keys.create(
name=f"{old_key.name} (Rotated)",
permissions=old_key.permissions,
max_tokens_per_month=old_key.max_tokens_per_month
)
# Revoke old key
client.admin.api_keys.revoke(key_id=old_key.id)
# Notify team
print(f"Rotated key {old_key.id} -> {new_key.id}")
Run rotation every Sunday at 2 AM
schedule.every().sunday.at("02:00").do(rotate_keys)
while True:
schedule.run_pending()
time.sleep(60)
3. Monitor for Anomalies
Set up automated monitoring to detect unusual usage patterns.
# Check for sudden spikes in usage
def check_anomalies():
yesterday = client.admin.usage.retrieve(
start_date="yesterday",
end_date="today"
)
last_week = client.admin.usage.retrieve(
start_date="7_days_ago",
end_date="6_days_ago"
)
if yesterday.total_tokens > last_week.total_tokens * 3:
print("ALERT: Usage spike detected!")
# Trigger notification
4. Use Descriptive Key Names
Always use meaningful names for API keys to make auditing easier.
# Good naming convention
keys = [
("prod-frontend-app", "Production frontend application"),
("staging-backend-api", "Staging environment backend"),
("data-science-team", "Data science research queries"),
("customer-support-bot", "Customer support automation")
]
for name, description in keys:
client.admin.api_keys.create(
name=name,
description=description,
permissions=["messages:write", "messages:read"]
)
Troubleshooting Common Issues
Issue: API Key Not Working
Solution: Verify the key is not revoked and has the correct permissions.try:
# Test key validity
client.messages.create(
model="claude-3-opus-20240229",
max_tokens=100,
messages=[{"role": "user", "content": "Hello"}]
)
except anthropic.PermissionDeniedError as e:
print(f"Permission error: {e}")
# Check key permissions in admin panel
except anthropic.AuthenticationError as e:
print(f"Auth error: Key may be revoked or invalid")
Issue: Usage Limits Not Working
Solution: Ensurehard_limit=True is set when creating the key limit.
# Correct way to set hard limit
client.admin.api_keys.update(
key_id="key_abc123",
max_tokens_per_month=10000000,
hard_limit=True # This must be explicitly set
)
Conclusion
Company endpoints give organizations the tools they need to manage Claude AI at scale. By implementing proper key management, usage monitoring, and automated controls, you can ensure your team gets the most out of Claude while maintaining security and cost control.
Key Takeaways
- Use separate API keys for each team or project to enable granular monitoring and access control
- Implement hard limits on API keys to prevent unexpected cost overruns
- Automate key rotation and usage monitoring to maintain security and catch anomalies early
- Leverage audit logs for compliance and security investigations
- Always use descriptive naming for API keys to simplify management and auditing