Skip to content

OpenAI

OpenAI provides GPT models known for strong general reasoning. It’s the default AI engine in Codemetry.

  1. Get an API Key

    Visit platform.openai.com/api-keys to create an API key.

  2. Set Environment Variable

    Terminal window
    export OPENAI_API_KEY=sk-proj-...

    Or add to your .env file:

    OPENAI_API_KEY=sk-proj-...
  3. Configure Codemetry

    config/codemetry.php
    'ai' => [
    'enabled' => true,
    'engine' => 'openai',
    'model' => null, // Uses gpt-6-luna by default
    ],
  4. Run Analysis

    Terminal window
    php artisan codemetry:analyze --days=7 --ai=1
Model Default Cost Quality Speed
gpt-6-luna ✓ Low Good Fast
gpt-6.1-sol Medium Excellent Medium
gpt-6-astra High Best Slower

OpenAI 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 gpt-6-luna (default)

  • OpenAI’s most efficient model, built for focused, high-volume tasks like Codemetry’s metric explanations

Alternative: Use gpt-6.1-sol

  • Close to Astra quality at a lower cost

For critical analyses: Use gpt-6-astra

  • OpenAI’s most capable model; use it sparingly

There is no --ai-model flag. To override the model for a single run, set CODEMETRY_AI_MODEL:

Terminal window
CODEMETRY_AI_MODEL=gpt-6.1-sol php artisan codemetry:analyze --days=7 --ai=1

Or in configuration:

'ai' => [
'engine' => 'openai',
'model' => 'gpt-6.1-sol',
],

Codemetry checks for API keys in this order:

  1. CODEMETRY_AI_API_KEY — Unified key for any engine
  2. OPENAI_API_KEY — OpenAI-specific key
Terminal window
# Option 1: Unified (works if you switch engines)
export CODEMETRY_AI_API_KEY=sk-proj-...
# Option 2: Engine-specific
export OPENAI_API_KEY=sk-proj-...

OpenAI 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 OpenAI pricing for current per-token rates.

Cause: API key is incorrect or expired.

Solution:

Cause: Too many requests or token usage exceeded tier limits.

Solution:

Cause: Invalid model name or model not available on your account.

Solution:

  • Check model name spelling
  • Verify model availability for your account tier
  • Use a different model

Cause: AI request failed, analysis continued without it.

Check:

  • ai_unavailable confounder in output indicates AI failed
  • Check Laravel logs for detailed error messages
  • Verify network connectivity to OpenAI