n8n and OpenAI API: Creating Simple Text Processing Automations
When it comes to automating text processing tasks, you have two solid options: use OpenAI’s API directly, or go through a service like OpenRouter that offers OpenAI-compatible models. Both approaches are valid, but in this article, we’ll focus on using OpenRouter to handle our text automation tasks.
Why OpenRouter?
Because it simplifies API management, provides a stable gateway to OpenAI models, and offers better flexibility in handling multiple model endpoints — especially useful in production or large-scale automation setups.
As a practical example, we’ll build an automation that automatically fetches and summarizes a long-form essay by Paul Graham, turning it into a concise summary without manual effort.
large-scale automation setups.
What Is n8n?
n8n is a free, open-source automation tool that lets you visually build workflows across APIs and services. It removes the hassle of custom integration development, letting you focus on solving problems and automating processes instead of writing boilerplate code.
OpenAI API vs. OpenRouter API
-
OpenAI API Directly:
You can integrate directly with OpenAI’s endpoints, but that requires managing API keys, rate limits, and keeping track of model versions yourself. -
OpenRouter API:
Acts as a unified gateway to OpenAI-compatible models with simplified configuration.
Easier key management Access to multiple models via a single platform Better for scaling automations without worrying about individual API changes
In this article, we’ll use the OpenRouter API for our example automation.
Index
- Set Up n8n
- Get OpenRouter API Access
- N8N Automation Flow
- Manual Trigger
- Fetch Essay List
- Extract Essay Names
- Split into Individual items
- Limit to First 3 Essays
- Fetch Essay Text
- Extract Title and Content
- Summarize with Openrouter LLM
- Merge Data
- Clean up Output
- Why OpenRouter Make Sense
- Next Steps You Can Take
- Watch Out For
- Interesting Facts
- FAQ
- Conclusion
Building a Simple Text Automation with n8n + OpenRouter
1. Set Up n8n
- Install n8n from https://n8n.io/ or use Docker.
- Open the n8n editor UI in your browser.
- Another way is to clone the repo git clone https://github.com/n8n-io/n8n.git
“Automation applied to an efficient operation will magnify the efficiency.” — Bill Gates
2. Get OpenRouter API Access
1. Create an OpenRouter Account
- Visit https://openrouter.ai/?utm_source=chatgpt.com.
- Click on “Sign Up” to create a new account. You can sign up using your Google, GitHub, or MetaMask credentials.
2. Generate Your API Key
- After logging in, navigate to the API Keys section in your account settings.
- Click on “Create New Key”.
- Provide a descriptive name for your API key (e.g., “n8n Text Automation”).
- Optionally, set a credit limit for the key to manage usage.
- Click “Create Key” to generate your API key.
- Important: Copy and securely store your API key, as it will not be displayed again.
- Generate your API key.
3. N8N Automation Flow
- Create N8N account
Automation Flow
Step 1: Manual Trigger — Start the Workflow
The workflow starts when you manually trigger it by clicking “Execute Workflow” in the n8n editor.
- This simulates an external trigger but could later be replaced by a real Webhook for production use.
- It passes a single item to the next step.
Step 2: Fetch Essay List (HTTP Request)
The automation makes an HTTP GET request to fetch the list of essays.
To demonstrate real-world use, we use a long-form essay by Paul Graham as input.
- Request URL:
http://www.paulgraham.com/articles.html
- The response is raw HTML containing links to all essays on Paul Graham’s website.
Step 3: Extract Essay Names (HTML Extract)
The HTML content is parsed to extract the essay titles and URLs.
- The system applies CSS selectors to pick out essay names and links from the HTML.
- The result is a list of essay metadata items (title + URL).
Step 4: Split Into Individual Items
The full list of essays is split into individual items.
- If 234 essays are found, this step turns them into 234 separate items for independent processing.
Step 5: Limit to First 3 Essays
To keep testing efficient and avoid overloading the system, we limit the process to the first 3 essays.
- This reduces the number of items from 234 to just 3.
- Each of the three items now contains metadata of a single essay.
Step 6: Fetch Essay Texts (HTTP Request)
For each of the 3 essay URLs, a separate HTTP GET request is made.
- The raw HTML content of each individual essay is retrieved.
- Each item now holds the full essay HTML content.
Step 7: Extract Title and Text Content (HTML Extract)
Each essay undergoes two extraction steps in parallel:
-
Extract Title
Extracts just the essay’s title from its HTML. -
Extract Text Only
Extracts the main essay body text from the HTML.
This results in three pairs of structured data per essay:
- Title
- Clean essay text
Step 8: Summarize with OpenRouter GPT (Basic LLM Chain)
Each essay’s clean text is sent to the OpenRouter Chat Model node using a predefined LLM chain.
- The model summarizes the essay text.
- Inputs:
- System prompt: “You are an expert text summarizer.”
- User input: The extracted essay text.
This outputs a summary for each essay.
Step 9: Merge Data
After summarization, the results are merged.
- The extracted title and generated summary are combined into one cohesive structure.
Each item now contains:
{
"title": "Hackers and Painters",
"summary": "Paul Graham explains how the creative process of hackers is similar to that of painters..."
}
Step 10: Clean Up Output
Finally, a Set node is used to format the output cleanly.
- Removes unnecessary metadata or intermediate fields.
- Ensures only the relevant title and summary fields are in the final output.
Final Output Example
[
{
"title": "Hackers and Painters",
"summary": "Paul Graham explains how the creative process of hackers is similar to that of painters, emphasizing the importance of innovation, original ideas, and doing work that matters."
},
{
"title": "Another Essay Title",
"summary": "This essay discusses..."
},
{
"title": "Third Essay Title",
"summary": "In this piece, Paul Graham explains..."
}
]
“The future of AI is not about replacing humans, it’s about augmenting human capabilities.” — Sundar Pichai
4. Why OpenRouter Makes Sense
- No need to manage multiple API endpoints manually.
- Provides a stable layer between you and OpenAI models.
- Easier scaling and maintenance for automation workflows.
- Simplified key and model version management.
5. Next Steps You can Take
- Automate bulk document summarization.
- Trigger workflows based on events (e.g., new email, file upload).
- Store summaries in databases or send them via Slack or email.
6. Watch Out For
- API Rate Limits: OpenRouter usage depends on your subscription plan.
- Input Size Limits: Keep inputs reasonable (a few KB).
- Secure Your API Key: Use environment variables instead of hard-coding.
7. Interesting Facts
-
LLMs like OpenAI’s GPT models can automate up to 10–20% of tasks across most knowledge jobs, freeing time for higher-value work. Source
-
AI-powered tools boost productivity by 12–25% in content, coding, and translation tasks, according to multiple OpenAI and academic studies.Source
-
Automation driven by AI could lift global productivity by up to 1.4% annually, accelerating digital transformation across industries. Source
-
Frontier models process complex work 100× faster and cheaper than traditional methods in controlled benchmarks.Source
“There’s a lot of automation that can happen that isn’t a replacement of humans, but of mind-numbing behavior.” — Stewart Butterfield
8. FAQ
1. Do I need coding knowledge to build this n8n + OpenRouter automation?
No. n8n provides a visual interface, so you can create and connect workflow nodes without writing code. You only need basic familiarity with APIs and request parameters.
2. Can I use the official OpenAI API instead of OpenRouter?
Yes, but OpenRouter offers more flexibility — it supports multiple OpenAI-compatible models and simplifies key management for production environments.
3. What models can I use with OpenRouter?
You can access GPT-3.5, GPT-4, Claude, Mistral, and many other top-performing models through a single API key.
4. Is there a cost to use n8n?
The self-hosted version of n8n is free and open-source. However, using OpenRouter or OpenAI APIs will incur usage-based costs depending on your selected model.
5. Can I trigger this workflow automatically?
Yes. You can replace the manual trigger with a webhook, schedule, or event-based trigger — for example, fetching text from an RSS feed or email automatically.
6. How secure is my OpenRouter API key in n8n?
Keep it safe by storing it as an environment variable or in n8n’s credentials system. Avoid hardcoding it in workflow nodes.
7. Can this setup summarize other types of text, like blog posts or reports?
Absolutely. You can connect it to any data source — files, URLs, or APIs — to summarize, clean, or classify text.
9. Conclusion
Whether you choose to work directly with OpenAI API or OpenRouter, automating text processing becomes easier with n8n. For most use cases, OpenRouter offers better scalability, flexibility, and simplicity – especially when you’re integrating multiple automations.
About the Author: Ankit is a full-stack developer at AddWebSolution and AI enthusiast who crafts intelligent web solutions with PHP, Laravel, and modern frontend tools.