This document provides information on using environment variables with the TravelAdvisor application.
TravelAdvisor supports environment variables for configuring various API keys and settings. This approach allows you to:
- Keep sensitive configuration out of your codebase
- Easily change configuration without modifying code
- Support different environments (development, testing, production)
- Simplify deployment to Cloud Foundry or other platforms
TravelAdvisor supports multiple ways to configure the application:
- Environment Variables - System-level or process-level environment variables
.envFiles - Local environment variable files for development- User Secrets - The .NET user secrets system for local development
- Cloud Foundry Service Bindings - When running in Cloud Foundry
The application loads configuration in the following order (later sources override earlier ones):
- Default values
.envfile values- User secrets
- System environment variables
- Cloud Foundry service bindings
In ASP.NET Core, environment variables with double underscores (__) are automatically mapped to configuration sections. For example:
GENAI__APIKEYmaps toGenAI:ApiKeyin the configurationGOOGLEMAPS__APIKEYmaps toGoogleMaps:ApiKeyin the configuration
For local development, you can create a .env file in the project root. This file should contain your environment variables in the format:
KEY=VALUE
Example .env file:
# GenAI Configuration
GENAI__APIKEY=your_genai_api_key_here
GENAI__APIURL=https://api.openai.com/v1
GENAI__MODEL=gpt-4o-mini
GENAI__SERVICENAME=travel-advisor-llm
# GoogleMaps Configuration
GOOGLEMAPS__APIKEY=your_googlemaps_api_key_here
The application will automatically load this file at startup.
-
Copy the example file:
cp .env.example .env
-
Edit the
.envfile and replace the placeholder values with your actual API keys. -
Run the application normally:
dotnet run --project src/TravelAdvisor.Web
| Environment Variable | Configuration Key | Description | Default |
|---|---|---|---|
GENAI__APIKEY |
GenAI:ApiKey |
API key for the GenAI service | (required) |
GENAI__APIURL |
GenAI:ApiUrl |
API URL for the GenAI service | https://api.openai.com/v1 |
GENAI__MODEL |
GenAI:Model |
Model name to use | gpt-4o-mini |
GENAI__SERVICENAME |
GenAI:ServiceName |
Service name for Cloud Foundry binding | travel-advisor-llm |
| Environment Variable | Configuration Key | Description | Default |
|---|---|---|---|
GOOGLEMAPS__APIKEY |
GoogleMaps:ApiKey |
API key for Google Maps | (required) |
When deploying to Cloud Foundry, you can bind your application to services. TravelAdvisor will detect services with names containing "genai" or tagged with "genai" and automatically use their credentials.
Example service binding:
applications:
- name: travel-advisor
services:
- travel-advisor-llmYou can create a user-provided service with your credentials:
cf create-user-provided-service travel-advisor-llm -p '{"api_key":"your_api_key", "api_url":"https://api.openai.com/v1", "model":"gpt-4o-mini"}'Then bind it to your application:
cf bind-service travel-advisor travel-advisor-llmIf you're experiencing issues with environment variables:
- Check that your
.envfile is in the correct location (project root) - Verify that the environment variables are formatted correctly (e.g.,
GENAI__APIKEYnotGENAI_APIKEY) - Check for any console log messages about environment variable loading
- Try setting the environment variables directly in your terminal session
- Restart your application after making changes to environment variables