fix: adapt image generation/editing to new Grok cardAttachment API#392
Open
JinchengGao-Infty wants to merge 1 commit intochenyme:mainfrom
Open
fix: adapt image generation/editing to new Grok cardAttachment API#392JinchengGao-Infty wants to merge 1 commit intochenyme:mainfrom
JinchengGao-Infty wants to merge 1 commit intochenyme:mainfrom
Conversation
## Problem Grok silently updated their web API: 1. Image generation via `app-chat` with explicit `modelName`/`modelMode` no longer triggers image generation - Grok returns text instead 2. Image results moved from `modelResponse.generatedImageUrls` to `cardAttachment.jsonData.image_chunk` format 3. Image editing uses a different card type (`render_edited_image`) than generation (`render_generated_image`) This broke both `/v1/images/generations` and `/v1/images/edits`. ## Root Cause Captured browser network requests and compared with grok2api payloads: - Browser uses `modeId: "auto"` without `modelName`/`modelMode` - Browser sends explicit `toolOverrides` disabling search tools - Browser sends `disableMemory: false, temporary: false` for edits ## Fix **app_chat.py**: `build_payload()` supports `model=None` — omits `modelName`/`modelMode` fields, allowing `modeId`-based routing. **image.py**: `_stream_app_chat()` and `_collect_app_chat()` now use `model=None, mode=None` with `modeId: "auto"` in request_overrides. **image_edit.py**: - `ImageStreamProcessor` and `ImageCollectProcessor` parse new `cardAttachment` format with `image_chunk.imageUrl` (progress >= 100) - Match both `render_generated_image` and `render_edited_image` types - Image URL: `https://assets.grok.com/{image_chunk.imageUrl}` - Edit path uses `disableMemory=false, temporary=false` and browser-matching `toolOverrides` to prevent search fallback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Grok silently updated their web API, breaking both
/v1/images/generationsand/v1/images/edits:app-chatwith explicitmodelName/modelModeno longer triggers image generation — Grok returns text insteadmodelResponse.generatedImageUrlstocardAttachment.jsonData.image_chunkformatrender_edited_image) than generation (render_generated_image)Root Cause
Captured browser network requests via Playwright and compared with grok2api payloads:
modelName"grok-3"modelMode"MODEL_MODE_FAST"modeId"auto"toolOverrides{"gmailSearch":false,...}{}cardAttachment.image_chunkmodelResponse.generatedImageUrlsFix
app_chat.py:build_payload()supportsmodel=None— omitsmodelName/modelMode, allowingmodeId-based routing viarequest_overrides.image.py:_stream_app_chat()and_collect_app_chat()now usemodel=None, mode=NonewithmodeId: "auto".image_edit.py:ImageStreamProcessorandImageCollectProcessorparse newcardAttachmentformat withimage_chunk.imageUrl(progress >= 100)render_generated_imageandrender_edited_imagecard typeshttps://assets.grok.com/{image_chunk.imageUrl}disableMemory=false, temporary=falseand browser-matchingtoolOverridesGrok cardAttachment Types
render_generated_imageimage_chunk.imageUrlrender_edited_imageimage_chunk.imageUrlrender_searched_imageimage.originalTest Plan
POST /v1/images/generationswithgrok-imagine-1.0— returns image URLPOST /v1/chat/completionswithgrok-imagine-1.0(stream) — returns markdown image in chat chunkPOST /v1/images/editswithgrok-imagine-1.0-edit+ image — returns edited image URLPOST /v1/chat/completionswithgrok-3— text chat unaffected