🔓 Unlock all 10,000+ workflows & prompts free Join Newsletter →
✅ Full access unlocked — explore all 10,000 AI workflow and prompt templates Browse Templates →
Home n8n Workflow
January 22, 2026

OpenAI + Pexels: publish ready drafts with images

Lisa Granqvist Partner Workflow Automation Expert

You start with a simple topic. Then you bounce between ChatGPT, stock photo sites, a doc, maybe a CMS, and a pile of tabs you swear you’ll close later. Somewhere in that shuffle, formatting breaks, the image doesn’t match the angle, and the “quick draft” turns into a mini project.

Marketing managers feel this when content calendars get tight. Agency owners feel it when clients expect speed plus polish. And if you’re a solo founder writing on weekends, this OpenAI Pexels automation is basically a survival tool. The outcome is simple: publish-ready HTML drafts with a relevant hero image, generated from one prompt.

This workflow turns a topic into a draft, extracts image keywords from the draft, pulls a matching royalty-free photo from Pexels, then outputs clean HTML you can paste and publish.

How This Automation Works

See how this solves the problem:

n8n Workflow Template: OpenAI + Pexels: publish ready drafts with images

The Challenge: Turning topics into publishable posts (fast)

Drafting content is rarely the hard part. Finishing it is. You write a decent first version, then you hunt for an image that doesn’t look like generic stock, then you rewrite the intro so the image makes sense, then you clean up headings and links so it won’t look messy after pasting into your CMS. If you’re doing this more than once a week, the context switching becomes the real cost. And honestly, it’s easy to lose consistency when every draft is assembled by hand.

The friction compounds. Here’s where it breaks down in day-to-day work.

  • You end up copying text between tools, and small formatting issues sneak in every time.
  • Image selection becomes a time sink because you’re guessing keywords instead of using the content’s actual context.
  • Drafts stay “almost done” since the last 10 minutes (HTML cleanup and layout) never feels worth starting.
  • When you batch content, quality drifts because you’re rushing the repetitive steps, not the ideas.

The Fix: OpenAI drafts with automatic Pexels image matching

This workflow starts with a topic you enter through a simple form trigger in n8n. OpenAI generates an initial draft based on that topic, then a second OpenAI step derives image keywords from what was actually written (not what you think it might need). Those keywords get sent to the Pexels API to fetch a relevant, royalty-free image. Finally, OpenAI produces a polished version of the content that fits the chosen visual, and n8n composes everything into a clean HTML template. What you get at the end is straightforward: a publish-ready draft with a matching hero image, displayed as HTML so you can paste it into WordPress or your editor of choice.

The workflow begins at the Form Input Trigger, moves through OpenAI for drafting and keyword extraction, then uses an HTTP Request to query Pexels. It finishes by assembling the final HTML and showing it in the output view for quick copy/paste.

What Changes: Before vs. After

Real-World Impact

Say you publish 3 posts a week. Manually, a rough draft (30 minutes), image hunt (20 minutes), and formatting/cleanup (20 minutes) lands around 70 minutes per post, or about 3.5 hours weekly. With this workflow, you spend maybe 5 minutes entering topics and skimming the output, then let OpenAI + Pexels do the heavy lifting while n8n assembles the HTML. You still review before publishing, but you’re reviewing something complete, not stitching it together.

Requirements

  • n8n instance (try n8n Cloud free)
  • Self-hosting option if you prefer (Hostinger works well)
  • OpenAI to generate drafts and image keywords.
  • Pexels API to fetch matching royalty-free images.
  • OpenAI API key (get it from the OpenAI API dashboard).
  • Pexels API key (get it from your Pexels API account page).

Skill level: Beginner. You’ll connect API keys, paste a couple values, and test with a sample topic.

Need help implementing this? Talk to an automation expert (free 15-minute consultation).

The Workflow Flow

You submit a topic through a form. The workflow uses a Form Trigger as the starting point, so you can enter “Topic: X” and run it without any extra setup. If you prefer, this can be swapped later for a webhook or a Google Sheet row.

OpenAI generates a draft and derives an image keyword. One OpenAI step creates the initial content, then another extracts keywords that represent what the post is truly about. There’s also an optional “unified” AI step plus a small code parser, which can reduce token usage by doing more in one pass.

