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-sonnet-5-5 by default
    ],
  4. Run Analysis

    Terminal window
    php artisan codemetry:analyze --days=7 --ai=1 --ai-engine=anthropic
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.

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:

Terminal window
CODEMETRY_AI_MODEL=claude-haiku-5-5 php artisan codemetry:analyze --days=7 --ai=1 --ai-engine=anthropic

Or in configuration:

'ai' => [
'engine' => 'anthropic',
'model' => 'claude-haiku-5-5',
],

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

Prices change often, so check Anthropic pricing for current per-token rates.

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