This document describes the multi-tier configuration system for API keys and model settings in Prompt Optimizer. The system supports three primary configuration methods: UI-based configuration (recommended for most users), environment variables (for deployment scenarios), and runtime configuration injection (for Docker deployments). This page covers the configuration architecture, built-in model setup, custom model patterns, and configuration precedence rules.
For deployment-specific configuration details, see Docker Deployment and Vercel Deployment. For information about model adapters and provider integration, see Model Configuration Management and LLM Service and Provider Adapters.
The configuration system is designed with multiple tiers to support different deployment scenarios while maintaining consistent behavior across all platforms.
Sources: packages/core/src/utils/environment.ts225-255 packages/core/src/services/model/defaults.ts39-94 packages/core/src/services/model/manager.ts22-193
The getEnvVar() function implements a three-tier priority system that determines which configuration source takes precedence:
| Priority | Source | Use Case | Access Method |
|---|---|---|---|
| 3 (Highest) | window.runtime_config | Docker runtime injection | window.runtime_config[key] (without VITE_ prefix) |
| 2 (Medium) | process.env | Node.js, Electron main process | process.env[key] |
| 1 (Lowest) | import.meta.env | Vite development, static build | import.meta.env[key] |
This priority system ensures that runtime configuration (Docker) can override build-time settings, while development environments have sensible defaults.
Sources: packages/core/src/utils/environment.ts225-255
The system recognizes eleven built-in providers, each configurable through environment variables following the pattern VITE_{PROVIDER}_API_KEY.
Sources: packages/core/src/services/model/defaults.ts11-20 packages/core/src/services/model/defaults.ts39-94
The getDefaultTextModels() function creates TextModelConfig objects for each provider by:
TextAdapterRegistry to get TextProvider and TextModel metadatagetEnvVar() for each provider's environment variablemodelMeta.defaultParameterValuesSources: packages/core/src/services/model/defaults.ts39-94
Beyond the built-in providers, the system supports unlimited custom models through a pattern-based environment variable convention: VITE_CUSTOM_API_{TYPE}_{SUFFIX}.
Each custom model requires three environment variables with matching suffixes:
| Variable Pattern | Purpose | Example |
|---|---|---|
VITE_CUSTOM_API_KEY_{suffix} | API key for authentication | VITE_CUSTOM_API_KEY_ollama=dummy_key |
VITE_CUSTOM_API_BASE_URL_{suffix} | Base URL for API endpoint | VITE_CUSTOM_API_BASE_URL_ollama=http://localhost:11434/v1 |
VITE_CUSTOM_API_MODEL_{suffix} | Model identifier | VITE_CUSTOM_API_MODEL_ollama=qwen2.5:7b |
Suffix Validation Rules (defined in packages/core/src/utils/environment.ts6-8):
SUFFIX_PATTERN: Must match /^[a-zA-Z0-9_-]+$/MAX_SUFFIX_LENGTH: Maximum 50 charactersSources: packages/core/src/utils/environment.ts263-394 packages/core/src/utils/environment.ts61-108
The generateDynamicModels() function (in packages/core/src/services/model/model-utils.ts) converts validated custom model environment variables into TextModelConfig objects:
scanCustomModelEnvVars() to find all valid custom model configurationscustom_{suffix} for the model IDTextModel using the OpenAI adapter as the baseconnectionConfig with the custom base URL and API keyenabled: true for all successfully scanned custom modelsExample: Environment variables for a local Ollama instance:
This generates a TextModelConfig with ID custom_ollama, enabling local model access without code changes.
Sources: README.md281-288 README_EN.md277-288
Users can configure models through the ModelManager UI component, which provides a graphical interface for all configuration options.
Sources: packages/ui/src/components/ModelManager.vue1-198
The UI exposes the following configuration options for text models:
| Field | Type | Description | UI Location |
|---|---|---|---|
name | string | Display name for the model | Model header |
enabled | boolean | Whether model is active | Toggle switch |
connectionConfig.apiKey | string | API authentication key | Protected input field |
connectionConfig.baseURL | string | API endpoint URL | Text input |
modelMeta.id | string | Selected model identifier | Dropdown |
paramOverrides | Record<string, unknown> | Model-specific parameters | Advanced settings panel |
Advanced Parameter Configuration: The llmParams field (now unified into paramOverrides) allows setting any parameter supported by the provider's SDK, such as:
{"temperature": 0.7, "max_tokens": 4096, "timeout": 60000}{"temperature": 0.8, "maxOutputTokens": 2048, "topP": 0.95}{"temperature": 0.5, "top_p": 0.9, "frequency_penalty": 0.1}Sources: README.md248-269 README_EN.md252-273
Docker deployments use environment variables injected at runtime through the container's environment and exposed via window.runtime_config.
Sources: docker-compose.yml1-44 docker-compose.dev.yml1-37
Docker deployments support all configuration variables through the environment section of docker-compose.yml:
Built-in Model Keys:
Custom Model Configuration:
Access Control:
The generate-auth.sh script (docker/generate-auth.sh1-46) processes ACCESS_PASSWORD to create HTTP Basic Authentication if provided.
Sources: docker-compose.yml18-41 docker/generate-auth.sh1-46
Vercel deployments configure API keys through environment variables in the Vercel project settings. The vercel.json file defines the build configuration:
Environment variables are set through the Vercel dashboard:
VITE_OPENAI_API_KEY, VITE_GEMINI_API_KEY, etc.ACCESS_PASSWORD for deployment protection (optional)During build, Vite inlines these environment variables into the static bundle via import.meta.env.
Sources: vercel.json1-32 README.md89-94 README_EN.md89-94
Electron desktop applications use a specialized configuration manager that synchronizes environment variables from the main process to the renderer process.
Sources: packages/core/src/services/model/manager.ts80-85
The ElectronConfigManager ensures that environment variables from the Electron main process (which has access to Node.js process.env) are available to the renderer process's model initialization logic. This is necessary because Electron's security model prevents direct access to process.env from renderer processes.
Sources: packages/core/src/index.ts66
The system validates configuration at multiple stages to ensure correctness before use.
| Layer | Function | Location | Checks |
|---|---|---|---|
| Environment Scanning | validateCustomModelConfig() | packages/core/src/utils/environment.ts61-108 | Suffix format, API key presence, URL validity, model name |
| Model Manager | validateTextModelConfig() | packages/core/src/services/model/manager.ts644-697 | Required fields, parameter schema compliance |
| LLM Service | validateModelConfig() | packages/core/src/services/llm/service.ts57-76 | Provider metadata, model metadata, enabled state |
| Parameter Validation | validateOverrides() | packages/core/src/services/model/parameter-utils.ts | Type checking, enum values, range constraints |
The ValidationResult interface (packages/core/src/utils/environment.ts47-54) provides structured feedback:
Errors prevent model usage and must be resolved. Warnings indicate potential issues (e.g., short API key) but don't block functionality.
Sources: packages/core/src/utils/environment.ts47-108 packages/core/src/services/model/manager.ts644-697
Model configurations are persisted to storage and automatically migrated between format versions.
Sources: packages/core/src/services/model/manager.ts75-193 packages/core/src/services/model/manager.ts216-238
The migrateConfig() method (packages/core/src/services/model/manager.ts216-238) handles backward compatibility by merging deprecated customParamOverrides into the unified paramOverrides field:
This ensures configurations from older versions continue to work while guiding users toward the new unified parameter system.
Sources: packages/core/src/services/model/manager.ts216-238
The shouldAutoEnableBuiltinModel() method (packages/core/src/services/model/manager.ts611-640) implements intelligent model activation:
Conditions for Auto-Enable:
getBuiltinModelIds() listenabled: falseconnectionConfig.apiKey is emptyThis allows environment variable changes (e.g., adding VITE_OPENAI_API_KEY after initial setup) to automatically activate previously disabled models without manual intervention.
Sources: packages/core/src/services/model/manager.ts611-640
The ModelManager implements the IImportExportable interface (packages/core/src/interfaces/import-export.ts) for bulk configuration management.
The exportData() method (packages/core/src/services/model/manager.ts715-726) returns all models as an array of TextModelConfig objects:
The importData() method (packages/core/src/services/model/manager.ts731-800) handles both new (TextModelConfig) and legacy (ModelConfig) formats:
This design allows partial import success and provides detailed error reporting for troubleshooting.
Refresh this wiki