- 403 Error: Backend was using public Gemini API instead of Vertex AI
- Port Mismatch: Dockerfile set PORT=8000, Cloud Run expects PORT=8080
- Import Errors: Old incompatible files conflicting with new code
Problem: Backend defaulted to public Gemini API (generativelanguage.googleapis.com)
Root: use_vertex_ai: bool = False in settings.py
Changes:
- backend/config/settings.py: Changed default
use_vertex_aifromFalse→True - backend/config/settings.py: Changed env var default from
"false"→"true" - Dockerfile: Added
ENV USE_VERTEX_AI=true - backend/.env.example: Documented
USE_VERTEX_AI=truesetting
Result: Backend now uses Vertex AI (aiplatform.googleapis.com) by default
Problem: Dockerfile set ENV PORT=8000, overriding Cloud Run's PORT=8080
Error: "Container failed to start and listen on the port defined by PORT=8080"
Changes:
- Dockerfile: Removed
ENV PORT=8000line - Added comment explaining Cloud Run sets PORT=8080 automatically
Result: Backend now listens on Cloud Run's PORT (8080)
Problem: Multiple versions of files causing import conflicts
Old incompatible files (renamed to .old.py):
backend/main.py→backend/main.old.pybackend/api/app.py→backend/api/app.old.pybackend/api/endpoints.py→backend/api/endpoints.old.pybackend/agents/agent_definitions.py→backend/agents/agent_definitions.old.pybackend/agents/agent_strategies.py→backend/agents/agent_strategies.old.pybackend/managers/chatbot_manager.py→backend/managers/chatbot_manager.old.py
New files activated (renamed from *_new.py → *.py):
backend/main_new.py→backend/main.pybackend/api/app_new.py→backend/api/app.pybackend/api/endpoints_new.py→backend/api/endpoints.pybackend/agents/agent_definitions_new.py→backend/agents/agent_definitions.pybackend/agents/agent_strategies_new.py→backend/agents/agent_strategies.pybackend/managers/chatbot_manager_new.py→backend/managers/chatbot_manager.py
Import updates in backend/api/app.py: -FROM:
from managers.chatbot_manager_new import get_chatbot_manager
from api.endpoints_new import router
from agents.agent_strategies_new import get_workflow_template
from agents.agent_definitions_new import get_agent_configTO:
from managers.chatbot_manager import get_chatbot_manager
from api.endpoints import router
from agents.agent_strategies import get_workflow_template
from agents.agent_definitions import get_agent_configImport updates in backend/main.py:
uvicorn.run("api.app:app", ...) # Changed from "api.app_new:app"Dockerfile CMD updated:
CMD ["python", "main.py"] # Changed from "main_new.py"Result: All imports resolved, no more conflicting file versions
gcloud run deploy legalmind-backend \
--source=backend \
--project=legalmind-486106 \
--region=us-central1 \
--allow-unauthenticated \
--set-env-vars="USE_VERTEX_AI=true" \
--timeout=300After deployment completes:
- ✅ Backend starts successfully on PORT=8080
- ✅ Health endpoint responds with HTTP 200
- ✅ Vertex AI configured correctly (no 403 errors)
- ✅ Contract analysis works without authentication errors
# Health check
curl https://legalmind-backend-677928716377.us-central1.run.app/health
# Expected response:
{
"status": "healthy",
"service": "LegalMind API",
"timestamp": "..."
}Dockerfile- Removed PORT override, added USE_VERTEX_AIbackend/config/settings.py- Changed defaults to use Vertex AIbackend/.env.example- Documented USE_VERTEX_AI settingbackend/main.py- Updated imports (renamed from main_new.py)backend/api/app.py- Updated imports (renamed from app_new.py)- Multiple backend modules - Renamed from *_new.py to *.py
Root Cause: Configuration defaulted to public Gemini API + old incompatible files
Solution: Enable Vertex AI by default + clean up file conflicts + fix port configuration
Status: Deployment in progress
Deployment Time: ~3-5 minutes
Once deployment completes, the backend will:
- Use Vertex AI exclusively (
aiplatform.googleapis.com) - Listen on the correct port (8080)
- Have no import conflicts
- Work correctly with Cloud Run service accounts