N8N LLM Workflow Bulk Updater
August 10, 2025 Β· View on GitHub
With the rapid pace of AI evolution, new language models are being released at an unprecedented rate. A common challenge for automation enthusiasts and businesses is: what happens when you have a large number of workflows or automations configured with one model, and you want to update them to use its successor?
This script was created to solve exactly that problem. When OpenAI recently released GPT-5 Mini, I found myself needing to update dozens of N8N workflows that were still using GPT-4.1 Mini. Rather than manually editing each workflow, this Python script programmatically updates model references by interacting directly with the N8N API.
The script performs bulk updates across all your N8N workflows, automatically finding and replacing old OpenRouter model IDs with newer ones - saving hours of manual work and ensuring consistency across your automation infrastructure.
Features
- Bulk Model Updates: Updates multiple OpenRouter model IDs across all workflows
- Dry Run Mode: Preview changes before applying (default)
- Cloudflare Support: Works with N8N instances behind Cloudflare Access
- Rich Console Output: Beautiful progress tracking and reporting
- Safe Operations: Confirmation prompts and error handling
Model Replacement
Replaces these OpenRouter model IDs:
openai/gpt-3.5-turboopenai/gpt-4o-miniopenai/gpt-4.1-miniopenai/gpt-4.1-nano
With: openai/gpt-5-mini
Quick Start
- Clone and install:
git clone <repo-url>
cd N8N-LLM-Workflow-Bulk-Updater
pip install -r requirements.txt
- Configure
.env:
cp .env.example .env
# Edit .env with your N8N details
- Run (dry run first):
python bulk_updater.py # Preview changes
python bulk_updater.py --live # Apply changes
Configuration
Environment Variables
Create a .env file with the following required variables:
# N8N API Configuration
N8N_API_KEY=your_n8n_api_key_here
N8N_BASE_URL=your_n8n_instance_url_here
# Cloudflare Access Headers (if using Cloudflare authentication)
CF_ACCESS_CLIENT_ID=your_cf_client_id_here
CF_ACCESS_CLIENT_SECRET=your_cf_client_secret_here
# Model Configuration
NEW_MODEL_ID=openai/gpt-5-mini
Getting Your N8N API Key
- Log into your N8N instance
- Go to Settings β Personal β API Keys
- Click Create API Key
- Copy the generated key to your
.envfile
Note: N8N uses a custom header format X-N8N-API-KEY (not standard Bearer tokens).
Usage Examples
Preview Changes (Dry Run)
python bulk_updater.py
Sample Output:
π Starting bulk update: openai/gpt-3.5-turbo, openai/gpt-4o-mini, openai/gpt-4.1-mini, openai/gpt-4.1-nano β openai/gpt-5-mini
π Target instance: https://n8n.example.com
β
Successfully connected to N8N API
π Found 86 workflows
Workflows to Update
ββββββββββββββββ³βββββββββββββββ³βββββββββ³ββββββββββββββ
β Name β ID β Active β Models Foundβ
β‘βββββββββββββββββββββββββββββββββββββββββββββββββββββ©
β My Workflow β abc123... β Yes β openai/gptβ¦ β
ββββββββββββββββ΄βββββββββββββββ΄βββββββββ΄ββββββββββββββ
π Found 1 workflows to update
π DRY RUN COMPLETE - Use --live to apply changes
Apply Changes
python bulk_updater.py --live
Override Target Model
python bulk_updater.py --new-model "openai/gpt-4o" --live
How It Works
- Connects to your N8N instance using the API key
- Fetches all workflows from your instance
- Scans each workflow for old OpenRouter model IDs
- Replaces found model IDs with the new target model
- Updates workflows back to N8N with minimal required fields
The script performs a simple find-and-replace operation on the workflow JSON, ensuring all references to old models are updated to the new one.
Troubleshooting
401 Unauthorized Error
- Cause: Invalid or missing N8N API key
- Solution:
- Verify your API key is correct in
.env - Ensure the API key hasn't expired
- Check that you have proper permissions in N8N
- Verify your API key is correct in
Connection Issues
- Cause: Network connectivity or Cloudflare configuration
- Solution:
- Test your N8N instance URL in a browser
- If using Cloudflare Access, verify your client ID and secret
- Check if your N8N instance is accessible from your current network
400 Bad Request Error
- Cause: Invalid workflow data or API payload
- Solution: This is usually handled automatically by the script's payload formatting
No Workflows Found
- Cause: No workflows contain the target model IDs
- Solution: This is normal if you've already updated all workflows or don't use the specified models
Security Notes
- API Keys: Never commit your
.envfile to version control - Cloudflare Headers: Keep CF access credentials secure
- Private Directory: The
private/folder is gitignored for additional secrets
File Structure
N8N-LLM-Workflow-Bulk-Updater/
βββ bulk_updater.py # Main script
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
βββ .env # Your secrets (gitignored)
βββ .gitignore # Git ignore rules
βββ model-replacement.md # Model mapping documentation
βββ README.md # This file
βββ private/ # Private files (gitignored)
βββ secrets/
βββ secrets.txt