Skip to content

fix: Gemini image support and add generate image output - #80

Open
sortedcord wants to merge 7 commits into
Sophomoresty:mainfrom
sortedcord:pr/gemini-image-support
Open

fix: Gemini image support and add generate image output#80
sortedcord wants to merge 7 commits into
Sophomoresty:mainfrom
sortedcord:pr/gemini-image-support

Conversation

@sortedcord

@sortedcord sortedcord commented Aug 16, 2026

Copy link
Copy Markdown

This PR restores authenticated Gemini Web Image input and adds generated image output through the OpenAI compataible APIs.

It also improves upstream error handling and secures remote image downloads.

Changes

Image Input

  • Updated uploaded file payloads to gemini web's current attachment format
  • uses fresh page session tokens for file bearing requests
  • supports configured google account paths through auth_user
  • uses chrome compatible requests through curl_cffi
  • preserves compatibility with legacy plain file references
  • returns one complete result for streamed image-input requests
image

This is a demonstration of gemini-web2api passing on image to gemini web chat via OpenWeb UI.

Image Generation

  • adds POST /v1/images/generations
  • Supports b64_json and validated URL responses
  • adds responses api image_generation tool output
  • extracts generated-image metadata from gemini rich-content frames
  • uses the full size image RPC when available
  • falls back to validated preview URLs
  • supports png, jpeg, and webP
image

Error handling

  • Detects structured and legacy BardErrorInfo responses
  • Treats application-level Gemini rejections as non-retryable
  • Primes streaming generators before sending SSE headers
  • Returns JSON 502 responses for failures before streaming starts
  • Emits protocol-compatible error data for failures after SSE starts

Security

Remote image input now:

  • Requires public HTTPS destinations
  • Rejects loopback, private, and link-local addresses
  • Pins validated DNS results to the actual curl connection
  • Revalidates and repins every redirect
  • Disables implicit redirects
  • Limits downloads to 10 MiB
  • Limits redirects to three hops
  • Validates declared MIME types against file signatures
  • Closes response and session resources on every path

Generated-image downloads are restricted to validated Google image hosts with bounded redirects
and response sizes.

Validation

  • 51 unit tests pass on the current Python runtime
  • 51 unit tests pass on Python 3.8
  • Ruff import, unused-import, and modernization checks pass
  • Docker image builds successfully
  • Live text generation passed
  • Live streaming image input passed
  • Live image generation passed
  • Live DNS-pinned remote image fetching passed
  • Independent review found no remaining blockers

Limitations

  • Gemini Web uses undocumented request and response formats that may change
  • Image-input streaming returns one complete result instead of incremental text
  • Remote image downloads intentionally bypass configured proxies so the validated DNS address can
    remain pinned
  • Image editing, caching, and proxying are not implemented
  • Google logout, expired cookies, and account security challenges still require credential renewal

@sortedcord sortedcord changed the title feat: Restore Gemini image support and add generate image output fix: Gemini image support and add generate image output Aug 16, 2026
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