Backend Environment Variables
The backend (POC_ADK/main.py and POC_ADK/data_agente/agent.py) requires the following environment variables.
Google Cloud Configuration
Google Cloud project ID where BigQuery datasets reside.Example:
datawarehouse-des, transelec-prodBigQuery dataset name that the agent will query.Example:
STG_ACTIVOS, ANALYTICS, REPORTINGGoogle Cloud region for Vertex AI and other services.Common values:
us-east4, us-central1, europe-west1Vertex AI Model Configuration
Primary Vertex AI model for the analytics agent.Available models:
gemini-2.5-pro, gemini-2.0-flash, gemini-1.5-proInternal name for the BigQuery agent instance.This is used for logging and agent identification.
Model name for the BigQuery agent (usually same as
ANALYTICS_AGENT_MODEL).Azure AD Authentication
Azure Active Directory tenant ID for authentication.Format: UUID (e.g.,
12345678-1234-1234-1234-123456789abc)Find this in Azure Portal → Azure Active Directory → Overview → Tenant IDAzure AD application (client) ID for JWT validation.Format: UUID (e.g.,
87654321-4321-4321-4321-cba987654321)Find this in Azure Portal → App registrations → Your App → Application (client) IDCORS and Frontend Configuration
Allowed frontend origin for CORS configuration.Must match: The exact URL where your frontend is deployed (including protocol and domain)
The backend implements strict CORS validation. Only requests from the specified
FRONTEND_URL will be accepted.Optional Configuration
Company name used in agent instructions and error messages.This appears in security guardrail messages to users.
Frontend Environment Variables
The frontend (frontend-agente/app/api/copilotkit/route.ts) requires the following environment variables.
Backend API Configuration
Backend API URL for the frontend to connect to.Must be public: Variables prefixed with
NEXT_PUBLIC_ are exposed to the browser.Next.js Configuration
Node.js environment mode. Set automatically by the Docker container.Values:
development, production, testDisables Next.js telemetry collection.Set to
1 to disable, 0 to enable.Port the frontend server listens on.
Hostname binding for the Next.js server.
Environment Variable Examples
Development (.env)
Create a.env file in your backend directory:
.env.local file in your frontend directory:
Production (Cloud Run)
For Cloud Run deployments, set environment variables using thegcloud CLI:
Validation
Backend Validation
The backend validates required variables at startup:Frontend Validation
The frontend uses fallback values:While defaults are provided, it’s strongly recommended to explicitly set all variables in production.
Security Best Practices
Never Commit Secrets
Add
.env files to .gitignore. Never commit sensitive values to version control.Use Secret Manager
For production, consider using Google Secret Manager instead of environment variables:
Rotate Credentials
Regularly rotate Azure AD client secrets and update the
AZURE_CLIENT_ID accordingly.Troubleshooting
Missing Required Variables
If the backend crashes withKeyError, check that all required variables are set:
CORS Issues
If you see CORS errors, verify theFRONTEND_URL matches exactly:
Wrong Backend URL
If the frontend can’t connect, verifyNEXT_PUBLIC_API_URL:
Variable Reference Table
| Variable | Service | Required | Default | Description |
|---|---|---|---|---|
PROJECT_ID | Backend | Yes | datawarehouse-des | Google Cloud project ID |
BIGQUERY_DATASET | Backend | Yes | STG_ACTIVOS | BigQuery dataset name |
GOOGLE_CLOUD_LOCATION | Backend | Yes | us-east4 | GCP region |
ANALYTICS_AGENT_MODEL | Backend | Yes | gemini-2.5-pro | Vertex AI model |
LLM_1_NAME | Backend | No | bigquery_agent_stg_activos | Agent name |
LLM_1_MODELO | Backend | No | gemini-2.5-pro | Agent model |
AZURE_TENANT_ID | Backend | Required | None | Azure AD tenant ID |
AZURE_CLIENT_ID | Backend | Required | None | Azure AD client ID |
FRONTEND_URL | Backend | Yes | Cloud Run URL | CORS allowed origin |
NOMBRE_EMPRESA | Backend | No | TRANSELEC S.A. | Company name |
NEXT_PUBLIC_API_URL | Frontend | Yes | Cloud Run URL | Backend API URL |
NODE_ENV | Frontend | No | production | Node environment |
NEXT_TELEMETRY_DISABLED | Frontend | No | 1 | Disable telemetry |
Next Steps
Docker Deployment
Build Docker containers with environment variables
Cloud Run Deployment
Deploy to Cloud Run with proper configuration