OpenAI + Pexels: publish ready drafts with images
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
flowchart LR
subgraph sg0["On form submission Flow"]
direction LR
n0["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/httprequest.dark.svg' width='40' height='40' /></div><br/>Pexels Image Search"]
n1@{ icon: "mdi:robot", form: "rounded", label: "Create Content with AI", pos: "b", h: 48 }
n2@{ icon: "mdi:robot", form: "rounded", label: "Find suitable content keyword", pos: "b", h: 48 }
n3@{ icon: "mdi:robot", form: "rounded", label: "Create Suitable Content Incl..", pos: "b", h: 48 }
n5["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/html.dark.svg' width='40' height='40' /></div><br/>View the Result"]
n6["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/form.svg' width='40' height='40' /></div><br/>On form submission"]
n8@{ icon: "mdi:brain", form: "rounded", label: "OpenAI 4.1 mini", pos: "b", h: 48 }
n9@{ icon: "mdi:brain", form: "rounded", label: "OpenAi 4.1 Mini", pos: "b", h: 48 }
n8 -.-> n1
n9 -.-> n3
n6 --> n1
n0 --> n3
n1 --> n2
n2 --> n0
n3 --> n5
end
subgraph sg1["Create Content and F Flow"]
direction LR
n4["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/code.svg' width='40' height='40' /></div><br/>Extract Content and Image Ke.."]
n7@{ icon: "mdi:robot", form: "rounded", label: "Create Content and Find Suit..", pos: "b", h: 48 }
n10@{ icon: "mdi:brain", form: "rounded", label: "OpenAI 4.1 mini for Content ..", pos: "b", h: 48 }
n10 -.-> n7
n7 --> n4
end
%% Styling
classDef trigger fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
classDef ai fill:#e3f2fd,stroke:#1976d2,stroke-width:2px
classDef aiModel fill:#e8eaf6,stroke:#3f51b5,stroke-width:2px
classDef decision fill:#fff8e1,stroke:#f9a825,stroke-width:2px
classDef database fill:#fce4ec,stroke:#c2185b,stroke-width:2px
classDef api fill:#fff3e0,stroke:#e65100,stroke-width:2px
classDef code fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
classDef disabled stroke-dasharray: 5 5,opacity: 0.5
class n6 trigger
class n1,n2,n3,n7 ai
class n8,n9,n10 aiModel
class n0 api
class n4 code
classDef customIcon fill:none,stroke:none
class n0,n5,n6,n4 customIcon
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
| What This Eliminates | Impact You’ll See |
|---|---|
|
|
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.
- Add and open Form Input Trigger.
- Set Form Title to
AI Content Generator. - 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.
- Open Draft Content Generator and set Prompt Type to
define. - 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.. - In Options → System Message, use the provided JSON-structured instructions to enforce valid JSON output.
- Ensure OpenAI Mini Model A is connected as the language model for Draft Content Generator.
- Credential Required: Connect your
openAiApicredentials in OpenAI Mini Model A.
Step 3: Generate the Image Keyword and Query Pexels
Extract a single image keyword from the content and fetch a relevant image via Pexels.
- Open Derive Image Keyword and verify the model is set to
gpt-4.1-mini. - Confirm the system message prompts the model to return a single keyword based on
{{ $json.output }}. - Credential Required: Connect your
openAiApicredentials in Derive Image Keyword. - Open Pexels Photo Lookup and set URL to
https://api.pexels.com/v1/search. - Set Query Parameters → query to
={{ $json.output[0].content[0].text }}. - Set Query Parameters → per_page to
5and orientation tolandscape. - Set Header Parameters → Authorization to your Pexels API key (replace
[CONFIGURE_YOUR_API_KEY]).
Step 4: Compose HTML Output with Image
Combine the AI content and image URL into a final HTML output.
- Open Compose HTML With Image and set Prompt Type to
define. - 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 }}. - Ensure OpenAI Mini Model B is connected as the language model for Compose HTML With Image.
- Credential Required: Connect your
openAiApicredentials in OpenAI Mini Model B. - 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.
- Open Utility: Unified Content & Image Draft and confirm the Text prompt matches the structured JSON format.
- Ensure the system message includes
Image_keywordin the JSON structure. - Confirm Utility: OpenAI Mini Model C is connected as the language model for Utility: Unified Content & Image Draft.
- Credential Required: Connect your
openAiApicredentials in Utility: OpenAI Mini Model C. - Open Utility: Parse Content and Keyword and leave the JS Code as provided to parse JSON and output
Title,Content, andImage_keyword.
Step 6: Test and Activate Your Workflow
Validate the full flow from form submission to HTML output, then enable it for production use.
- Click Execute Workflow and submit the Form Input Trigger form with sample inputs.
- Verify Draft Content Generator outputs valid JSON and Derive Image Keyword returns a single keyword.
- Check Pexels Photo Lookup returns image data and Compose HTML With Image generates HTML output.
- Confirm Display Final Output renders the final HTML as expected.
- Toggle the workflow to Active once the end-to-end test succeeds.
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
About 30 minutes if you already have your API keys.
Yes. You’re mostly pasting API keys and testing a sample topic in the form trigger.
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.
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.
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.
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.
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.
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.