Skip to content

Google AI

Google’s Gemini models offer strong reasoning capabilities with good integration into Google Cloud environments.

  1. Get an API Key

    Visit aistudio.google.com/apikey to create an API key.

    Alternatively, use Google Cloud’s Vertex AI for enterprise deployments.

  2. Set Environment Variable

    Terminal window
    export GOOGLE_AI_API_KEY=AIza...

    Or add to your .env file:

    GOOGLE_AI_API_KEY=AIza...
  3. Configure Codemetry

    config/codemetry.php
    'ai' => [
    'enabled' => true,
    'engine' => 'google',
    'model' => null, // Uses gemini-3.8-flash by default
    ],
  4. Run Analysis

    Terminal window
    php artisan codemetry:analyze --days=7 --ai=1 --ai-engine=google
Model Default Cost Quality Speed
gemini-3.8-flash ✓ Low Good Very Fast
gemini-3.5-flash-lite Very Low Good Very Fast
gemini-4-argon High Best Medium

Google 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 gemini-3.8-flash (default)

  • Google’s current Flash model: fast and inexpensive

Alternative: Use gemini-3.5-flash-lite

  • The lowest-cost option for frequent runs

For critical analyses: Use gemini-4-argon

  • Google’s Pro-tier model for deeper investigations

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

Terminal window
CODEMETRY_AI_MODEL=gemini-3.5-flash-lite php artisan codemetry:analyze --days=7 --ai=1 --ai-engine=google

Or in configuration:

'ai' => [
'engine' => 'google',
'model' => 'gemini-3.5-flash-lite',
],

Codemetry checks for API keys in this order:

  1. CODEMETRY_AI_API_KEY — Unified key for any engine
  2. GOOGLE_AI_API_KEY — Google AI-specific key
Terminal window
# Option 1: Unified
export CODEMETRY_AI_API_KEY=AIza...
# Option 2: Engine-specific
export GOOGLE_AI_API_KEY=AIza...

Google 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 Gemini API pricing for current per-token rates.

For enterprise deployments, consider using Vertex AI:

  1. Enable Vertex AI API in Google Cloud Console
  2. Set up authentication (service account or ADC)
  3. Use Vertex AI endpoints instead of AI Studio

This provides:

  • Enterprise SLAs
  • VPC integration
  • Compliance certifications
  • Centralized billing

Cause: API key is incorrect or not enabled.

Solution:

Cause: Free tier limits reached.

Solution:

  • Wait for quota reset (resets periodically)
  • Enable billing for higher limits
  • Use Flash models for lower quota consumption

Cause: Model name incorrect or model deprecated.

Solution:

  • Check current model names in Google AI documentation
  • Model names may change as versions update
  • Use a different model variant

Cause: Google AI not available in your region.

Solution:

  • Check Google AI availability for your region
  • Consider using a VPN for development
  • Use a different AI engine

Symptom: gemini-4-argon takes longer than expected.

Solution:

  • This is normal; Pro models prioritize quality over speed
  • Use gemini-3.8-flash (the default) for faster responses
  • Consider Pro only for detailed investigations