This script automatically seeds default credentials from environment variables into the Flowise database. It detects all AAI_DEFAULT_* environment variables and creates encrypted credentials for various AI and third-party services with enhanced safety features, interactive database connection recovery, and smart auto-detection for local development scenarios.
The credential seeding script provides:
- Automatic Detection: Scans for all
AAI_DEFAULT_*environment variables - Multiple Credential Types: Supports both single API key and multi-field credential configurations
- Auto-Discovery: Attempts to detect unmapped credentials by matching them to credential files
- Database Integration: Directly inserts encrypted credentials into the Flowise database
- Secure Encryption: Uses the same encryption method as the Flowise server
- Interactive Database Recovery: Prompts for PostgreSQL URL when connection fails
- SSL Auto-Detection: Automatically applies SSL for cloud database providers
- User/Organization Verification: Verifies credentials will be assigned to valid users/organizations
- Enhanced Safety: Test mode shows what would be changed before making modifications
- Robust Environment Loading: Multiple fallback paths for .env file loading
- Smart Auto-Detection: DEFAULT - Automatically detects single user/org scenarios for local development
- Environment File Management: Offers to update .env files with selected values for future use
⚠️ Default is Safe:pnpm seed-credentialsnow runs in TEST MODE with AUTO-DETECTION (dry-run, no writes). To actually write credentials to the database, you must usepnpm seed-credentials:write.
# Test mode with auto-detection (recommended for local development)
pnpm seed-credentials
# OR
pnpm run seed-credentials
# Production mode with auto-detection (actually creates/updates credentials)
pnpm seed-credentials:write
# OR
pnpm run seed-credentials:write
# Debug mode (shows detailed environment variable loading)
pnpm seed-credentials -- --debug
# Combined test and debug mode
pnpm seed-credentials -- --debug
# Direct node usage (advanced)
node scripts/seed-credentials/seed-credentials.js --test --auto-detect
node scripts/seed-credentials/seed-credentials.js --debug
node scripts/seed-credentials/seed-credentials.js --auto-detect
node scripts/seed-credentials/seed-credentials.js --test --debug
node scripts/seed-credentials/seed-credentials.js # (production, not recommended)The script now includes intelligent auto-detection for local development scenarios:
When the script detects exactly one user and one organization in your database, it will:
- Auto-Suggest Values: Automatically select the single user and organization
- Confirm with User: Ask for confirmation before using the auto-detected values
- Fallback to Manual: If you decline, fall back to the traditional manual selection
- Update .env Files: Offer to save the selected values to your .env file for future use
- Single User + Single Org: Auto-detects and suggests these values
- Multiple Users/Orgs: Shows all available options for manual selection
- No Users/Orgs: Provides clear error messages and guidance
- Confirmation Required: Always asks for confirmation before using auto-detected values
After selecting user/organization values, the script will:
- Detect .env Files: Find existing .env files in common locations
- Offer Updates: Ask if you want to save the values for future use
- Multiple Options: Provide options to update files, copy commands, or skip
- Smart Updates: Preserve existing .env file structure and comments
# Auto-detect single user/org (default behavior)
pnpm seed-credentials
# Traditional manual selection (disable auto-detection)
pnpm seed-credentials -- --no-auto-detect
# Test mode with auto-detection
pnpm seed-credentials -- --test --auto-detectIf the initial database connection fails, the script will automatically:
- Check for
DATABASE_SECURE_EXTERNAL_URL: First looks for this environment variable containing a full PostgreSQL connection URL - Interactive Prompt: If not found, prompts you to enter a PostgreSQL URL manually
- Automatic Parsing: Parses the URL and extracts all connection parameters
- SSL Auto-Detection: Automatically enables SSL for cloud providers (Render, Railway, AWS, Google Cloud)
- Retry Connection: Attempts to connect with the parsed configuration
Supported PostgreSQL URL Format:
postgresql://username:password@host:port/database
postgres://username:password@host:port/database
Example:
postgresql://admin:mypassword@dpg-abc123.oregon-postgres.render.com/mydatabase
| Variable | Default | Description |
|---|---|---|
DATABASE_TYPE |
postgres |
Database type (currently supports PostgreSQL) |
DATABASE_HOST |
localhost |
Database host address |
DATABASE_PORT |
5432 |
Database port number |
DATABASE_USER |
postgres |
Database username |
DATABASE_PASSWORD |
postgres |
Database password |
DATABASE_NAME |
flowise |
Database name |
| Variable | Description |
|---|---|
DATABASE_SECURE_EXTERNAL_URL |
Full PostgreSQL URL (used if primary connection fails) |
DATABASE_SSL |
Enable SSL connection (true/false) |
| Variable | Default | Description |
|---|---|---|
FLOWISE_SECRETKEY_OVERWRITE |
theanswerencryptionkey |
Encryption key for credential data |
DATABASE_SEED_USER_ID |
null |
REQUIRED UUID of the user to associate credentials with |
DATABASE_SEED_ORG_ID |
null |
REQUIRED UUID of the organization to associate credentials with |
| Variable | Description |
|---|---|
TEST_MODE |
Set to true to run in test mode |
DEBUG_MODE |
Set to true to enable debug output |
AUTO_DETECT |
Set to true to enable auto-detection mode |
UPDATE_ENV |
Set to true to automatically update .env files |
| Option | Description |
|---|---|
--test |
Run in test mode (dry run, no database writes) |
--dry-run |
Alias for --test |
--debug |
Enable detailed debug output |
--auto-detect |
Enable smart auto-detection for local dev |
--update-env |
Automatically update .env files with values |
Important: DATABASE_SEED_USER_ID and DATABASE_SEED_ORG_ID must be valid UUIDs that exist in your database. The script will verify these exist and show you the associated user/organization details for safety.
Note: By default,
pnpm seed-credentialsruns in test mode. Usepnpm seed-credentials:writeto actually write to the database.
These credentials require a single environment variable:
| Environment Variable | Credential Name | Description |
|---|---|---|
AAI_DEFAULT_OPENAI_API_KEY |
openai-default |
OpenAI API key |
AAI_DEFAULT_ANTHROPHIC |
anthropic-default |
Anthropic API key |
AAI_DEFAULT_GROQ |
groq-default |
Groq API key |
AAI_DEFAULT_DEEPSEEK |
deepseek-default |
DeepSeek API key |
AAI_DEFAULT_EXASEARCH |
exasearch-default |
ExaSearch API key |
AAI_DEFAULT_REPLICATE |
replicate-default |
Replicate API key |
AAI_DEFAULT_SERPAPI |
serpapi-default |
SerpAPI key |
AAI_DEFAULT_PINCONE |
pinecone-default |
Pinecone API key |
AAI_DEFAULT_GITHUB_TOKEN |
github-default |
GitHub access token |
These credentials require multiple environment variables:
- Base:
AAI_DEFAULT_AWS_BEDROCK - Required Variables:
AAI_DEFAULT_AWS_BEDROCK_ACCESS_KEY- AWS Access KeyAAI_DEFAULT_AWS_BEDROCK_SECRET_KEY- AWS Secret Key
- Optional Variables:
AAI_DEFAULT_AWS_BEDROCK_SESSION_TOKEN- AWS Session Token
- Base:
AAI_DEFAULT_SUPABASE - Required Variables:
AAI_DEFAULT_SUPABASE_URL- Supabase project URLAAI_DEFAULT_SUPABASE_API- Supabase API key
- Base:
AAI_DEFAULT_GOOGLE_SEARCH_API - Required Variables:
AAI_DEFAULT_GOOGLE_SEARCH_API- Google API keyAAI_DEFAULT_GOOGLE_SEARCH_API_ENGINE_ID- Custom Search Engine ID
- Base:
AAI_DEFAULT_REDIS - Optional Variables (all have defaults):
AAI_DEFAULT_REDIS_HOST(default:localhost)AAI_DEFAULT_REDIS_PORT(default:6379)AAI_DEFAULT_REDIS_USERNAME(default:default)AAI_DEFAULT_REDIS_PASSWORD(default: empty)
The script can automatically detect unmapped AAI_DEFAULT_* variables by:
- Scanning the
components/credentials/directory for credential files - Matching environment variable names to credential file names
- Creating basic API key mappings for detected services
This feature is useful for adding new services without modifying the script configuration.
Before processing credentials, the script:
- Validates USER_ID and ORG_ID: Ensures they are properly formatted UUIDs
- Database Verification: Checks that the user and organization actually exist in the database
- Identity Display: Shows the actual user email/name and organization name for confirmation
- Safety Warnings: Alerts if credentials would be orphaned (no valid user/org assignment)
When running with --test or --dry-run:
- Read-Only Analysis: No changes are made to the database
- Credential Preview: Shows which credentials would be created or updated
- UUID Preservation: Displays existing credential UUIDs that would be preserved
- User/Org Lookup: Shows available users and organizations if verification fails
- Comprehensive Summary: Details exactly what would happen in production mode
The script uses a robust loading system with multiple fallback paths:
- Project Root:
../../.env(primary) - Project Root Local:
../../.env.local - Scripts Directory:
../.env(fallback) - Current Working Directory:
./.env - System Environment: Direct
process.envvariables (highest priority)
# Database Configuration (Primary)
DATABASE_TYPE=postgres
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USER=your_db_user
DATABASE_PASSWORD=your_db_password
DATABASE_NAME=flowise
# Database Connection Recovery (Fallback)
DATABASE_SECURE_EXTERNAL_URL=postgresql://user:pass@host.render.com/database
DATABASE_SSL=true
# Security
FLOWISE_SECRETKEY_OVERWRITE=your-secret-encryption-key
# REQUIRED: User/Org Association (must exist in database)
DATABASE_SEED_USER_ID=123e4567-e89b-12d3-a456-426614174000
DATABASE_SEED_ORG_ID=987fcdeb-51c2-43d1-9f4a-123456789abc
# Script Control
TEST_MODE=false
DEBUG_MODE=false
# Direct API Keys
AAI_DEFAULT_OPENAI_API_KEY=sk-your-openai-key
AAI_DEFAULT_ANTHROPHIC=your-anthropic-key
AAI_DEFAULT_GROQ=your-groq-key
AAI_DEFAULT_DEEPSEEK=your-deepseek-key
AAI_DEFAULT_EXASEARCH=your-exasearch-key
AAI_DEFAULT_REPLICATE=your-replicate-key
AAI_DEFAULT_SERPAPI=your-serpapi-key
AAI_DEFAULT_PINECONE=your-pinecone-key
AAI_DEFAULT_GITHUB_TOKEN=your-github-token
AAI_DEFAULT_BRAVE_SEARCH=your-brave-search-key
# Multi-field Credentials
AAI_DEFAULT_AWS_BEDROCK_ACCESS_KEY=your-aws-access-key
AAI_DEFAULT_AWS_BEDROCK_SECRET_KEY=your-aws-secret-key
AAI_DEFAULT_AWS_BEDROCK_SESSION_TOKEN=your-aws-session-token
AAI_DEFAULT_SUPABASE_URL=https://your-project.supabase.co
AAI_DEFAULT_SUPABASE_API=your-supabase-key
AAI_DEFAULT_GOOGLE_SEARCH_API=your-google-api-key
AAI_DEFAULT_GOOGLE_SEARCH_API_ENGINE_ID=your-search-engine-id
# Optional Redis Configuration
AAI_DEFAULT_REDIS_HOST=redis.example.com
AAI_DEFAULT_REDIS_PORT=6380
AAI_DEFAULT_REDIS_USERNAME=your-redis-user
AAI_DEFAULT_REDIS_PASSWORD=your-redis-password- Environment Loading: Loads environment variables with multiple fallback paths
- Debug Output (if
--debug): Shows environment variable loading details - Environment Scanning: Finds all
AAI_DEFAULT_*variables - Credential Mapping: Groups related variables and maps them to credential configurations
- Auto-Detection: Attempts to detect unmapped credentials
- Database Connection: Connects with automatic retry and recovery:
- Attempts connection with configured settings
- On failure, checks
DATABASE_SECURE_EXTERNAL_URL - If not found, prompts for PostgreSQL URL interactively
- Parses URL and enables SSL for cloud providers
- User/Organization Verification: Validates and displays user/org details
- Safety Checks: Ensures USER_ID and ORG_ID exist in database
- Table Verification: Ensures the credential table exists
- Credential Processing: For each credential:
- Test Mode: Shows what would be done without making changes
- Production Mode: Updates existing or creates new credentials
- Preserves existing UUIDs when updating
- Encrypts credential data using Flowise encryption
- Summary Report: Displays comprehensive results
- Read-Only: No database modifications
- Analysis: Shows existing credentials and what would be created/updated
- Safety: Displays available users/orgs if verification fails
- Preview: Shows exact UUIDs that would be preserved
- Summary: Detailed breakdown of planned changes
- Write Operations: Actually creates/updates credentials in database
- UUID Preservation: Updates existing credentials without changing UUIDs
- New Credentials: Creates new credentials with fresh UUIDs
- Encryption: Uses Flowise-compatible encryption for all credential data
The script provides comprehensive logging including:
- Environment variable loading source
- Database connection information with credential ownership details
- User and organization verification results
- Number of AAI_DEFAULT variables found
- Credential mapping and auto-detection results
- Detailed analysis of each credential (existing vs new)
- Existing credential UUIDs and timestamps
- Field counts and names for each credential
- Available users and organizations (if verification fails)
- Real-time credential creation/update status
- New credential UUIDs
- Success/failure counts with detailed summaries
- Environment variable loading paths attempted
- Database configuration values (passwords masked)
- Complete list of AAI_DEFAULT variables found
- Database Connection: Intelligent recovery with URL prompting
- SSL Requirements: Automatic SSL detection for cloud providers
- User/Org Validation: Comprehensive verification with helpful error messages
- Invalid UUIDs: Clear error messages with correction guidance
- Missing Required Variables: Detailed warnings with field information
- Credential Conflicts: Safe updating that preserves existing UUIDs
- Auto-Detection Failures: Graceful handling with detailed logging
- Environment Loading: Multiple fallback paths with clear status reporting
- Encryption: All credential data is encrypted using the same method as the Flowise server
- Environment Variables: Store sensitive data in environment variables, not in code
- Database Access: Ensure database credentials are properly secured
- Credential Visibility: All created credentials default to 'Private' visibility
-
Database Connection Failed
Solution: The script now handles this automatically!
- First checks for
DATABASE_SECURE_EXTERNAL_URLenvironment variable - If not found, prompts you to enter a PostgreSQL URL interactively
- Automatically detects and enables SSL for cloud providers
- Example URL:
postgresql://user:pass@host.render.com/database
- First checks for
-
SSL/TLS Required Errors
Automatic Resolution: The script detects cloud providers and enables SSL automatically
- Render:
*.render.comdomains get SSL automatically - Railway:
*.railway.appdomains get SSL automatically - AWS:
*.aws.comdomains get SSL automatically - Manual override: Set
DATABASE_SSL=trueenvironment variable
- Render:
-
USER_ID/ORG_ID Validation Errors
Enhanced Error Messages: The script now provides detailed guidance
- Validates UUID format automatically
- Checks that user/organization exists in database
- Shows actual user email/name and organization details
- In test mode: Displays available users/organizations to choose from
Example Fix:
# Run in test mode to see available options node scripts/seed-credentials/seed-credentials.js --test # Copy the correct UUIDs from the output export DATABASE_SEED_USER_ID="valid-uuid-from-database" export DATABASE_SEED_ORG_ID="valid-uuid-from-database"
-
Missing Credentials/Environment Variables
Enhanced Detection:
- Run with
--debugto see exactly which variables are loaded - Shows loading source (which .env file was used)
- Lists all AAI_DEFAULT variables found
- Displays field mappings for each credential type
- Run with
-
Permission Errors
- Ensure database user has CREATE/INSERT/UPDATE permissions
- Verify database user can access the
credential,user, andorganizationtables - Check that the user can create tables if the credential table doesn't exist
-
Credential Conflicts or Duplicates
Safe Handling: The script now handles this intelligently
- Preserves existing credential UUIDs when updating
- Shows what would be updated vs created in test mode
- Maintains compatibility with existing Flowise flows
# See what would be changed without making modifications
pnpm seed-credentials
# OR
node scripts/seed-credentials/seed-credentials.js --test
# Shows:
# - Which credentials would be created vs updated
# - Existing credential UUIDs that would be preserved
# - User/organization verification results
# - Available users/orgs if verification fails# See detailed environment variable loading
pnpm seed-credentials -- --debug
# OR
node scripts/seed-credentials/seed-credentials.js --debug
# Shows:
# - Which .env file was loaded (or if using system env vars)
# - All database configuration values (passwords masked)
# - Complete list of AAI_DEFAULT variables found
# - Environment variable loading attempts and results# Get maximum visibility into what's happening
pnpm seed-credentials -- --debug
# OR
node scripts/seed-credentials/seed-credentials.js --test --debugThe script uses multiple fallback paths for .env files:
- Project Root:
<project-root>/.env(primary) - Project Root Local:
<project-root>/.env.local - Scripts Directory:
<project-root>/scripts/.env(legacy fallback) - Current Directory:
./.env - System Environment: Direct environment variables (highest priority)
Check Loading:
# See which .env file is being used
node scripts/seed-credentials/seed-credentials.js --debug | grep "Loading environment"Supported Formats:
postgresql://username:password@host:port/database
postgres://username:password@host:port/database
Common Mistakes:
- Missing protocol: Should start with
postgresql://orpostgres:// - URL encoding: Special characters in passwords may need URL encoding
- Port specification: Include port even if it's the default (5432)
Testing Your URL:
# Set the URL and test the connection
export DATABASE_SECURE_EXTERNAL_URL="postgresql://user:pass@host:port/db"
node scripts/seed-credentials/seed-credentials.js --testTo add support for a new single API key service:
AAI_DEFAULT_YOUR_SERVICE: {
name: 'your-service-default',
credentialName: 'yourServiceApi',
mapFn: (value) => ({ yourServiceApiKey: value })
}For services requiring multiple configuration values:
AAI_DEFAULT_YOUR_SERVICE: {
name: 'your-service-default',
credentialName: 'yourServiceApi',
requiredVars: ['FIELD1', 'FIELD2'],
optionalVars: ['OPTIONAL_FIELD'],
mapFn: (vars) => ({
yourServiceField1: vars['FIELD1'],
yourServiceField2: vars['FIELD2'],
yourServiceOptional: vars['OPTIONAL_FIELD']
})
}The script requires the following npm packages:
typeorm- Database ORM for PostgreSQL connectionsdotenv- Environment variable loading with fallback supportcrypto-js- Encryption functionality (Flowise-compatible)node:path,node:fs,node:crypto,node:readline- Node.js built-in modules
Built-in Node.js modules used:
node:readline- Interactive user prompts for database URL recoverynode:path- File path resolution for .env file fallbacksnode:fs- File system access for credential auto-detectionnode:crypto- Additional cryptographic operations
Make sure the npm packages are installed in your project:
# Install required dependencies
npm install typeorm dotenv crypto-js
# Or with pnpm
pnpm install typeorm dotenv crypto-jsNote: Node.js built-in modules don't need to be installed separately.