How to Use the Company Endpoint in the Claude API: A Practical Guide
Learn how to leverage the Company endpoint in the Claude API to manage organizational settings, control access, and streamline team workflows with practical code examples.
This guide explains the Company endpoint in the Claude API, showing you how to configure organizational settings, manage user access, and integrate team-level controls into your applications using Python and TypeScript examples.
How to Use the Company Endpoint in the Claude API: A Practical Guide
When building applications with the Claude API, managing organizational settings and team access is crucial for scaling your AI-powered solutions. The Company endpoint in the Claude API provides a powerful interface for configuring company-wide settings, controlling user permissions, and streamlining workflows across your team.
In this guide, you'll learn what the Company endpoint is, how to authenticate and make requests, and practical ways to integrate it into your applications. Whether you're a developer setting up a new team or an administrator managing existing users, this article covers everything you need to get started.
What Is the Company Endpoint?
The Company endpoint allows you to programmatically manage your organization's settings within the Claude ecosystem. This includes:
- Retrieving company information and configuration
- Managing user access and roles
- Updating organizational preferences
- Monitoring usage and billing details
Prerequisites
Before you start using the Company endpoint, ensure you have:
- An Anthropic API key with administrative privileges
- Access to the Claude API documentation for reference
- Basic familiarity with REST APIs and JSON
- A development environment with Python 3.7+ or Node.js 14+
Authentication
All requests to the Company endpoint require authentication via your API key. Include the key in the x-api-key header:
curl https://api.anthropic.com/v1/company \
-H "x-api-key: YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01"
Important: The API key must belong to an admin user within the company. Standard user keys will return a 403 Forbidden error.
Making Your First Request
Let's start by retrieving basic company information. This is the simplest way to verify your setup.
Python Example
import requests
API_KEY = "your-api-key-here"
BASE_URL = "https://api.anthropic.com/v1"
headers = {
"x-api-key": API_KEY,
"anthropic-version": "2023-06-01",
"Content-Type": "application/json"
}
def get_company_info():
response = requests.get(f"{BASE_URL}/company", headers=headers)
if response.status_code == 200:
return response.json()
else:
print(f"Error: {response.status_code} - {response.text}")
return None
company = get_company_info()
if company:
print(f"Company Name: {company['name']}")
print(f"Company ID: {company['id']}")
print(f"Plan: {company['plan']}")
TypeScript Example
const API_KEY = "your-api-key-here";
const BASE_URL = "https://api.anthropic.com/v1";
async function getCompanyInfo() {
const response = await fetch(${BASE_URL}/company, {
method: "GET",
headers: {
"x-api-key": API_KEY,
"anthropic-version": "2023-06-01",
"Content-Type": "application/json"
}
});
if (!response.ok) {
throw new Error(Error: ${response.status} - ${await response.text()});
}
const data = await response.json();
console.log(Company Name: ${data.name});
console.log(Company ID: ${data.id});
console.log(Plan: ${data.plan});
return data;
}
getCompanyInfo().catch(console.error);
Managing Users
One of the most powerful features of the Company endpoint is user management. You can list, invite, and remove users programmatically.
Listing All Users
def list_users():
response = requests.get(f"{BASE_URL}/company/users", headers=headers)
if response.status_code == 200:
users = response.json()['data']
for user in users:
print(f"{user['email']} - Role: {user['role']} - Status: {user['status']}")
return users
else:
print(f"Error: {response.status_code}")
return []
list_users()
Inviting a New User
def invite_user(email: str, role: str = "member"):
payload = {
"email": email,
"role": role # "admin" or "member"
}
response = requests.post(f"{BASE_URL}/company/users", headers=headers, json=payload)
if response.status_code == 201:
print(f"Invitation sent to {email}")
return response.json()
else:
print(f"Failed to invite user: {response.text}")
return None
invite_user("[email protected]", "member")
Updating Company Settings
You can also update company-wide settings, such as default rate limits or allowed IP ranges.
def update_company_settings(settings: dict):
response = requests.patch(f"{BASE_URL}/company", headers=headers, json=settings)
if response.status_code == 200:
print("Settings updated successfully")
return response.json()
else:
print(f"Update failed: {response.text}")
return None
Example: Set default rate limit
update_company_settings({
"default_rate_limit": 1000, # requests per minute
"allowed_ip_ranges": ["192.168.1.0/24", "10.0.0.0/8"]
})
Error Handling Best Practices
When working with the Company endpoint, you may encounter these common errors:
| Status Code | Meaning | Solution |
|---|---|---|
| 401 | Unauthorized | Check your API key |
| 403 | Forbidden | Ensure your key has admin privileges |
| 404 | Not Found | Verify the endpoint URL |
| 429 | Rate Limited | Implement exponential backoff |
| 500 | Server Error | Retry after a short delay |
import time
def safe_api_call(func, max_retries=3):
for attempt in range(max_retries):
try:
result = func()
return result
except requests.exceptions.HTTPError as e:
if e.response.status_code == 429:
wait_time = 2 ** attempt
print(f"Rate limited. Waiting {wait_time} seconds...")
time.sleep(wait_time)
else:
raise
raise Exception("Max retries exceeded")
Real-World Use Cases
1. Automated Onboarding
When a new developer joins your team, you can automatically invite them to your Claude API company account via a webhook from your HR system.
2. Usage Monitoring Dashboard
Build a custom dashboard that displays real-time usage metrics across your organization, helping you track costs and identify unusual activity.
3. Role-Based Access Control
Programmatically assign admin or member roles based on an employee's department or seniority, ensuring security best practices.
Limitations and Considerations
- Rate Limits: The Company endpoint has its own rate limits separate from the Messages API. Check the
anthropic-ratelimit-*headers in responses. - Data Freshness: Changes made via the API may take a few seconds to propagate across all services.
- Audit Logging: Anthropic automatically logs all Company endpoint changes. You can retrieve audit logs via the API for compliance purposes.
Conclusion
The Company endpoint is a powerful tool for teams that want to manage their Claude API usage at scale. By automating user management, settings configuration, and monitoring, you can reduce administrative overhead and focus on building great AI-powered applications.
Start by retrieving your company info, then experiment with user management and settings updates. As you become more comfortable, explore advanced features like audit logs and custom rate limits.
Key Takeaways
- The Company endpoint allows programmatic management of organizational settings, users, and billing within the Claude API ecosystem.
- Authentication requires an admin-level API key passed via the
x-api-keyheader. - You can list, invite, and remove users, as well as update company-wide settings like rate limits and IP ranges.
- Implement robust error handling with retry logic to manage rate limits and transient errors.
- Real-world use cases include automated onboarding, usage dashboards, and role-based access control.