How to Manage Your Anthropic Account and API Keys: A Practical Guide for Claude Users
Learn how to navigate the Anthropic Console, create and manage API keys, set up billing, and configure organizations for Claude API access. Step-by-step guide with code examples.
This guide walks you through setting up your Anthropic account, generating API keys, managing billing, and organizing projects in the Console so you can start using the Claude API effectively.
Introduction
Getting started with the Claude API requires more than just understanding how to send prompts. You need to set up your Anthropic account, generate API keys, configure billing, and manage your organization. This guide covers everything you need to know about the "Company" side of using Claude—your account settings, API key management, and billing configuration.
Whether you're an individual developer or part of a team, understanding these fundamentals will save you time and prevent common pitfalls.
Creating Your Anthropic Account
Before you can use the Claude API, you need an Anthropic account. Visit console.anthropic.com and sign up with your email address or a Google/GitHub account.
Account Verification
After signing up, you'll receive a verification email. Click the link to verify your account. If you don't see the email, check your spam folder.
Two-Factor Authentication (2FA)
For security, Anthropic strongly recommends enabling two-factor authentication. Go to Account Settings > Security and enable 2FA using an authenticator app like Google Authenticator or Authy.
Navigating the Anthropic Console
The Anthropic Console is your central hub for managing everything related to Claude. Here's a quick tour of the main sections:
- Dashboard: Overview of your API usage, recent activity, and quick stats.
- API Keys: Generate, view, and revoke API keys.
- Billing: Manage your payment methods, view invoices, and set spending limits.
- Organization: Manage team members, roles, and settings.
- Logs: View detailed API request logs for debugging.
Generating and Managing API Keys
API keys are how your applications authenticate with the Claude API. Here's how to create and manage them.
Creating a New API Key
- Log in to the Anthropic Console.
- Navigate to API Keys in the left sidebar.
- Click the Create Key button.
- Give your key a descriptive name (e.g., "Production App", "Development Testing").
- Choose the key type:
- Click Create.
Best Practices for API Key Security
- Never hardcode keys in your source code. Use environment variables instead.
- Rotate keys regularly (every 90 days is a good practice).
- Use separate keys for development, staging, and production.
- Revoke compromised keys immediately.
Using API Keys in Code
Here's how to use your API key with the Claude API in Python:
import anthropic
import os
Load from environment variable (recommended)
client = anthropic.Anthropic(
api_key=os.environ.get("ANTHROPIC_API_KEY")
)
Or pass directly (not recommended for production)
client = anthropic.Anthropic(api_key="sk-ant-...")
message = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Claude!"}
]
)
print(message.content)
For TypeScript/Node.js:
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
async function main() {
const message = await client.messages.create({
model: 'claude-3-5-sonnet-20241022',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude!' }],
});
console.log(message.content);
}
main();
Setting Environment Variables
macOS/Linux:export ANTHROPIC_API_KEY="sk-ant-..."
Windows (Command Prompt):
set ANTHROPIC_API_KEY=sk-ant-...
Windows (PowerShell):
$env:ANTHROPIC_API_KEY="sk-ant-..."
For persistent storage, add the export to your shell profile (.bashrc, .zshrc, etc.) or use a .env file with a library like python-dotenv.
Managing Billing and Usage
Understanding your billing setup is crucial to avoid unexpected charges or service interruptions.
Adding a Payment Method
- Go to Billing in the Console.
- Click Add Payment Method.
- Enter your credit card details. Anthropic accepts Visa, Mastercard, and American Express.
- Set a spending limit to control costs.
Understanding Pricing
Claude API pricing is based on tokens processed. As of this writing:
- Claude 3.5 Sonnet: $3.00 per million input tokens, $15.00 per million output tokens
- Claude 3 Haiku: $0.25 per million input tokens, $1.25 per million output tokens
- Claude 3 Opus: $15.00 per million input tokens, $75.00 per million output tokens
Setting Spending Limits
To prevent runaway costs:
- In the Billing section, click Spending Limits.
- Set a soft limit (you'll get an email alert when reached) and a hard limit (API calls will be blocked).
- Configure alerts for different thresholds (e.g., 50%, 80%, 100% of your budget).
Viewing Usage Logs
The Logs section shows detailed information about each API call:
- Timestamp
- Model used
- Tokens consumed (input and output)
- Response status
- Cost
Managing Your Organization
If you're working with a team, you can create an organization to share API keys and manage access.
Creating an Organization
- Click your profile icon in the top-right corner.
- Select Create Organization.
- Give it a name and add team members by email.
Roles and Permissions
Anthropic supports three roles:
- Owner: Full control, including billing and member management.
- Admin: Can manage API keys and view logs, but cannot change billing.
- Member: Can use API keys and view their own usage.
Inviting Team Members
- Go to Organization > Members.
- Click Invite Member.
- Enter the email address and select a role.
- The invitee will receive an email with a link to join.
Troubleshooting Common Issues
"Invalid API Key" Error
- Ensure you're using the correct key (check for typos).
- Verify the key hasn't been revoked.
- Check that the key has the necessary permissions.
Rate Limiting
If you receive a 429 status code, you've hit a rate limit. Solutions:
- Implement exponential backoff in your code.
- Request a rate limit increase from Anthropic support.
- Distribute requests across multiple keys.
Billing Issues
- Payment declined: Update your payment method in the Billing section.
- Unexpected charges: Review your usage logs to identify the source.
- Need an invoice: Download invoices from the Billing section.
Code Example: Checking Your Account Balance
Here's a simple Python script to check your remaining credits (if you're on a prepaid plan):
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.environ.get("ANTHROPIC_API_KEY")
)
The API doesn't have a direct balance endpoint, but you can check usage
try:
# Make a minimal API call to verify key works
response = client.messages.create(
model="claude-3-haiku-20240307",
max_tokens=10,
messages=[{"role": "user", "content": "ping"}]
)
print("API key is valid and working.")
print(f"Response: {response.content[0].text}")
except anthropic.AuthenticationError:
print("Invalid API key. Please check your key.")
except anthropic.RateLimitError:
print("Rate limit exceeded. Try again later.")
except Exception as e:
print(f"An error occurred: {e}")
Key Takeaways
- Secure your API keys: Use environment variables, rotate keys regularly, and never commit them to version control.
- Set spending limits: Protect yourself from unexpected costs by configuring both soft and hard limits in the Billing section.
- Use separate keys for different environments: Development, staging, and production should each have their own key for better security and monitoring.
- Leverage organization features: If working with a team, create an organization to manage permissions and share resources efficiently.
- Monitor usage regularly: Check the Logs section to track token consumption, debug issues, and optimize your API calls for cost efficiency.