Skip to content

Anthropic

Anthropic’s Claude models are known for thoughtful, nuanced responses and strong reasoning capabilities.

  1. Get an API Key

    Visit console.anthropic.com/settings/keys to create an API key.

  2. Set Environment Variable

    Terminal window
    export ANTHROPIC_API_KEY=sk-ant-...

    Or add to your .env file:

    ANTHROPIC_API_KEY=sk-ant-...
  3. Configure Codemetry

    config/codemetry.php
    'ai' => [
    'enabled' => true,
    'engine' => 'anthropic',
    'model' => null, // Uses claude-3-5-haiku by default
    ],
  4. Run Analysis

    Terminal window
    php artisan codemetry:analyze --days=7 --ai=1 --ai-engine=anthropic
Model Default Cost Quality Speed
claude-3-5-haiku-latest Low Good Fast
claude-3-5-sonnet-latest Medium Excellent Medium
claude-3-opus-latest High Best Slow

For routine analysis: Use claude-3-5-haiku-latest (default)

  • Fast and cost-effective
  • Good quality explanations
  • Best for daily/weekly analyses

For detailed investigation: Use claude-3-5-sonnet-latest

  • Superior reasoning about patterns
  • More comprehensive explanations
  • Good for monthly reviews or investigations

For critical analyses: Use claude-3-opus-latest

  • Best-in-class reasoning
  • Most thorough explanations
  • Use sparingly due to cost
Terminal window
# Override model for single run
php artisan codemetry:analyze --days=7 --ai=1 --ai-engine=anthropic --ai-model=claude-3-5-sonnet-latest

Or in configuration:

'ai' => [
'engine' => 'anthropic',
'model' => 'claude-3-5-sonnet-latest',
],

Codemetry checks for API keys in this order:

  1. CODEMETRY_AI_API_KEY — Unified key for any engine
  2. ANTHROPIC_API_KEY — Anthropic-specific key
Terminal window
# Option 1: Unified
export CODEMETRY_AI_API_KEY=sk-ant-...
# Option 2: Engine-specific
export ANTHROPIC_API_KEY=sk-ant-...

Anthropic charges per token. Codemetry sends minimal data:

  • ~500-1000 input tokens per day analyzed
  • ~200-500 output tokens per summary

Estimated costs per 30-day analysis:

Model Input Output Total
claude-3-5-haiku ~$0.003 ~$0.008 ~$0.011
claude-3-5-sonnet ~$0.01 ~$0.05 ~$0.06
claude-3-opus ~$0.05 ~$0.25 ~$0.30

Cause: API key is incorrect or expired.

Solution:

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

Cause: Anthropic API is experiencing high load.

Solution:

  • Retry after a few seconds
  • This is usually temporary

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