đ Building AI Automation Workflows with n8n & OpenAI
Ever wished you could get a chatbot to write your commit messages while youâre sipping a cold brew?
Youâre not alone. In this article weâll walk through how to glue n8n (the openâsource workflow engine) together with OpenAIâs API to create smart, reusable automations. No heavyâweight infra, just a few clicks, a sprinkle of JavaScript, and a lot of fun. đ
đŻ Why Combine n8n + OpenAI?
- Zeroâcode UI â Design flows visually, then drop in a tiny code node when you need custom logic.
- Scalable â Run locally, on Docker, or in the cloud; n8n handles the orchestration, OpenAI does the heavy AI lifting.
- Reusable â Once youâve built a âGenerate commit messageâ workflow, you can call it from any repo, CI pipeline, or Slack bot.
Think of n8n as the conductor and OpenAI as the soloist. Letâs get them to jam together.
đ ď¸ Prerequisites
| What you need | Why |
|---|---|
| n8n (Docker or selfâhosted) | To create and run the workflow |
| OpenAI API key | To talk to GPTâ4/3.5 |
| Node.js (optional) | For local testing of the JS code node |
| A Git repo (any language) | To see the automation in action |
If you already have n8n running, skip the Docker step; otherwise:
# Quick start with Docker
docker run -d \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
n8nio/n8n
Open http://localhost:5678 in your browser and youâre ready to roll.
đ StepâbyâStep: âAIâPowered Commit Message Generatorâ
1ď¸âŁ Create a New Workflow
- Click + New Workflow.
- Rename it to
Generate Commit Message. - Drag a Webhook node onto the canvas â this will be the entry point.
2ď¸âŁ Capture the Diff
Add a GitHub node (or a simple HTTP Request node if you prefer raw Git).
Configure it to fetch the latest diff:
{
"method": "GET",
"url": "https://api.github.com/repos/{{ $json.owner }}/{{ $json.repo }}/commits/{{ $json.sha }}/diff",
"headers": {
"Authorization": "Bearer {{ $credentials.githubApiKey }}"
}
}
Tip: If youâre using a private repo, store the token in Credentials â API Key to keep it out of the workflow JSON.
3ď¸âŁ Call OpenAI
Drop a HTTP Request node after the diff node. Set it to POST https://api.openai.com/v1/chat/completions with these headers:
| Header | Value |
|---|---|
Authorization |
Bearer YOUR_OPENAI_API_KEY |
Content-Type |
application/json |
Body (JSON):
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant that writes concise, conventional commit messages."
},
{
"role": "user",
"content": "Here is a git diff:\n{{ $json.diff }}\nWrite a commit message (max 50 chars)."
}
],
"temperature": 0.2,
"max_tokens": 60
}
n8n will replace {{ $json.diff }} with the diff you fetched earlier.
4ď¸âŁ Parse the Response
Add a Set node to extract the generated message:
{
"commitMessage": "={{ $json.choices[0].message.content.trim() }}"
}
5ď¸âŁ Push the Commit (optional)
If you want the workflow to automatically commit, add another GitHub node:
-
Operation:
Create Commit -
Message:
{{ $json.commitMessage }} -
Branch:
{{ $json.branch }}
â ď¸ Caution: Autoâcommitting is powerful but can be risky. Consider gating it behind a PR review or a Slack approval step.
6ď¸âŁ Respond to the Caller
Finally, attach a Return node to the webhook so the caller (e.g., your CI job) gets the message back:
{
"status": "success",
"commitMessage": "{{ $json.commitMessage }}"
}
đ§Š Bonus: Add a âHuman in the Loopâ Slack Prompt
Sometimes you want a quick sanity check before the commit lands. Insert a Slack node after the OpenAI step:
-
Send Message â channel
#devâops - Text:
AI suggests: *{{ $json.commitMessage }}* â approve? (yes/no)
Then add a Wait for Trigger node that listens for a reply. If the reply is yes, continue to the GitHub commit node; otherwise, abort.
đ Tips & Tricks
- Cache diffs â Use the Cache node to avoid hitting the GitHub API multiple times in the same workflow run.
-
Prompt engineering â Adding a few examples in the system prompt (e.g.,
"feat: add login flow"â"Added login flow") dramatically improves output quality. - Rate limits â OpenAIâs free tier is generous, but add a Rate Limit node if you expect many CI calls.
-
Environment variables â Store
OPENAI_API_KEYandGITHUB_TOKENin the Environment section of n8n for easier rotation. - Debugging â Turn on Execution Mode â Manual and hit Run to see each nodeâs output in the UI.
đ WrapâUp
You now have a fully functional AIâpowered workflow that:
- Receives a webhook (or CI trigger).
- Pulls the latest code diff.
- Lets GPTâ4 craft a conventional commit message.
- Optionally asks for human approval.
- Commits the change back to GitHub.
The beauty of n8n is that you can clone this pattern for any repetitive dev taskâautoâgenerated documentation, issue triage, even code review summaries. The skyâs the limit when you pair a flexible orchestrator with a powerful LLM. đ
What will you automate next? Drop a comment below, share your workflow JSON, or ask for help tweaking the prompt. Letâs build the future of developer productivity together!
References
- n8n Docs â Workflow Nodes
- OpenAI API â Chat Completion
- Conventional Commits â specification
Happy automating! đ
Top comments (0)