Skip to content

Add grok-superimage support, safer SSE streaming, image recovery & proxy/ retry improvements#50

Merged
lijirou12 merged 2 commits into
mainfrom
codex/migrate-imagine-to-grok-superimage-1.0-65x674
Feb 27, 2026
Merged

Add grok-superimage support, safer SSE streaming, image recovery & proxy/ retry improvements#50
lijirou12 merged 2 commits into
mainfrom
codex/migrate-imagine-to-grok-superimage-1.0-65x674

Conversation

@lijirou12
Copy link
Copy Markdown
Owner

Motivation

  • Support a new server-controlled image model grok-superimage-1.0 with unified server-side image parameters and safer streaming semantics for chat image outputs.
  • Make streaming endpoints resilient to upstream errors by emitting SSE error events instead of causing transport 5xx breaks.
  • Improve image generation robustness for cases where upstream may block or review images by adding recovery attempts and better final-image classification.
  • Improve retry logic and reverse proxy handling to better handle transient upstream failures and SOCKS proxy behavior.

Description

  • Added grok-superimage-1.0 ModelInfo and a server-side config section [superimage] in config.defaults.toml and admin UI support (app/static/admin/js/config.js) to control n, size, and response_format, and added SUPERIMAGE_MODEL_ID and _superimage_server_image_config() in app/api/v1/chat.py so the server overrides client image_config for this model.
  • Implemented safe SSE streaming helpers in app/api/v1/chat.py: _safe_sse_stream() converts exceptions into SSE error events and yields a final data: [DONE], and _streaming_error_response() to return a one-shot SSE error response for sync exceptions during stream setup; integrated these into image generation/edit and general chat/video streaming return paths.
  • Image generation improvements in app/services/grok/services/image.py: added configurable parallel recovery attempts controlled by image.blocked_parallel_attempts, run extra parallel _fetch_batch attempts when finals are insufficient, and raise UpstreamException when still insufficient after recovery.
  • Image stream processors changes in image.py and image_edit.py: only expose final images for chat-format streams, preserve original imagine image name for grok-superimage-1.0 (no -final suffix), ensure a final empty chat chunk and data: [DONE] are emitted if no intermediate chat chunk was emitted, and avoid exposing preview partials for chat streams.
  • WebSocket imagine reverse changes in app/services/reverse/ws_imagine.py: classify final images by byte-size threshold (final_min_bytes) rather than filename extension, log and raise a _BlockedError on suspected blocked/review conditions to trigger recovery behavior.
  • Retry and token picking logic in app/services/grok/utils/retry.py: added transient_upstream() that detects transient upstream errors/timeouts; used in app/services/grok/services/chat.py to attempt switching tokens on transient upstream errors when alternatives exist.
  • Reverse app-chat changes in app/services/reverse/app_chat.py: normalize proxy URLs (convert socks5:// -> socks5h://, socks4:// -> socks4a://), prefer proxy param for SOCKS proxies while using proxies for HTTP/HTTPS, and adjust timeout selection logic.
  • Minor API/admin changes: renamed import get_storage -> resolve_storage and router function get_storage -> get_storage_mode to avoid name collision in app/api/v1/admin_api/config.py.
  • Documentation updates in readme.md to list the new model and behavior notes, and added new default config keys in config.defaults.toml and localized admin UI strings in app/static/admin/js/config.js.

Testing

  • Ran the test suite with pytest -q and all tests passed.
  • Ran static checks with flake8 and no new lint errors were reported.
  • Performed local manual smoke checks of POST /v1/chat/completions for an image model stream and confirmed SSE error payloads and grok-superimage-1.0 behavior (server-side n/size/response_format) were emitted as expected.

Codex Task

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 27, 2026

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

Project Deployment Actions Updated (UTC)
grok2api Ready Ready Preview, Comment Feb 27, 2026 4:30am

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@lijirou12 lijirou12 merged commit 33fee45 into main Feb 27, 2026
3 of 4 checks passed
@lijirou12 lijirou12 deleted the codex/migrate-imagine-to-grok-superimage-1.0-65x674 branch February 27, 2026 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant