๐ŸŽจ Image Generation Intermediate โฑ 15 min โ˜๏ธ No GPU needed

Generating Images 10x Cheaper โ€” Image Automation with Kie.ai + n8n

Cut your AI image generation costs dramatically by combining Kie.ai with n8n for fully automated image pipelines.

Lesson Notes

What You'll Build

A fully automated social media video pipeline that runs on a schedule: it pulls an image prompt from Google Sheets, sends it to Kie.ai's API (no local GPU needed), generates a voiceover with KokoroTTS, creates background music, renders a captioned video using NCA Toolkit, and posts it to Instagram โ€” all without touching your computer.

What You Need

  • n8n running in Docker
  • Kie.ai account with API credits
  • MinIO running in Docker (S3-compatible local storage)
  • KokoroTTS running in Docker
  • NCA Toolkit running in Docker
  • Blotato account (for social media posting)
  • Google Sheet with columns: ID, image_prompt, talking_points, more_talking_points, music_tags, status

Why Kie.ai Instead of Local GPU?

Running ComfyUI locally needs a capable GPU. Kie.ai gives you API access to the same models (Z-Image, Flux, Suno) at a few cents per generation. For volume workflows โ€” posting daily to social media โ€” the cost is negligible and you don't need any local hardware beyond a machine that can run Docker.

Workflow Step by Step

  1. Schedule Trigger โ€” Runs the workflow on your chosen interval (e.g. daily at midnight).
  2. Google Sheets โ€” Get Row โ€” Pulls the first row where status = "processing". This is your image prompt and talking points.
  3. UUID Node โ€” Generates a unique ID so every file in this run shares the same name pattern: zimage_UUID.png, voiceover_UUID.mp3, music_UUID.mp3.
  4. HTTP POST โ†’ Kie.ai โ€” Sends a POST to https://api.kie.ai/api/v1/jobs/create-task with your Bearer token, model (zimage), aspect ratio (9:16 for TikTok/Instagram), and the image prompt from Google Sheets.
  5. Wait Node (3โ€“5 min) โ€” Kie.ai generates images asynchronously. Give it enough time before polling.
  6. HTTP GET โ†’ Kie.ai โ€” Query the task using the taskId returned in step 4. Extract the result URL with a Code node.
  7. HTTP GET โ†’ Download Image โ€” Fetch the generated image as binary data.
  8. S3 Upload โ†’ MinIO โ€” Store the image in your MinIO bucket. Use host.docker.internal:9000 as the endpoint from within n8n's Docker container.
  9. KokoroTTS โ€” POST your talking points to host.docker.internal:[port]. KokoroTTS returns an MP3. Upload that to MinIO too.
  10. NCA Toolkit โ€” Get Audio Duration โ€” POST to /v1/ffmpeg/pose with metadata: {duration: true} to find out how long the voiceover is. This determines your video length.
  11. Music Generation โ€” Either use ComfyUI locally or Kie.ai's Suno integration to generate background music matching your music_tags from Google Sheets.
  12. NCA Toolkit โ€” Render Video โ€” POST all three files (image, voiceover, music) to NCA Toolkit's FFmpeg endpoint. It loops the image, layers the audio, fades in/out, and returns an MP4.
  13. NCA Toolkit โ€” Add Captions โ€” POST the MP4 to /v1/video/caption. Set font, size, color, and style: "word_by_word" for animated captions.
  14. Download Captioned Video from MinIO โ€” Retrieve the final MP4.
  15. Blotato โ€” Upload Media โ€” Upload to Blotato's media library so it has a URL to post.
  16. Blotato โ€” Create Post โ€” Select Instagram, choose your account, write the caption (drag in image_prompt + talking points), set the media URL.
  17. Google Sheets โ€” Update Row โ€” Set status = "done" and log the post date so this row doesn't get picked up again.

The Docker Networking Trick

This is the most common point of confusion. n8n runs inside a Docker container. MinIO, KokoroTTS, and NCA Toolkit also run in Docker. When n8n needs to talk to them, you can't use localhost โ€” that would refer to n8n's own container, not your machine. Use host.docker.internal instead. This is a special DNS name Docker provides so containers can reach services on the host machine or other containers by their exposed ports.

host.docker.internal:9000  โ†’ MinIO
host.docker.internal:8188  โ†’ ComfyUI
host.docker.internal:8080  โ†’ NCA Toolkit

Key Things That Can Go Wrong

  • Task ID capitalisation โ€” Kie.ai returns taskId (camelCase). In the GET request query param, it must be taskId exactly โ€” wrong case returns a 500.
  • UUID changes on re-run โ€” If you pin nodes while testing, unpin them before the full run or the UUID will differ between the image and upload steps.
  • MinIO bucket visibility โ€” New buckets default to Private. Set to Public so the NCA Toolkit can fetch the files by URL during rendering.
  • Wait time too short โ€” If Kie.ai hasn't finished when you poll, you'll get an empty result. Bump the wait to 5 minutes for image generation.
๐Ÿ’ก Tip to Try

After the workflow runs, check your MinIO bucket in the browser at localhost:9001 โ€” you should see the image file, voiceover MP3, and final MP4 all with the same UUID in their filenames. If any are missing, that step failed silently.

Tools mentioned in this lesson:

๐Ÿ“ฆ Downloads

โšก
ImageDisplay-OffSiteImages.json
n8n Workflow to Generate images using Offsite Image Gen
Import to n8n 35KB โ†“ 0
๐Ÿ”’ Join free

๐Ÿ’ฌ Q&A

No comments yet. Be the first to ask a question.
โ† Previous
First lesson in this category
● Generating Images 10x Cheaper โ€” Image Automation with Kie.ai + n8n PHP 8.x UTF-8