OpenAI
OpenAI provides GPT models known for strong general reasoning. It’s the default AI engine in Codemetry.
-
Get an API Key
Visit platform.openai.com/api-keys to create an API key.
-
Set Environment Variable
Terminal window export OPENAI_API_KEY=sk-proj-...Or add to your
.envfile:OPENAI_API_KEY=sk-proj-... -
Configure Codemetry
config/codemetry.php 'ai' => ['enabled' => true,'engine' => 'openai','model' => null, // Uses gpt-6-luna by default], -
Run Analysis
Terminal window php artisan codemetry:analyze --days=7 --ai=1
Available Models
Section titled “Available Models”| 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.
Choosing a Model
Section titled “Choosing a Model”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:
CODEMETRY_AI_MODEL=gpt-6.1-sol php artisan codemetry:analyze --days=7 --ai=1Or in configuration:
'ai' => [ 'engine' => 'openai', 'model' => 'gpt-6.1-sol',],API Key Options
Section titled “API Key Options”Codemetry checks for API keys in this order:
CODEMETRY_AI_API_KEY— Unified key for any engineOPENAI_API_KEY— OpenAI-specific key
# Option 1: Unified (works if you switch engines)export CODEMETRY_AI_API_KEY=sk-proj-...
# Option 2: Engine-specificexport OPENAI_API_KEY=sk-proj-...Cost Management
Section titled “Cost Management”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.
Troubleshooting
Section titled “Troubleshooting”“Invalid API key”
Section titled ““Invalid API key””Cause: API key is incorrect or expired.
Solution:
- Verify key at platform.openai.com/api-keys
- Check for typos or extra whitespace
- Ensure key has not been revoked
“Rate limit exceeded”
Section titled ““Rate limit exceeded””Cause: Too many requests or token usage exceeded tier limits.
Solution:
- Wait and retry
- Check usage at platform.openai.com/usage
- Consider upgrading your OpenAI tier
“Model not found”
Section titled ““Model not found””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
AI Summary Missing
Section titled “AI Summary Missing”Cause: AI request failed, analysis continued without it.
Check:
ai_unavailableconfounder in output indicates AI failed- Check Laravel logs for detailed error messages
- Verify network connectivity to OpenAI