@openpets/anthropic
v1.0.4
Published
OpenPets plugin for the Anthropic API. Create messages, manage batches, count tokens, and manage your organization with Admin API. Includes organization management, workspace control, usage/cost reports, and more.
Downloads
66
Maintainers
Readme
Anthropic Pet
OpenPets plugin for the Anthropic API. Interact with Claude AI models AND manage your organization programmatically.
Features
Claude AI Features (requires ANTHROPIC_API_KEY)
- Messages API - Send messages to Claude and receive responses
- Token Counting - Count tokens in messages before sending
- Message Batches - Create and manage batches for async processing
- Beta Features - Access beta endpoints for prompt caching and more
Admin Features (requires ANTHROPIC_ADMIN_API_KEY)
- Organization Management - View org details, manage members, send invites
- Workspace Management - Create, update, archive workspaces
- Workspace Members - Manage team access per workspace
- API Key Management - List, monitor, and update API keys
- Usage & Cost Reports - Detailed analytics on token usage and costs
- Claude Code Analytics - Track Claude Code usage
Quick Start
1. Get API Keys
For Claude AI (Required):
- Sign up at Anthropic Console
- Create an API key at API Keys Settings
For Admin Features (Optional):
- Only organization admins can create Admin API keys
- Create at Admin API Keys
- Admin keys start with
sk-ant-admin...
2. Configure Environment
Copy the example environment file and add your keys:
cp .env.example .env
# Edit .env and add your keysOr set directly:
export ANTHROPIC_API_KEY=sk-ant-api03-xxxxx
export ANTHROPIC_ADMIN_API_KEY=sk-ant-admin-xxxxx # Optional3. Test Connections
Test Claude API:
opencode run "test anthropic connection"Test Admin API (if configured):
opencode run "test admin connection"4. Use Claude AI
opencode run "ask Claude what is the capital of France"5. Use Admin Features (Optional)
opencode run "list all organization members"
opencode run "get usage report for last 7 days"
opencode run "list all workspaces"Available Tools
Claude AI Tools (15 tools)
| Tool | Description |
|------|-------------|
| anthropic-test-connection | Test API connection and verify credentials |
| anthropic-messages-post | Send a message to Claude and get a response |
| anthropic-beta-messages-count-tokens-post | Count tokens in a message without sending |
| anthropic-beta-message-batches-list | List all message batches |
| anthropic-beta-message-batches-post | Create a new message batch |
| anthropic-beta-message-batches-retrieve | Get status of a specific batch |
| anthropic-beta-message-batches-cancel | Cancel a running batch |
| anthropic-beta-message-batches-results | Get results from a completed batch |
Admin API Tools (28 tools - requires ANTHROPIC_ADMIN_API_KEY)
Organization Management:
anthropic-admin-test-connection- Test admin API connectionanthropic-admin-get-organization- Get organization detailsanthropic-admin-list-users- List organization membersanthropic-admin-get-user- Get specific user detailsanthropic-admin-update-user-role- Update member roleanthropic-admin-remove-user- Remove organization member
Invitations:
anthropic-admin-list-invites- List pending invitesanthropic-admin-create-invite- Send new invitationanthropic-admin-get-invite- Get invite detailsanthropic-admin-delete-invite- Cancel invitation
Workspaces:
anthropic-admin-list-workspaces- List all workspacesanthropic-admin-create-workspace- Create new workspaceanthropic-admin-get-workspace- Get workspace detailsanthropic-admin-update-workspace- Update workspace nameanthropic-admin-archive-workspace- Archive workspace
Workspace Members:
anthropic-admin-list-workspace-members- List workspace membersanthropic-admin-add-workspace-member- Add member to workspaceanthropic-admin-get-workspace-member- Get workspace member detailsanthropic-admin-update-workspace-member-role- Update workspace member roleanthropic-admin-remove-workspace-member- Remove workspace member
API Keys:
anthropic-admin-list-api-keys- List all API keysanthropic-admin-get-api-key- Get API key details and usageanthropic-admin-update-api-key- Update key name or status
Usage & Cost Analytics:
anthropic-admin-usage-report- Get detailed token usage reportanthropic-admin-cost-report- Get cost breakdown in USDanthropic-admin-claude-code-usage- Get Claude Code analytics
Environment Variables
| Variable | Required | Description |
|----------|----------|-------------|
| ANTHROPIC_API_KEY | Yes | Your Anthropic API key for Claude AI |
| ANTHROPIC_ADMIN_API_KEY | No | Admin API key for organization management (starts with sk-ant-admin...) |
| ANTHROPIC_VERSION | No | API version header (defaults to 2023-06-01) |
| ANTHROPIC_HOST | No | Override API base URL (defaults to https://api.anthropic.com) |
Usage Examples
Claude AI Examples
Simple Message:
opencode run "send a message to Claude asking for a haiku about programming"Count Tokens:
opencode run "count how many tokens are in 'Hello, how are you today?'"List Batches:
opencode run "list all my message batches"Admin API Examples
Organization Management:
opencode run "list all organization members"
opencode run "invite [email protected] as a developer"
opencode run "update user role to admin"Workspace Management:
opencode run "create a workspace called Production"
opencode run "list all workspaces"
opencode run "add user to workspace as developer"Usage & Cost Analytics:
opencode run "get usage report for last 7 days"
opencode run "show cost breakdown for January 2025"
opencode run "get Claude Code usage statistics"API Key Management:
opencode run "list all API keys"
opencode run "show active API keys only"
opencode run "get usage statistics for a specific API key"Message Format
When using the Messages API directly, format messages as a JSON array:
[
{"role": "user", "content": "Hello, Claude!"},
{"role": "assistant", "content": "Hello! How can I help you today?"},
{"role": "user", "content": "Tell me about AI."}
]Available Models
| Model | ID | Best For |
|-------|-----|----------|
| Claude 3.5 Sonnet | claude-3-5-sonnet-20241022 | Most capable, best for complex tasks |
| Claude 3 Opus | claude-3-opus-20240229 | Highly capable, thorough responses |
| Claude 3 Haiku | claude-3-haiku-20240307 | Fast, cost-effective for simple tasks |
Regenerating Tools
This pet uses auto-generated OpenAPI tools. To regenerate:
cd pets/anthropic
pets generate-openapi --verboseAdmin API Features in Detail
Usage Reports
Track token consumption across your organization with detailed breakdowns:
- Group by: model, workspace, API key, service tier
- Filter by: models, service tiers, context windows, workspaces, API keys
- Metrics: Uncached input, cached input, cache creation, output tokens
- Time ranges: Custom start/end times with 1m, 1h, or 1d aggregation
Cost Reports
Get service-level cost breakdowns in USD:
- All costs reported in cents (decimal strings)
- Token usage costs by model
- Web search costs
- Code execution costs
- Group by workspace or description
- Custom time ranges
Workspace Organization
Organize your API resources into logical groups:
- Create separate workspaces for dev/staging/production
- Set custom spend limits per workspace
- Control team access with workspace-specific roles
- Track usage and costs per workspace
Security & Governance
Manage your organization's security posture:
- Audit all API keys and their usage
- Monitor who has access to your organization
- Track invitation status
- Update or revoke access as needed
FAQ
Q: How do I get an Anthropic API key? A: Sign up at https://console.anthropic.com and create an API key in the API Keys section.
Q: How do I get an Admin API key?
A: Only organization admins can create Admin API keys at https://console.anthropic.com/settings/admin-keys. These keys start with sk-ant-admin... and enable organization management.
Q: What's the difference between regular and admin API keys? A: Regular API keys are for using Claude AI. Admin API keys are for managing your organization, workspaces, members, and accessing usage/cost reports.
Q: Can I use this plugin without an admin key? A: Yes! The admin key is optional. Without it, you get all Claude AI features (messages, batches, token counting). With it, you also get organization management and analytics.
Q: What is max_tokens? A: The maximum number of tokens Claude can generate in its response. Different models have different limits.
Q: What are message batches? A: Message Batches allow you to process multiple messages asynchronously. Create a batch, poll for completion, then retrieve results.
Q: What can I do with usage and cost reports? A: Track spending, optimize model usage, implement chargeback by team/workspace, monitor cache effectiveness, and identify cost optimization opportunities.
