AI-Powered Short Link Generator and Manager - n8n Workflow

Leverage this advanced n8n workflow to create a dynamic short link service using an AI agent (GPT-4.1-mini) that saves URLs to an n8n Data Table and automatically handles all redirects.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Developers looking for robust n8n templates for advanced use cases.
Users who need an internal, self-hosted short link service without external dependencies.
Teams wanting to leverage natural language processing (via an AI agent) to interact with infrastructure tasks.
n8n automation specialists seeking examples of complex, multi-path n8n workflows.

Overview

This comprehensive n8n workflow provides a full-stack solution for generating, storing, and managing short links. It solves the common problem of needing a quick, reliable URL shortener while leveraging the power of an AI Agent for interaction.

The automation is split into three main parts: the AI conversational interface, the link creation tool, and the redirect service. By using the specialized n8n node types for AI agents (specifically connecting to an OpenAI Chat Model like GPT-4.1-mini), users can simply tell the agent to create a short link, and the agent automatically calls the necessary workflow tool. All data is securely stored within an n8n Data Table, making this a highly integrated and private solution. This is a prime example of complex, functional n8n automation in action.

How it Works

This powerful n8n workflow operates across three parallel processing paths:


  1. AI Interaction Path: The process begins with the When chat message received n8n trigger. This activates the AI Agent n8n node, which uses the OpenAI Chat Model and Simple Memory for conversation. The agent is configured with a specialized tool called Call 'Create Short Link'. When the user requests a short link, the AI agent uses its reasoning capabilities to extract the originalLink and calls this tool.


  1. Short Link Creation Path (Tool Execution): The Call 'Create Short Link' tool executes a section of the same n8n workflow. It is initiated by the GenerateShortLink n8n node (an Execute Workflow Trigger).

First, a Config n8n node sets the base yourwebhookurl.
Next, a Code n8n node generates a unique, 4-character random shortlinkId.
The Insert row n8n node saves both the originalLink and the new shortlinkId into the designated ShortLink Data Table.
Finally, the Generate ShortLink Code n8n node constructs the full shortened URL by combining the webhook URL and the unique ID, returning this short link back to the AI Agent.


  1. Short Link Redirect Path (API): When a user clicks on the generated short link, it hits the ShortLink API n8n trigger (a Webhook node at the /shortLink path).

The webhook extracts the shortlinkId from the URL query parameter (a).
The Get row(s) Data Table n8n node uses this ID to look up and retrieve the stored originalLink.
The Page Redirect HTML n8n node generates a standard HTML redirect page.
The Response n8n node sends this redirect HTML back to the browser, successfully forwarding the user to the original destination.

Installation Guide

To deploy this comprehensive n8n workflow, follow these steps:


  1. Import the n8n workflow: Copy the provided JSON and import it directly into your n8n instance.

  2. OpenAI Credentials: Ensure you have configured the OpenAI Chat Model n8n node with valid credentials for your OpenAI account.

  3. Data Table Setup: Create an n8n Data Table named ShortLink with the following two columns:

originalLink (Type: string)
shortLinkId (Type: string)

  1. Configure Webhook URL: The workflow relies on knowing its own external URL. In the Config n8n node, replace the placeholder value (http://localhost:5678) with the base URL of your publicly accessible n8n instance (e.g., https://my-n8n.com).

  2. Activate n8n triggers: Ensure both the When chat message received n8n trigger and the ShortLink API n8n trigger are active to begin generating and managing links.

Node Details

When chat message received (n8n trigger): The starting point for the AI path. It listens for incoming chat messages to initiate the short link creation process.
AI Agent (n8n node): Orchestrates the conversation and tool usage. It connects the Language Model (OpenAI) and the custom tool (Call 'Create Short Link') to perform the requested action.
OpenAI Chat Model (n8n node): Provides the intelligence for the agent, using the 'gpt-4.1-mini' model for fast and accurate reasoning.
Call 'Create Short Link' (n8n node): A specialized tool n8n node that allows the AI to execute the defined link creation sub-workflow, passing the required originalLink parameter.
GenerateShortLink (n8n trigger/node): Acts as the entry point for the internal tool workflow, receiving data from the AI Agent.
Generate shorlinkId (Code n8n node): Generates a random, 4-character alphanumeric string used as the unique identifier for the short link.
Insert row (Data Table n8n node): The persistence layer. It stores the relationship between the originalLink and the generated shortlinkId in the ShortLink Data Table.
ShortLink API (Webhook n8n trigger): The API endpoint that handles incoming short link clicks. It listens on the path /shortLink and triggers the redirect logic.
Get row(s) (Data Table n8n node): Retrieves the full originalLink from the Data Table by matching the received shortlinkId query parameter.
Page Redirect (HTML n8n node): Generates the necessary HTML structure to perform an immediate client-side redirect to the stored original URL.

Related n8n Workflows

Free

Nodes: 13 Nodes
Updated: December 26 2025
View all
Created by

I am Nguyen Trung Nghia, a Software Engineer passionate about AI Automation. I build intelligent automation systems that help businesses reduce costs, increase productivity, and scale faster with the power of AI technology.

Featured*