openclaw - 💡(How to fix) Fix Google image generation fails with HTTP 404: x-goog-api-key header auth not accepted by generateContent endpoint [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#53751Fetched 2026-04-08 01:23:55
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Participants

The bundled Google image generation provider (dist/extensions/google/image-generation-provider.js) sends the API key via the x-goog-api-key HTTP header. Google's generateContent endpoint for image generation models returns HTTP 404 when authenticated this way, but returns 200 when the same key is passed as a ?key= query parameter.

Root Cause

The image generation provider in pi-embedded-CbCYZxIb.js uses parseGeminiAuth() which returns { headers: { "x-goog-api-key": apiKey } }. The URL is built as:

${baseUrl}/models/${model}:generateContent

This works for regular chat completions but not for image generation models. The image generation endpoint requires the API key as a query parameter:

${baseUrl}/models/${model}:generateContent?key=${apiKey}

Code Example

${baseUrl}/models/${model}:generateContent

---

${baseUrl}/models/${model}:generateContent?key=${apiKey}

---

# This returns 404:
curl -H "x-goog-api-key: $KEY" -H "Content-Type: application/json" \
  "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent" \
  -d '{"contents":[{"role":"user","parts":[{"text":"blue circle"}]}],"generationConfig":{"responseModalities":["TEXT","IMAGE"]}}'

# This returns 200:
curl -H "Content-Type: application/json" \
  "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent?key=$KEY" \
  -d '{"contents":[{"role":"user","parts":[{"text":"blue circle"}]}],"generationConfig":{"responseModalities":["TEXT","IMAGE"]}}'
RAW_BUFFERClick to expand / collapse

Bug Report

Environment

  • OpenClaw version: 2026.3.23-2
  • OS: macOS 26.3.1 (arm64)
  • Auth: GEMINI_API_KEY env var (API key from Google AI Studio)

Description

The bundled Google image generation provider (dist/extensions/google/image-generation-provider.js) sends the API key via the x-goog-api-key HTTP header. Google's generateContent endpoint for image generation models returns HTTP 404 when authenticated this way, but returns 200 when the same key is passed as a ?key= query parameter.

Steps to Reproduce

  1. Configure GEMINI_API_KEY in env
  2. Add google to plugins.allow
  3. Set agents.defaults.imageGenerationModel.primary: "google/gemini-3-pro-image-preview"
  4. Call image_generate tool

Expected

Image is generated successfully.

Actual

Google image generation failed (HTTP 404)

Root Cause Analysis

The image generation provider in pi-embedded-CbCYZxIb.js uses parseGeminiAuth() which returns { headers: { "x-goog-api-key": apiKey } }. The URL is built as:

${baseUrl}/models/${model}:generateContent

This works for regular chat completions but not for image generation models. The image generation endpoint requires the API key as a query parameter:

${baseUrl}/models/${model}:generateContent?key=${apiKey}

Verification

# This returns 404:
curl -H "x-goog-api-key: $KEY" -H "Content-Type: application/json" \
  "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent" \
  -d '{"contents":[{"role":"user","parts":[{"text":"blue circle"}]}],"generationConfig":{"responseModalities":["TEXT","IMAGE"]}}'

# This returns 200:
curl -H "Content-Type: application/json" \
  "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent?key=$KEY" \
  -d '{"contents":[{"role":"user","parts":[{"text":"blue circle"}]}],"generationConfig":{"responseModalities":["TEXT","IMAGE"]}}'

Suggested Fix

In the Google image generation provider, append the API key as a query parameter instead of (or in addition to) the x-goog-api-key header when building the generateContent URL for image generation requests.

Notes

  • The previous nano-banana-pro skill (removed in 2026.3.22) used ?key= query param auth and worked correctly.
  • Regular Gemini chat completions work fine with header auth — this only affects image generation models.
  • Tested with gemini-3-pro-image-preview, gemini-3.1-flash-image-preview, gemini-2.5-flash-image, and nano-banana-pro-preview — all 404 with header auth, all 200 with query param auth.

extent analysis

Fix Plan

To fix the issue, modify the parseGeminiAuth() function in pi-embedded-CbCYZxIb.js to append the API key as a query parameter for image generation requests.

  • Update the parseGeminiAuth() function to include a conditional check for image generation requests:
function parseGeminiAuth(apiKey, isImageGeneration) {
  if (isImageGeneration) {
    return {
      urlParams: { key: apiKey }
    };
  } else {
    return {
      headers: { "x-goog-api-key": apiKey }
    };
  }
}
  • Modify the URL construction to include the query parameter for image generation requests:
const url = `${baseUrl}/models/${model}:generateContent`;
if (isImageGeneration) {
  url += `?key=${apiKey}`;
}

Alternatively, you can use the URL class to construct the URL with query parameters:

const url = new URL(`${baseUrl}/models/${model}:generateContent`);
if (isImageGeneration) {
  url.searchParams.set("key", apiKey);
}
  • Ensure that the isImageGeneration flag is set correctly when calling the parseGeminiAuth() function for image generation requests.

Verification

After applying the fix, verify that image generation requests return a 200 status code by running the following curl command:

curl -H "Content-Type: application/json" \
  "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent?key=$KEY" \
  -d '{"contents":[{"role":"user","parts":[{"text":"blue circle"}]}],"generationConfig":{"responseModalities":["TEXT","IMAGE"]}}'

Replace $KEY with the actual API key.

Extra Tips

  • Ensure that the API key is properly secured and not exposed in the code or logs.
  • Consider adding error handling for cases where the API key is invalid or missing.
  • If you're using a library or framework to construct the URL, check the documentation for any specific requirements or recommendations for handling query parameters.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Google image generation fails with HTTP 404: x-goog-api-key header auth not accepted by generateContent endpoint [1 participants]