Loading environment variables
Apicentric automatically loads environment variables from a.env file in your project root if one exists. You can also set environment variables directly in your shell or deployment platform.
Creating a .env file
Copy the.env.example file to create your own .env file:
.env with your specific values.
Server configuration
Control how Apicentric’s HTTP server runs.Port number for the Apicentric server.Example:
APICENTRIC_PORT=8080Host address to bind the server to.
0.0.0.0- Listen on all network interfaces127.0.0.1- Listen only on localhost
APICENTRIC_HOST=127.0.0.1Authentication
Configure authentication and security settings.When enabled, requires authentication for all API endpoints.Set to
true to enable JWT authentication.Example: APICENTRIC_PROTECT_SERVICES=trueSecret key used to sign and verify JWT tokens.Example:
APICENTRIC_JWT_SECRET=your-secret-key-hereDatabase
Configure the database for persistent storage.Path to the SQLite database file.The directory will be created automatically if it doesn’t exist.Example:
APICENTRIC_DB_PATH=/var/lib/apicentric/db.sqliteCORS configuration
Configure Cross-Origin Resource Sharing (CORS) for browser requests.Comma-separated list of allowed origins for CORS requests.This is useful when your frontend application runs on a different domain or port than Apicentric.Example:
ALLOWED_ORIGINS=http://localhost:3000,https://app.example.comDefault: http://localhost:3000,http://localhost:9002Logging
Control logging verbosity and output.Log level configuration using Rust’s
env_logger format.Log levels:error- Only errorswarn- Warnings and errorsinfo- Informational messages (default)debug- Detailed debugging informationtrace- Very verbose tracing output
AI configuration
Configure AI providers for code generation features.API key for OpenAI services.Required if you set
ai.provider to openai in your apicentric.json.Example: OPENAI_API_KEY=sk-...API key for Google Gemini services.Required if you set
ai.provider to gemini in your apicentric.json, unless you specify the API key directly in the config file.Example: GEMINI_API_KEY=AIza...Frontend configuration
These variables are used by the Apicentric web UI.URL of the Apicentric API server.This tells the frontend where to send API requests.Example:
NEXT_PUBLIC_API_URL=http://localhost:8000WebSocket URL for real-time updates.Used for live log streaming and state updates in the web UI.Example:
NEXT_PUBLIC_WS_URL=ws://localhost:8000/wsProduction settings
Configure behavior for production deployments.Node.js environment mode.Options:
development- Development mode with hot reloadingproduction- Optimized production builds
NODE_ENV=productionEnable console logging in the frontend application.Set to
false in production to disable console logs.Example: NEXT_PUBLIC_ENABLE_CONSOLE=falseComplete example
Environment variable precedence
When the same setting can be configured in multiple places, Apicentric uses this precedence order (highest to lowest):- Command-line arguments - Flags passed directly to the CLI
- Environment variables - Set in your shell or
.envfile - Configuration file - Settings in
apicentric.json - Default values - Built-in defaults
Security best practices
Follow these security best practices when working with environment variables:
-
Never commit secrets to version control
- Add
.envto your.gitignore - Use
.env.exampleas a template without real secrets
- Add
-
Use strong, random secrets
- Generate JWT secrets with at least 32 bytes of randomness
- Rotate secrets periodically
-
Restrict access in production
- Store secrets in your deployment platform’s secret management system
- Use environment-specific
.envfiles - Limit who can access production secrets
-
Use read-only database paths
- Ensure the database directory has appropriate permissions
- Back up your database regularly
Deployment platforms
Most deployment platforms provide ways to set environment variables:- Docker: Use
docker run -eordocker-compose.ymlenv sections - Kubernetes: Use ConfigMaps and Secrets
- Heroku: Use
heroku config:set - Vercel/Netlify: Use the dashboard or CLI to set environment variables
- AWS/GCP/Azure: Use their respective secret management services
Debugging environment variables
To verify which environment variables are loaded, you can check the logs when Apicentric starts. The log output will show which configuration values are being used (with secrets redacted). You can also use the following command to see all environment variables in your shell:Related pages
- apicentric.json - Main configuration file
- service.yaml - Service definition format