- Open PowerShell in your project directory
- Run this ONE command:
.\deploy-complete-fix.ps1
- Wait 8-10 minutes
- Your backend will be fully operational with ZERO 403 errors
The backend code had silent fallbacks that tried to use the public Gemini API with service account credentials. Service accounts don't have permission to use that API β 403 error.
β
Removed all fallback mechanisms
β
Strict Vertex AI mode with proper error handling
β
Added google-cloud-aiplatform SDK
β
Automated deployment script that handles everything
β
Diagnostic script to verify everything works
cd C:\Users\surya\OneDrive\Desktop\suryansh\coding_projects\gemini-hackathon
.\deploy-complete-fix.ps1 -ProjectId "legalmind-486106"That's it. The script will:
- Fix all GCP permissions
- Build your Docker image
- Deploy to Cloud Run
- Verify it works
- Show you the service URL
Total time: ~8 minutes
Check if it's working:
gcloud run services logs read legalmind-backend --region=us-central1 --followLook for: "β Using Vertex AI with Application Default Credentials"
| File | Purpose |
|---|---|
deploy-complete-fix.ps1 |
π RUN THIS - Complete automated fix |
deploy-complete-fix.sh |
Same but for Linux/Mac |
diagnose-deployment.ps1 |
Verify everything is working |
docs/CRITICAL_FIX_403_SCOPE_ERROR.md |
Full technical details |
File: backend/services/gemini_service.py
# BEFORE: Had fallback that caused 403 error
if self.use_vertex:
GenerativeModel = _safely_import_vertex_class("GenerativeModel")
if GenerativeModel:
self._model = GenerativeModel(...)
else:
# π΄ Falls back to REST API (WRONG!)
self.use_vertex = False
self._model = genai.GenerativeModel(...)
# AFTER: Strict mode, no fallback
if self.use_vertex:
GenerativeModel = _safely_import_vertex_class("GenerativeModel")
if not GenerativeModel:
# π’ Fails with clear error (RIGHT!)
raise RuntimeError(
"Vertex AI SDK not installed. "
"Install: pip install google-cloud-aiplatform"
)
self._model = GenerativeModel(...)File: backend/requirements.txt
Added: google-cloud-aiplatform>=1.50.0
- Your backend needs Vertex AI credentials
- When running on Cloud Run, it uses service account credentials automatically
- The code had a bug: if Vertex AI wasn't available, it tried to use the public API instead
- Public API doesn't work with service account credentials
- Public API requires an API key
- Result: 403 "you don't have permission"
The fix: Don't fall back to public API. Just use Vertex AI and fail fast if it's not available.
-
Run the diagnostic:
.\diagnose-deployment.ps1 -
Check logs:
gcloud run services logs read legalmind-backend --region=us-central1 --limit=50 -
Read the full guide:
docs/CRITICAL_FIX_403_SCOPE_ERROR.md
- Now: Run the deployment script
- In 2-5 minutes: Docker build and push complete
- In 5-8 minutes: Cloud Run deployment complete
- In ~8 minutes: Backend is live and accepting requests
Stop reading. Run the command. Done. β¨
.\deploy-complete-fix.ps1