Anthropic
Anthropic’s Claude models are known for thoughtful, nuanced responses and strong reasoning capabilities.
-
Get an API Key
Visit console.anthropic.com/settings/keys to create an API key.
-
Set Environment Variable
Terminal window export ANTHROPIC_API_KEY=sk-ant-...Or add to your
.envfile:ANTHROPIC_API_KEY=sk-ant-... -
Configure Codemetry
config/codemetry.php 'ai' => ['enabled' => true,'engine' => 'anthropic','model' => null, // Uses claude-sonnet-5-5 by default], -
Run Analysis
Terminal window php artisan codemetry:analyze --days=7 --ai=1 --ai-engine=anthropic
Available Models
Section titled “Available Models”| Model | Default | Cost | Quality | Speed |
|---|---|---|---|---|
claude-sonnet-5-5 |
✓ | Medium | Excellent | Medium |
claude-haiku-5-5 |
Low | Good | Fast | |
claude-opus-5-5 |
High | Best | Slower |
Anthropic retires models regularly. If a model on this page stops working, check the provider’s model list and set a current one.
Choosing a Model
Section titled “Choosing a Model”For routine analysis: Use claude-sonnet-5-5 (default)
- Strong reasoning about metric patterns at a moderate price
Alternative: Use claude-haiku-5-5
- Fastest and cheapest; enough for routine daily or weekly runs
For critical analyses: Use claude-opus-5-5
- Anthropic’s most capable model; use it for occasional deep investigations
There is no --ai-model flag. To override the model for a single run, set CODEMETRY_AI_MODEL:
CODEMETRY_AI_MODEL=claude-haiku-5-5 php artisan codemetry:analyze --days=7 --ai=1 --ai-engine=anthropicOr in configuration:
'ai' => [ 'engine' => 'anthropic', 'model' => 'claude-haiku-5-5',],API Key Options
Section titled “API Key Options”Codemetry checks for API keys in this order:
CODEMETRY_AI_API_KEY— Unified key for any engineANTHROPIC_API_KEY— Anthropic-specific key
# Option 1: Unifiedexport CODEMETRY_AI_API_KEY=sk-ant-...
# Option 2: Engine-specificexport ANTHROPIC_API_KEY=sk-ant-...Cost Management
Section titled “Cost Management”Anthropic charges per token. Codemetry sends minimal data:
- ~500-1000 input tokens per day analyzed
- ~200-500 output tokens per summary
Prices change often, so check Anthropic pricing for current per-token rates.
Troubleshooting
Section titled “Troubleshooting”“Invalid API key”
Section titled ““Invalid API key””Cause: API key is incorrect or expired.
Solution:
- Verify key at console.anthropic.com/settings/keys
- Check for typos or extra whitespace
- Ensure key is active
“Rate limit exceeded”
Section titled ““Rate limit exceeded””Cause: Too many requests or exceeded tier limits.
Solution:
- Wait and retry (usually 1-5 minutes)
- Check usage in Anthropic console
- Consider requesting higher limits
“Overloaded”
Section titled ““Overloaded””Cause: Anthropic API is experiencing high load.
Solution:
- Retry after a few seconds
- This is usually temporary
“Model not available”
Section titled ““Model not available””Cause: Model name incorrect or not available in your region.
Solution:
- Check model name spelling
- Use a different model variant
- Verify API access includes the requested model