Skip to content

AI Engines Overview

Codemetry can optionally use AI to generate human-readable explanations of analysis results. AI summarization is entirely opt-in and privacy-conscious.

AI features are disabled by default. You must explicitly enable them:

Terminal window
php artisan codemetry:analyze --days=7 --ai=1

Or in configuration:

'ai' => [
'enabled' => true,
// ...
],

AI engines never receive code or diffs. They only receive:

  • Aggregated metrics (churn, scatter, fix counts)
  • Normalized values (z-scores, percentiles)
  • Computed scores and labels
  • Confounders (flags like large_refactor_suspected)

This design ensures your source code stays private.

If AI is enabled but unavailable:

  • Analysis continues normally
  • Heuristic scores are unaffected
  • ai_unavailable confounder is added
  • No AI summary in output

OpenAI

GPT-6 Luna (default), Sol, Astra. Best balance of quality and cost.

Anthropic

Claude Sonnet 5.5 (default), Haiku 5.5, Opus 5.5. Excellent reasoning quality.

DeepSeek

DeepSeek Flash (default), V4 Pro. Cost-effective alternative.

Google

Gemini 3.8 Flash (default), 3.5 Flash-Lite, 4 Argon. Google Cloud integration.

Terminal window
# Set in environment
export CODEMETRY_AI_ENGINE=openai # or: anthropic, deepseek, google
Terminal window
# Engine-specific key
export OPENAI_API_KEY=sk-...
# Or unified key
export CODEMETRY_AI_API_KEY=sk-...
Terminal window
php artisan codemetry:analyze --days=7 --ai=1
config/codemetry.php
'ai' => [
'enabled' => false, // Set true to enable by default
'engine' => env('CODEMETRY_AI_ENGINE', 'openai'),
'model' => env('CODEMETRY_AI_MODEL', null), // null = engine default
'api_key' => env('CODEMETRY_AI_API_KEY', null),
'batch_size' => env('CODEMETRY_AI_BATCH_SIZE', 10), // Days per API call
],
Option Description
enabled Enable AI by default (can override with --ai=0/1)
engine Which AI provider to use
model Specific model (null = use engine’s default)
api_key API key (falls back to engine-specific env vars)
batch_size Number of days to process per API call (default: 10)

When AI is enabled, each analysis window includes:

{
"ai_summary": {
"explanation_bullets": [
"High churn (95th percentile) indicates major development activity.",
"The presence of reverts suggests some changes needed rollback.",
"Despite the bad score, the large_refactor_suspected flag hints at planned restructuring.",
"Consider reviewing commit history to confirm this was intentional work."
],
"score_delta": 0,
"confidence_delta": 0.0,
"label_override": null
}
}

Human-readable insights about the day’s metrics. Useful for:

  • Team reports
  • Executive summaries
  • Understanding why a day scored poorly

AI can suggest score adjustments (V1: always 0). Future versions may allow AI to fine-tune scores based on context.

AI can suggest overriding the label (V1: always null). Example: changing “bad” to “medium” if metrics suggest false positive.

Codemetry batches multiple days into a single API call for efficiency. By default, 10 days are processed per request.

'ai' => [
'batch_size' => 10, // Process 10 days per API call
],

Benefits:

  • Fewer API calls: A 30-day analysis requires only 3 API calls instead of 30
  • Lower latency: Fewer round-trips to the AI provider
  • Cost efficiency: Batch requests are more token-efficient

You can adjust batch_size based on your needs:

  • Higher values (15-20): Fewer API calls, but larger request/response sizes
  • Lower values (1-5): More granular error handling, but more API calls

AI costs are per API call, and batching significantly reduces total calls. Codemetry’s requests are small: roughly 500-1000 input tokens per day analyzed and 200-500 output tokens per summary.

Engine Default model Cheaper option Pricing
OpenAI gpt-6-luna — openai.com/api/pricing
Anthropic claude-sonnet-5-5 claude-haiku-5-5 Anthropic pricing
DeepSeek deepseek-flash — DeepSeek pricing
Google gemini-3.8-flash gemini-3.5-flash-lite Gemini API pricing

Codemetry is fully functional without AI:

  • Heuristic scores are deterministic and reliable
  • Reasons explain score contributors
  • Confounders provide context flags
  • JSON output includes all raw data

AI adds explanatory convenience, not core functionality.