Pexels is searched using the derived keyword. n8n sends an HTTP request to the Pexels API, pulls back a relevant photo result, and passes the image details forward. Pexels has a free tier (at time of writing it’s about 200 requests per hour), which is plenty for many small teams.

The workflow composes clean HTML output. OpenAI produces the final polished copy that matches the selected image, and the HTML node displays a ready-to-paste layout combining image and content.

You can easily modify the HTML template to match your blog layout or switch the output to Markdown based on your needs. See the full implementation guide below for customization options.

Step-by-Step Implementation Guide

Step 1: Configure the Form Trigger

Set up the form that collects user inputs to start the workflow.

  1. Add and open Form Input Trigger.
  2. Set Form Title to AI Content Generator.
  3. Confirm the form fields: Topic or Keyword, Content Type (Blog Post/Social Media Post/Landing Page/Email Newsletter), Tone (Professional/Casual/Friendly/Educational), and Content Length (Short/Medium/Long).

Step 2: Set Up AI Content Drafting

Create the initial content draft using the AI agent connected to a chat model.

  1. Open Draft Content Generator and set Prompt Type to define.
  2. Set the Text field to =Create a {{ $json['Content Type'] }} about: {{ $json['Topic or Keyword'] }} Tone: {{ $json.Tone }} Length: {{ $json['Content Length'] }} words Remember to respond with valid JSON only..
  3. In Options → System Message, use the provided JSON-structured instructions to enforce valid JSON output.
  4. Ensure OpenAI Mini Model A is connected as the language model for Draft Content Generator.
  5. Credential Required: Connect your openAiApi credentials in OpenAI Mini Model A.

⚠️ Common Pitfall: If the AI response is not valid JSON, the downstream parsing and keyword extraction will fail. Keep the system message exactly as provided.

Step 3: Generate the Image Keyword and Query Pexels

Extract a single image keyword from the content and fetch a relevant image via Pexels.

  1. Open Derive Image Keyword and verify the model is set to gpt-4.1-mini.
  2. Confirm the system message prompts the model to return a single keyword based on {{ $json.output }}.
  3. Credential Required: Connect your openAiApi credentials in Derive Image Keyword.
  4. Open Pexels Photo Lookup and set URL to https://api.pexels.com/v1/search.
  5. Set Query Parameters → query to ={{ $json.output[0].content[0].text }}.
  6. Set Query Parameters → per_page to 5 and orientation to landscape.
  7. Set Header Parameters → Authorization to your Pexels API key (replace [CONFIGURE_YOUR_API_KEY]).

⚠️ Common Pitfall: If the Pexels API key is missing or invalid, Pexels Photo Lookup will return an authorization error and no image URL will be available.

Step 4: Compose HTML Output with Image

Combine the AI content and image URL into a final HTML output.

  1. Open Compose HTML With Image and set Prompt Type to define.
  2. Confirm the system message references {{ $('Form Input Trigger').item.json['Content Type'] }}, {{ $('Form Input Trigger').item.json['Topic or Keyword'] }}, {{ $('Draft Content Generator').item.json.output }}, and {{ $json.photos[0].url }}.
  3. Ensure OpenAI Mini Model B is connected as the language model for Compose HTML With Image.
  4. Credential Required: Connect your openAiApi credentials in OpenAI Mini Model B.
  5. Open Display Final Output and set HTML to {{ $json.output }}.

Step 5: Configure the Utility Draft + Parser Path

This separate path generates a unified JSON output and parses it into structured fields for reuse or future extension.

  1. Open Utility: Unified Content & Image Draft and confirm the Text prompt matches the structured JSON format.
  2. Ensure the system message includes Image_keyword in the JSON structure.
  3. Confirm Utility: OpenAI Mini Model C is connected as the language model for Utility: Unified Content & Image Draft.
  4. Credential Required: Connect your openAiApi credentials in Utility: OpenAI Mini Model C.
  5. Open Utility: Parse Content and Keyword and leave the JS Code as provided to parse JSON and output Title, Content, and Image_keyword.

This utility path is not connected to the main flow. If you want it to run, connect Form Input Trigger to Utility: Unified Content & Image Draft or trigger it manually for testing.

Step 6: Test and Activate Your Workflow

