Skip to content

Fix image generation using FLUX.2 via AI Gateway#23

Merged
ctate merged 6 commits intomainfrom
fix/image-gen-use-ai-gateway-gpt-image-1-xaUpV1
Nov 25, 2025
Merged

Fix image generation using FLUX.2 via AI Gateway#23
ctate merged 6 commits intomainfrom
fix/image-gen-use-ai-gateway-gpt-image-1-xaUpV1

Conversation

@ctate
Copy link
Collaborator

@ctate ctate commented Nov 25, 2025

No description provided.

@vercel
Copy link
Contributor

vercel bot commented Nov 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
workflow-builder Ready Ready Preview Comment Nov 25, 2025 4:42pm

varName: string
): string[] {
imports.add("import { generateImage } from './integrations/ai';");
imports.add(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generateAiImageActionCode function generates incomplete code that's missing the required API key configuration. This will cause runtime failures when the generated code tries to call the generateImage function without authentication.

View Details
📝 Patch Details
diff --git a/lib/workflow-codegen.ts b/lib/workflow-codegen.ts
index 9d74a99..4472d59 100644
--- a/lib/workflow-codegen.ts
+++ b/lib/workflow-codegen.ts
@@ -452,6 +452,11 @@ export function generateWorkflowCode(
       `${indent}  model: "${imageModel}",`,
       `${indent}  prompt: \`${imagePrompt}\`,`,
       `${indent}  size: "1024x1024",`,
+      `${indent}  providerOptions: {`,
+      `${indent}    openai: {`,
+      `${indent}      apiKey: process.env.AI_GATEWAY_API_KEY!`,
+      `${indent}    },`,
+      `${indent}  },`,
       `${indent}});`,
     ];
   }

Analysis

Missing API key configuration in generateAiImageActionCode

What fails: generateAiImageActionCode() in lib/workflow-codegen.ts (lines 436-457) generates code that calls experimental_generateImage without the required providerOptions.openai.apiKey parameter, causing authentication failures when the generated code is executed.

How to reproduce:

  1. Create a workflow with a "Generate Image" action
  2. Download/export the generated code via the API endpoint
  3. Execute the generated code without setting OPENAI_API_KEY environment variable
  4. The generateImage() call fails with authentication error

Result: Generated code produces authentication error:

Error: OpenAI API request failed: 401 Unauthorized - Incorrect API key provided

Expected: According to Vercel AI SDK documentation, providerOptions parameter can be used to pass provider-specific settings including API keys. The generated code should match the pattern used in:

  • lib/codegen-templates/generate-image.ts (lines 17-21) - template version includes providerOptions
  • lib/workflow-codegen-sdk.ts (line 514) - SDK version includes providerOptions
  • lib/steps/generate-image.ts (lines 36-40) - step function version includes providerOptions

All three existing patterns consistently pass providerOptions: { openai: { apiKey: process.env.AI_GATEWAY_API_KEY } } to ensure authentication works correctly.

Fix: Added providerOptions parameter to the generated code in generateAiImageActionCode() to match the existing patterns used throughout the codebase.

@ctate ctate merged commit d97ea19 into main Nov 25, 2025
4 checks passed
taitsengstock referenced this pull request in techops-services/keeperhub Dec 8, 2025
* Fix image generation by using gpt-image-1 via ai gateway

* Update model to bfl/flux-2-pro

* Remove dalle 2 and 3 support

* Remove flash image and its preview

* Replace open api key with ai gateway api key

* Add example usage of experimental_generateImage for 1024x1024 image

---------

Co-authored-by: Chris Tate <ctate@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant