Skip to content

Add grok-superimage support, robust SSE streaming, image recovery and proxy/ retry fixes#51

Merged
lijirou12 merged 2 commits intomainfrom
codex/migrate-imagine-to-grok-superimage-1.0-y2p5rd
Feb 27, 2026
Merged

Add grok-superimage support, robust SSE streaming, image recovery and proxy/ retry fixes#51
lijirou12 merged 2 commits intomainfrom
codex/migrate-imagine-to-grok-superimage-1.0-y2p5rd

Conversation

@lijirou12
Copy link
Copy Markdown
Owner

Motivation

  • Introduce a server-controlled "superimage" model and improve image generation reliability when upstreams are blocked or return only previews.
  • Make streaming endpoints more robust by wrapping streams to emit SSE-formatted error events instead of transport-level 5xx breaks.
  • Improve token retry behavior by treating certain upstream errors as transient and falling back to alternate tokens, and defaulting retry counts when config is missing.
  • Fix proxy handling for app-chat reverse requests and avoid HTTP CONNECT mishandling for SOCKS proxies.

Description

  • Added a new model entry grok-superimage-1.0 and server-side [superimage] config options (n, size, response_format) and wired them into the Chat API to force server-controlled image parameters for that model (app/services/grok/services/model.py, app/api/v1/chat.py, config.defaults.toml, readme.md).
  • Implemented SSE-safe streaming helpers to catch exceptions and return SSE error events (_safe_sse_stream, _streaming_error_response) and wrapped all streaming responses with them so clients receive structured SSE errors (app/api/v1/chat.py).
  • Added logic to use server-side superimage parameters when model == grok-superimage-1.0 and ensured streaming for that model only emits final images and preserves original image names for URL outputs (app/services/grok/services/image.py, app/services/grok/services/image_edit.py).
  • Added blocked-image recovery: run configurable parallel retry attempts when insufficient finals are produced and fail with a clear UpstreamException if still insufficient (image.blocked_parallel_attempts) (app/services/grok/services/image.py, config.defaults.toml, admin UI updates).
  • Tightened final-image classification to require a byte-size threshold and adjusted WS imagine logic to detect suspected blocking/review and raise a blocked error to trigger recovery attempts (app/services/reverse/ws_imagine.py).
  • Improved image stream processors to only expose final images for chat completion streams, ensure a final chat completion chunk and always emit the terminal [DONE] marker for chat-formatted streams (app/services/grok/services/image.py, app/services/grok/services/image_edit.py).
  • Added transient upstream detection helper and integrated it into token-retry logic to try alternate tokens on transient errors, and defaulted retry.max_retry fallbacks to 3 when unset (app/services/grok/utils/retry.py, app/services/grok/services/chat.py, app/services/grok/services/image.py, app/services/grok/services/image_edit.py).
  • Normalized and improved proxy handling for the app-chat reverse path, selecting between proxy and proxies parameters for curl-cffi based on scheme and logging proxy usage, and simplified timeout selection (app/services/reverse/app_chat.py).
  • Minor API/admin changes: renamed local import to avoid shadowing (get_storage -> resolve_storage) and exposed storage mode endpoint name change; added admin UI fields and locales for superimage and blocked_parallel_attempts (app/api/v1/admin_api/config.py, app/static/admin/js/config.js).

Testing

  • Ran the project's automated test suite with pytest (existing unit/integration tests) and no test failures were observed.
  • Performed basic smoke checks of the chat/image generation flows (non-blocking) to validate SSE error formatting and that grok-superimage-1.0 uses server-controlled image parameters during request validation.

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:47am

@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 8b0eed1 into main Feb 27, 2026
3 of 4 checks passed
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