Validate the full flow from form submission to HTML output, then enable it for production use.

  1. Click Execute Workflow and submit the Form Input Trigger form with sample inputs.
  2. Verify Draft Content Generator outputs valid JSON and Derive Image Keyword returns a single keyword.
  3. Check Pexels Photo Lookup returns image data and Compose HTML With Image generates HTML output.
  4. Confirm Display Final Output renders the final HTML as expected.
  5. Toggle the workflow to Active once the end-to-end test succeeds.
🔒

Unlock Full Step-by-Step Guide

Get the complete implementation guide + downloadable template

Watch Out For

  • OpenAI credentials can expire or be tied to the wrong project. If things break, check your API key permissions and usage limits in the OpenAI dashboard first.
  • If you’re using Wait nodes or external rendering, processing times vary. Bump up the wait duration if downstream nodes fail on empty responses.
  • Pexels API requests can silently fail if your header is wrong or you hit hourly limits. Check the HTTP Request node’s response status and the returned error body before changing anything else.
  • Default prompts in AI nodes are generic. Add your brand voice early or you’ll be editing outputs forever.

Common Questions

How quickly can I implement this OpenAI Pexels automation?

About 30 minutes if you already have your API keys.

Can non-technical teams implement this draft creation automation?

Yes. You’re mostly pasting API keys and testing a sample topic in the form trigger.

Is n8n free to use for this OpenAI Pexels automation workflow?

Yes. n8n has a free self-hosted option and a free trial on n8n Cloud. Cloud plans start at $20/month for higher volume. You’ll also need to factor in OpenAI API costs (often a few cents per draft, depending on model) and Pexels API usage.

Where can I host n8n to run this automation?

Two options: n8n Cloud (managed, easiest setup) or self-hosting on a VPS. For self-hosting, Hostinger VPS is affordable and handles n8n well. Self-hosting gives you unlimited executions but requires basic server management.

How do I adapt this OpenAI Pexels automation solution to my specific challenges?

You can swap the Form Input Trigger for a Webhook or Google Sheets trigger, then keep the rest of the workflow the same. Many teams customize the “Derive Image Keyword” prompt to match brand style (for example, “avoid corporate stock phrases”). You can also edit “Compose HTML With Image” to output Markdown or to match your WordPress theme’s block structure. If you want to lower costs, the “Unified Content & Image Draft” path plus the parsing code node can combine steps and reduce token usage.

Why is my Pexels connection failing in this workflow?

Usually it’s a missing or incorrect Pexels API key header. Check the HTTP Request node configuration and confirm your key is active in your Pexels API dashboard. If you’re generating lots of drafts in a short time, you may also be hitting the hourly request cap, which will return errors until the limit resets.

What’s the capacity of this OpenAI Pexels automation solution?

On a typical n8n Cloud plan you can run thousands of executions per month, and on self-hosting you’re mainly limited by your server. Pexels is capped (commonly around 200 API requests per hour), so that’s the practical ceiling for image lookups. OpenAI throughput is usually not the bottleneck unless you batch large topic lists. If you plan to generate in bulk, use the workflow’s batching approach and space runs across the day.

Is this OpenAI Pexels automation better than using Zapier or Make?

Often, yes. This kind of workflow benefits from multi-step logic, optional branching (like the unified AI path), and small “glue” code for parsing content, which n8n handles cleanly. Zapier and Make can do it, but the moment you add richer logic and multiple AI calls, costs and complexity tend to climb. n8n also gives you a self-hosted option, which is useful when you want lots of runs without per-task pricing. If you’re unsure, Talk to an automation expert and we’ll sanity-check your use case.

This is what “content velocity” is supposed to feel like: one topic in, a polished draft with a relevant image out. Set it up once, then spend your time on ideas and distribution instead of tab hopping.

Need Help Setting This Up?

Our automation experts can build and customize this workflow for your specific needs. Free 15-minute consultation—no commitment required.

Lisa Granqvist

Workflow Automation Expert

Expert in workflow automation and no-code tools.

×

Use template

Get instant access to this n8n workflow Json file

💬
Get a free quote today!
Get a free quote today!

Tell us what you need and we'll get back to you within one working day.

Get a free quote today!
Get a free quote today!

Tell us what you need and we'll get back to you within one working day.

Launch login modal Launch register modal