Quick overview
This sub-workflow replaces a broken Sora video-generation step by submitting text-to-video jobs to Kie.ai, caching identical requests in an n8n Data Table, and saving successful renders to Google Drive before returning a single result payload to the calling workflow.
How it works
- Receives input from a calling workflow (or a manual test run) with a prompt and optional render settings.
- Normalizes and clamps the request parameters, generates a deterministic job key, and prepares a model fallback chain.
- Checks an n8n Data Table for a matching job key and immediately returns the previously stored video details if a cache hit exists.
- Submits the job to Kie.ai for each model in sequence, polling Kie.ai every 20 seconds for up to 5 minutes per model and moving on when a model fails or times out.
- Aggregates all attempts to pick the first successful render and compiles an attempt trail with total credits consumed.
- Downloads the winning video, uploads it to Google Drive, and upserts the job key, video URL, Drive file ID, model, and credit usage into the n8n Data Table.
- Returns a flat response containing either the delivered video details or a failure payload with the models tried and reasons.
Setup
- Create an HTTP Header Auth credential for Kie.ai and add your API key so the HTTP requests to api.kie.ai can authenticate.
- Connect Google Drive credentials and set the target Drive and folder ID where rendered videos should be saved.
- Create an n8n Data Table to act as a render ledger (jobKey, videoUrl, driveFileId, model, creditsConsumed, renderedAtMs) and replace YOUR_RENDER_LEDGER_TABLE_ID in both Data Table steps.
- In the calling workflow, add an Execute Sub-workflow node pointing to this workflow and pass at least prompt (optionally durationSeconds, aspectRatio, resolution, firstFrameUrl, callbackUrl, and modelChain).