# Vision API Enablement Guide

**Last Updated:** 2026-01-19

## Current Status

✅ **API Key Configuration:** Complete - Vision API uses the same key as ShiftOps  
⚠️ **API Enablement:** Pending - Vision API needs to be enabled in GCP project

## Important: Project Consistency

Vision API **must be enabled in the same GCP project** that your Google Maps API key belongs to (the project ShiftOps uses). This ensures:

- Consistent API key management
- Same billing account
- Unified project administration
- Easier troubleshooting

## Step 1: Identify Your Project

Run this script to find which project your API key belongs to:

```bash
php v2/scripts/find-api-key-project.php
```

This will show you:
- The project number your API key belongs to
- Direct links to enable Vision API
- Links to enable billing
- Links to configure API key restrictions

**Example Output:**
```
✓ Project Number Found: 842128635996

To enable Vision API:
1. Visit: https://console.cloud.google.com/apis/api/vision.googleapis.com/overview?project=842128635996
2. Click 'Enable'
```

## Step 2: Enable Vision API

1. **Open the URL** provided by the script (or manually navigate to Google Cloud Console)
2. **Select the correct project** (the one your API key belongs to - same as ShiftOps)
3. **Click "Enable"** button
4. **Wait 1-2 minutes** for changes to propagate

## Step 3: Enable Billing (if needed)

Vision API requires billing to be enabled, even for free tier usage:

1. Navigate to: https://console.cloud.google.com/billing?project=YOUR_PROJECT_NUMBER
2. Link a billing account if not already linked
3. Verify billing is active

## Step 4: Configure API Key Restrictions

Ensure your API key has Vision API enabled:

1. Navigate to: https://console.cloud.google.com/apis/credentials?project=YOUR_PROJECT_NUMBER
2. Find your API key (the one ShiftOps uses)
3. Click to edit
4. Under "API restrictions", ensure "Cloud Vision API" is checked
5. Save changes

## Step 5: Verify Setup

After enabling, test the setup:

```bash
# Test API connectivity
php v2/scripts/test-vision-api-direct.php

# Run complete test suite
php v2/scripts/test-ocr-complete.php

# Check diagnostics dashboard
# Visit: /v2/admin/ocr-diagnostics.php?debug=1
```

## Troubleshooting

### "API has not been used in project X before"

**Solution:** Enable Vision API in that project (use the script to get the exact URL)

### "Billing not enabled"

**Solution:** Enable billing for the project (use the script to get the exact URL)

### "API key not valid"

**Solution:** 
1. Check API key restrictions include Vision API
2. Verify you're using the same key as ShiftOps
3. Ensure the key belongs to the correct project

## Quick Reference

**Find Project:**
```bash
php v2/scripts/find-api-key-project.php
```

**Test API:**
```bash
php v2/scripts/test-vision-api-direct.php
```

**Diagnostics:**
```bash
php v2/scripts/ocr-diagnose-api-key.php
php v2/scripts/monitor-ocr-api.php
```

**Web Dashboard:**
```
/v2/admin/ocr-diagnostics.php?debug=1
```

## Notes

- Vision API uses the **same API key** as ShiftOps (Google Maps API key)
- Must be enabled in the **same GCP project** as ShiftOps
- This ensures consistency across all Google APIs
- No separate API key needed unless you want to use a different project
