AI Image Generation, Google Drive Storage, and Usage Tracking - n8n Workflow

Automate DALL-E/GPT image generation using an n8n workflow. Store files in Google Drive and log prompts, links, and estimated costs in Google Sheets. Get started with n8n templates.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Content creators needing prompt-to-image automation.

  • Businesses tracking AI usage costs precisely.

  • Users looking for advanced n8n workflow examples combining AI, storage, and logging.

  • Developers seeking robust n8n templates for OpenAI integrations.

Overview

This advanced n8n workflow solves the challenge of automating image generation while simultaneously ensuring robust logging and cost oversight. Using a simple chat prompt as an n8n trigger, it calls the OpenAI API (GPT-image-1 model), processes the resulting base64 image data, stores the generated assets in Google Drive for centralized access, and meticulously records the transaction details—including estimated costs—in Google Sheets. This is a crucial n8n workflow for maintaining transparency and control over cloud AI expenditures and serves as an excellent example of functional n8n templates.

How it Works


  1. Trigger: The n8n trigger, When chat message received (a Chat Trigger n8n node), initiates the entire n8n workflow upon receiving a prompt.

  2. Image Generation: An HTTP Request n8n node sends the prompt ($json.chatInput) to the OpenAI API, requesting image generation using the gpt-image-1 model. This is the core function of the n8n workflow.

  3. Data Handling: The Split Out n8n node handles the API response, isolating the image data array. The Loop Over Items n8n node ensures each generated image is processed individually.

  4. Preparation: The data is processed by the Edit Fields-file_name n8n node to assign a unique, timestamp-based filename and prepare the base64 content. The Convert to File n8n node then transforms the base64 string into a binary file, ready for cloud storage.

  5. Storage: The Google Drive n8n node uploads the binary image file to the designated cloud folder.

  6. Logging Image Details: The Edit Fields1 n8n node extracts the newly created file links (web link, thumbnail link) from the Google Drive response. The first Google Sheets n8n node logs the prompt and the resulting image links, creating a visual catalog in the spreadsheet.

  7. Cost Tracking: Separately, the Aggregate n8n node collects the initial response data for global logging. The second Google Sheets1 n8n node records the prompt, datetime, input/output tokens, and a calculated estimated price, offering essential cost transparency for this sophisticated n8n template.

Installation Guide


  1. Import the n8n workflow: Copy the provided JSON and import it into your n8n instance.

  2. OpenAI Credentials: Set up your OpenAI API credentials for the HTTP Request n8n node. This needs access to the image generation endpoint.

  3. Google Drive Credentials: Set up OAuth2 credentials for the Google Drive n8n node and update the Folder ID parameter to point to your desired storage location.

  4. Google Sheets Credentials: Set up OAuth2 credentials for both Google Sheets n8n nodes. You must link the nodes to your specific target spreadsheet document ID and ensure the sheet names (工作表1 and usage in the example) match your desired logging tabs.

  5. Activate: Ensure the Chat Trigger n8n node is configured and the entire n8n workflow is activated to run automatically upon prompt receipt.

Node Details

When chat message received (@n8n/n8n-nodes-langchain.chatTrigger): This serves as the primary n8n trigger, initiating the automation when a message containing the desired prompt is received.
HTTP Request (n8n node): Configured to connect to the OpenAI Image Generation API using the gpt-image-1 model. It injects the prompt dynamically from the upstream trigger data.
Split Out & Loop Over Items (n8n node): Flow control nodes used to reliably iterate over the array of generated images (even if only one is requested), crucial for handling API responses within this n8n workflow.
Convert to File (n8n node): Handles the conversion of the base64 encoded image data (b64json) received from the OpenAI API into a binary object for storage.
Google Drive (n8n node): Manages the file upload operation, storing the generated image in the cloud. It uses dynamic naming based on timestamps.
Google Sheets (Image Log) (n8n node): Appends a row containing the original prompt and the newly generated image links (WebView and Thumbnail) to a designated sheet.


  • Google Sheets1 (Cost Tracking) (n8n node): A specialized component of this n8n template designed for logging usage data (inputtokens, output_tokens) and calculating estimated total costs based on predefined rates, providing excellent operational transparency.

Related n8n Workflows

Free

Nodes: 11 Nodes
Updated: December 26 2025
View all
Created by

Martech Engineer with automation. here is my website: https://www.darrelltw.com/

Featured*