[PR #7489] [MERGED] feat(image): add SpicyAPI image generation connections #7757

Closed
opened 2026-10-24 04:07:13 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7489
Author: @SpicyMarinara
Created: 10/12/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/spicyapi-image-generation


📝 Commits (5)

  • bfcb1f3 feat(image): add SpicyAPI image generation connections
  • ae0d4f0 fix(image): wait for stored SpicyAPI results and tidy the editor change
  • c69d3bb fix(image): stop SpicyAPI polling on a stateless reply or a long outage
  • 601371c fix(image): fit SpicyAPI references to its limits and survive dropped connections
  • 8f6eba6 fix(image): omit SpicyAPI image_urls when every reference was skipped

📊 Changes

8 files changed (+772 additions, -2 deletions)

View changed files

📝 docs/media/image-providers.md (+12 -0)
📝 packages/client/src/components/connections/ConnectionEditor.tsx (+13 -2)
📝 packages/client/src/localization/locales/en.json (+2 -0)
📝 packages/server/src/routes/connections.routes.ts (+22 -0)
📝 packages/server/src/services/image/image-generation.ts (+176 -0)
➕ packages/server/src/services/image/spicyapi-image.ts (+196 -0)
📝 packages/shared/src/constants/model-lists.ts (+16 -0)
➕ scripts/regressions/spicyapi-image.regression.ts (+335 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7478

Why this change

Users couldn't get SpicyAPI (https://spicyapi.ai) to make images in Marinara. SpicyAPI's OpenAI-style address (/v1) only handles chat and video, and it has no /v1/images/generations. A Custom image connection pointed at it had nothing to call. SpicyAPI makes images only through its own task API: POST /api/v1/jobs/createTask, then GET /api/v1/jobs/recordInfo until the task finishes. Each model also declares its own input fields, for example an aspect ratio, a width and height, or a fixed size.

What changed

  • Behavior change for existing connections: an image connection with a spicyapi.ai Base URL and no saved service now uses the new SpicyAPI service instead of the OpenAI-compatible path. That path could never return an image from SpicyAPI, so nothing that worked before stops working. Connections whose saved service is OpenAI (DALL-E) are unchanged. They still can't make images until their service is switched to SpicyAPI.
  • New SpicyAPI image service in the connection editor. It fills in the Base URL https://api.spicyapi.ai/api/v1, the model alibaba/z-image-spicy-pro/text-to-image, and a link to the SpicyAPI console's key page.
  • Generation (packages/server/src/services/image/spicyapi-image.ts and generateSpicyApi in image-generation.ts):
    • It reads the chosen model's input schema (GET /api/v1/models/{model}) and sends only the fields that model declares. It picks the closest declared aspect_ratio or size, or a width/height fitted to the model's min, max and step.
    • If the model has a negative_prompt field, the negative prompt goes there. Otherwise it is added to the end of the prompt as text.
    • Edit models get reference images as data URLs in image_urls (up to the model's maxItems) or image_url.
    • References are fitted to SpicyAPI's documented inline limits: 1 MiB per decoded image (JPEG, PNG, WebP or GIF) and 2 MiB for the whole request. A larger or unsupported reference is re-encoded as a smaller WebP with the optional sharp module. Extra references are then dropped from the end until the request fits. Each step logs a warning. Without sharp, an oversize reference is skipped. If every reference is skipped, image_urls is left out rather than sent empty.
    • Custom Parameters are merged into input.
    • Tasks are created with ?wait=50 and an Idempotency-Key. If the connection drops before a reply, the same request is resent with the same key, up to 3 attempts. SpicyAPI answers a repeated key with the original task, so it isn't billed twice. Tasks still running after that are polled every 2 s, including a succeeded task whose result is still being stored.
    • A 429, a 5xx or a dropped connection while polling doesn't abandon the paid task. After about two minutes of them in a row, the wait ends with the task ID in the error.
    • A reply without a task state fails at once. failed, canceled and expired tasks report SpicyAPI's errorCode and errorMessage.
    • The signed result URL is downloaded through the existing result-URL policy, without the API key.
    • The model ID is checked before any request, so it can't change the request path.
  • Test Connection reads GET /api/v1/models?modality=image with the key, which costs nothing. Fetch Models from API lists the account's available text-to-image and edit models.
  • Prompt debug logging: [debug/image/spicyapi] final request payload goes through logDebugOverride and imagePayloadForLog. The API key is only ever in the Authorization header and is never logged. Reference image bytes are redacted.
  • Docs: new SpicyAPI section, plus rows in the service and reference-image tables, in docs/media/image-providers.md. Translation follow-up: #7491.
  • Regression: scripts/regressions/spicyapi-image.regression.ts runs against a fake SpicyAPI server.

Images only. SpicyAPI video is not part of this PR.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Commands run by the agent:

  • node ./scripts/run-regressions.mjs --filter scripts/regressions/spicyapi-image.regression.ts: passed. The fake SpicyAPI server checks:
    • the three ways a model can take a shape (aspect ratio, width and height, fixed size);
    • the negative prompt handling and the reference image cap;
    • that Custom Parameters are merged into input;
    • the Idempotency-Key and wait=50 on task creation;
    • that a dropped createTask connection is resent once with the same Idempotency-Key and body, and that a dropped poll connection doesn't stop polling;
    • that two 800 KB avatars sent to an edit model are cut to one so the body fits 2 MiB, and that a real PNG character sheet of about 1.9 MB is shrunk to a WebP under 1 MiB. The fake server rejects either limit the way SpicyAPI documents;
    • that a 503 or a result still being stored doesn't stop polling;
    • that failed tasks, stateless replies, results without a URL, and 402 replies report their reason;
    • that invalid model IDs and a blank key fail before any request is sent;
    • that the API key isn't sent with the result download and doesn't appear in debug logs;
    • that Test Connection and Fetch Models only read the catalog.
  • Proof for the review fixes in 601371cf6 and 8f6eba62f: at the previous head, the new dropped-connection case failed with TypeError: fetch failed (SocketError: other side closed). With only the reference fitting switched off, the new reference case failed with SpicyAPI image generation failed (413): Request body too large. Both pass on the final code.
  • pnpm check (localization, format, lint and typecheck, e2e and token-estimation types, full build): exit 0 on the final code (8f6eba62f). The only lint warning is an existing react-hooks/exhaustive-deps warning in client code this PR doesn't touch.
  • node ./scripts/run-regressions.mjs --filter image: 18/18 passed. --filter connection: 6/6 passed (rerun on 601371cf6). These include fal-image, image-custom-parameters, image-generation-timeout, gpt-image-2-5 and codex-chatgpt-image. model-source-hosts, open-issues, codex-reasoning-effort and issue-sweep-5216-5218 also passed; each touches the shared image source lists.
  • Not covered by a regression: the two-minute limit on consecutive failed polls, which would take 60 polls at 2 s, and SpicyAPI's 8 MP per-image pixel cap. A reference under 1 MB but over 8 MP still gets SpicyAPI's own 400 reply; a ponytail: comment in fitSpicyApiReference names that limit and the upgrade path.

Reviewer findings fixed in 601371cf6:

  • Edit-model references ignored SpicyAPI's inline limits, so two 800 KB avatars got a 413 and a 1.5 MB character sheet got a 400. Fixed by shrinking oversize references and dropping extras until the request fits, following the NanoGPT request-size pattern.
  • A dropped connection during createTask or a poll ended the generation with a bare fetch failed and abandoned a paid task. Fixed: createTask is resent with the same Idempotency-Key, and a failed poll counts like a busy reply.

Local CodeRabbit review (coderabbit review --agent --committed, three runs; the third, on 8f6eba62f, reported 1 finding, the docs-i18n mirror below, which #7491 covers and which now quotes the updated English text):

  • Fixed: polling went on until the 30-minute image deadline when a reply had no state or SpicyAPI kept failing (commit c69d3bb8c).
  • Addressed outside the diff: "mirror the guide on docs-i18n". Follow-up #7491 is open and linked.
  • Declined: "warn or reject when references exist but the model has no image_urls/image_url field". In SpicyAPI's public catalog, every edit endpoint declares one of those two fields, and no text-to-image endpoint does. Rejecting would break Illustrator's text-to-image requests, which often carry character references. A warning would fire on every one of them. Text-to-image models skip references, as with Venice and Z.AI, and the guide says so.

Manual verification notes

Not verified against the live SpicyAPI service. The agent had no SpicyAPI key. The request and response shapes come from SpicyAPI's published OpenAPI contract (https://docs.spicyapi.ai/openapi.yaml).

Manual verification needed:

  1. In Connections, create an Image Generation connection and pick SpicyAPI. Confirm that the Base URL https://api.spicyapi.ai/api/v1 and the model alibaba/z-image-spicy-pro/text-to-image are filled in, and that the API key link opens the SpicyAPI console.
  2. Paste a real SpicyAPI key and click Test Connection. It should succeed without charging your balance. With a wrong key, it should show SpicyAPI's 401 message.
  3. Click Fetch Models from API and confirm that text-to-image and edit models appear, with no upscaler or layer models.
  4. Click Test Image with alibaba/z-image-spicy-pro/text-to-image, then with bytedance/seedream-5.0-pro/text-to-image. Both should return an image. With Debug mode on, confirm that the server log shows [debug/image/spicyapi] final request payload without the key.
  5. Generate a portrait-shaped image, such as a character avatar, and confirm the result is portrait-shaped.
  6. Pick an /edit model, such as alibaba/qwen-image-2.1/edit, and generate a scene illustration that has a character reference. Confirm the reference is used. Repeat with a character whose avatar file is over 1 MB. The image should still generate, and the server log should show no SpicyAPI 413 or 400 error.
  7. Open an image connection whose service is OpenAI (DALL-E) and whose Base URL is on spicyapi.ai. Switch its service to SpicyAPI and confirm that Test Image now works.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Updated docs/media/image-providers.md. The [docs-i18n] follow-up is #7491. Per the 2026-10-12 policy, CHANGELOG.md is untouched, and the release note comes from What changed above.

UI evidence (if applicable)

None captured. The only UI change is one more card in the existing image service grid, plus a key link.

Summary by CodeRabbit

  • New Features
    • Added SpicyAPI as an image-generation provider, with model selection, connection testing, and model discovery.
    • Added support for provider-specific image settings, task polling and resumption, and reference images on compatible edit models.
    • Added SpicyAPI setup guidance and API-key access in the connection editor. Oversized reference images are reduced to meet provider limits.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7489 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/12/2026 **Status:** ✅ Merged **Merged:** 10/12/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/spicyapi-image-generation` --- ### 📝 Commits (5) - [`bfcb1f3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bfcb1f33e95fff2ab4815a6f862d332d4fe3a404) feat(image): add SpicyAPI image generation connections - [`ae0d4f0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ae0d4f0a6af0cf5cfcd24a9624045e24d1195d2b) fix(image): wait for stored SpicyAPI results and tidy the editor change - [`c69d3bb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c69d3bb8c61379c7a269ec4ab4782813e2bf2a72) fix(image): stop SpicyAPI polling on a stateless reply or a long outage - [`601371c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/601371cf6b4c7a3e8ae3bc60a5c3895bc5f11162) fix(image): fit SpicyAPI references to its limits and survive dropped connections - [`8f6eba6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8f6eba62fd246feef5363409b1ba8abbbeac1f7d) fix(image): omit SpicyAPI image_urls when every reference was skipped ### 📊 Changes **8 files changed** (+772 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docs/media/image-providers.md` (+12 -0) 📝 `packages/client/src/components/connections/ConnectionEditor.tsx` (+13 -2) 📝 `packages/client/src/localization/locales/en.json` (+2 -0) 📝 `packages/server/src/routes/connections.routes.ts` (+22 -0) 📝 `packages/server/src/services/image/image-generation.ts` (+176 -0) ➕ `packages/server/src/services/image/spicyapi-image.ts` (+196 -0) 📝 `packages/shared/src/constants/model-lists.ts` (+16 -0) ➕ `scripts/regressions/spicyapi-image.regression.ts` (+335 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7478 ## Why this change Users couldn't get SpicyAPI (https://spicyapi.ai) to make images in Marinara. SpicyAPI's OpenAI-style address (`/v1`) only handles chat and video, and it has no `/v1/images/generations`. A **Custom** image connection pointed at it had nothing to call. SpicyAPI makes images only through its own task API: `POST /api/v1/jobs/createTask`, then `GET /api/v1/jobs/recordInfo` until the task finishes. Each model also declares its own input fields, for example an aspect ratio, a width and height, or a fixed size. ## What changed - **Behavior change for existing connections:** an image connection with a `spicyapi.ai` Base URL and no saved service now uses the new SpicyAPI service instead of the OpenAI-compatible path. That path could never return an image from SpicyAPI, so nothing that worked before stops working. Connections whose saved service is **OpenAI (DALL-E)** are unchanged. They still can't make images until their service is switched to **SpicyAPI**. - New **SpicyAPI** image service in the connection editor. It fills in the Base URL `https://api.spicyapi.ai/api/v1`, the model `alibaba/z-image-spicy-pro/text-to-image`, and a link to the SpicyAPI console's key page. - Generation (`packages/server/src/services/image/spicyapi-image.ts` and `generateSpicyApi` in `image-generation.ts`): - It reads the chosen model's input schema (`GET /api/v1/models/{model}`) and sends only the fields that model declares. It picks the closest declared `aspect_ratio` or `size`, or a `width`/`height` fitted to the model's min, max and step. - If the model has a `negative_prompt` field, the negative prompt goes there. Otherwise it is added to the end of the prompt as text. - Edit models get reference images as data URLs in `image_urls` (up to the model's `maxItems`) or `image_url`. - References are fitted to SpicyAPI's documented inline limits: 1 MiB per decoded image (JPEG, PNG, WebP or GIF) and 2 MiB for the whole request. A larger or unsupported reference is re-encoded as a smaller WebP with the optional `sharp` module. Extra references are then dropped from the end until the request fits. Each step logs a warning. Without `sharp`, an oversize reference is skipped. If every reference is skipped, `image_urls` is left out rather than sent empty. - **Custom Parameters** are merged into `input`. - Tasks are created with `?wait=50` and an `Idempotency-Key`. If the connection drops before a reply, the same request is resent with the same key, up to 3 attempts. SpicyAPI answers a repeated key with the original task, so it isn't billed twice. Tasks still running after that are polled every 2 s, including a succeeded task whose result is still being stored. - A 429, a 5xx or a dropped connection while polling doesn't abandon the paid task. After about two minutes of them in a row, the wait ends with the task ID in the error. - A reply without a task state fails at once. `failed`, `canceled` and `expired` tasks report SpicyAPI's `errorCode` and `errorMessage`. - The signed result URL is downloaded through the existing result-URL policy, without the API key. - The model ID is checked before any request, so it can't change the request path. - **Test Connection** reads `GET /api/v1/models?modality=image` with the key, which costs nothing. **Fetch Models from API** lists the account's available text-to-image and edit models. - Prompt debug logging: `[debug/image/spicyapi] final request payload` goes through `logDebugOverride` and `imagePayloadForLog`. The API key is only ever in the `Authorization` header and is never logged. Reference image bytes are redacted. - Docs: new SpicyAPI section, plus rows in the service and reference-image tables, in `docs/media/image-providers.md`. Translation follow-up: #7491. - Regression: `scripts/regressions/spicyapi-image.regression.ts` runs against a fake SpicyAPI server. Images only. SpicyAPI video is not part of this PR. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Commands run by the agent: - `node ./scripts/run-regressions.mjs --filter scripts/regressions/spicyapi-image.regression.ts`: passed. The fake SpicyAPI server checks: - the three ways a model can take a shape (aspect ratio, width and height, fixed size); - the negative prompt handling and the reference image cap; - that Custom Parameters are merged into `input`; - the `Idempotency-Key` and `wait=50` on task creation; - that a dropped createTask connection is resent once with the same `Idempotency-Key` and body, and that a dropped poll connection doesn't stop polling; - that two 800 KB avatars sent to an edit model are cut to one so the body fits 2 MiB, and that a real PNG character sheet of about 1.9 MB is shrunk to a WebP under 1 MiB. The fake server rejects either limit the way SpicyAPI documents; - that a 503 or a result still being stored doesn't stop polling; - that failed tasks, stateless replies, results without a URL, and 402 replies report their reason; - that invalid model IDs and a blank key fail before any request is sent; - that the API key isn't sent with the result download and doesn't appear in debug logs; - that Test Connection and Fetch Models only read the catalog. - Proof for the review fixes in 601371cf6 and 8f6eba62f: at the previous head, the new dropped-connection case failed with `TypeError: fetch failed` (`SocketError: other side closed`). With only the reference fitting switched off, the new reference case failed with `SpicyAPI image generation failed (413): Request body too large`. Both pass on the final code. - `pnpm check` (localization, format, lint and typecheck, e2e and token-estimation types, full build): exit 0 on the final code (8f6eba62f). The only lint warning is an existing `react-hooks/exhaustive-deps` warning in client code this PR doesn't touch. - `node ./scripts/run-regressions.mjs --filter image`: 18/18 passed. `--filter connection`: 6/6 passed (rerun on 601371cf6). These include `fal-image`, `image-custom-parameters`, `image-generation-timeout`, `gpt-image-2-5` and `codex-chatgpt-image`. `model-source-hosts`, `open-issues`, `codex-reasoning-effort` and `issue-sweep-5216-5218` also passed; each touches the shared image source lists. - Not covered by a regression: the two-minute limit on consecutive failed polls, which would take 60 polls at 2 s, and SpicyAPI's 8 MP per-image pixel cap. A reference under 1 MB but over 8 MP still gets SpicyAPI's own 400 reply; a `ponytail:` comment in `fitSpicyApiReference` names that limit and the upgrade path. Reviewer findings fixed in 601371cf6: - Edit-model references ignored SpicyAPI's inline limits, so two 800 KB avatars got a 413 and a 1.5 MB character sheet got a 400. Fixed by shrinking oversize references and dropping extras until the request fits, following the NanoGPT request-size pattern. - A dropped connection during createTask or a poll ended the generation with a bare `fetch failed` and abandoned a paid task. Fixed: createTask is resent with the same `Idempotency-Key`, and a failed poll counts like a busy reply. Local CodeRabbit review (`coderabbit review --agent --committed`, three runs; the third, on 8f6eba62f, reported 1 finding, the docs-i18n mirror below, which #7491 covers and which now quotes the updated English text): - Fixed: polling went on until the 30-minute image deadline when a reply had no state or SpicyAPI kept failing (commit c69d3bb8c). - Addressed outside the diff: "mirror the guide on `docs-i18n`". Follow-up #7491 is open and linked. - Declined: "warn or reject when references exist but the model has no `image_urls`/`image_url` field". In SpicyAPI's public catalog, every edit endpoint declares one of those two fields, and no text-to-image endpoint does. Rejecting would break Illustrator's text-to-image requests, which often carry character references. A warning would fire on every one of them. Text-to-image models skip references, as with Venice and Z.AI, and the guide says so. ### Manual verification notes Not verified against the live SpicyAPI service. The agent had no SpicyAPI key. The request and response shapes come from SpicyAPI's published OpenAPI contract (`https://docs.spicyapi.ai/openapi.yaml`). Manual verification needed: 1. In **Connections**, create an **Image Generation** connection and pick **SpicyAPI**. Confirm that the Base URL `https://api.spicyapi.ai/api/v1` and the model `alibaba/z-image-spicy-pro/text-to-image` are filled in, and that the API key link opens the SpicyAPI console. 2. Paste a real SpicyAPI key and click **Test Connection**. It should succeed without charging your balance. With a wrong key, it should show SpicyAPI's 401 message. 3. Click **Fetch Models from API** and confirm that text-to-image and edit models appear, with no upscaler or layer models. 4. Click **Test Image** with `alibaba/z-image-spicy-pro/text-to-image`, then with `bytedance/seedream-5.0-pro/text-to-image`. Both should return an image. With **Debug mode** on, confirm that the server log shows `[debug/image/spicyapi] final request payload` without the key. 5. Generate a portrait-shaped image, such as a character avatar, and confirm the result is portrait-shaped. 6. Pick an `/edit` model, such as `alibaba/qwen-image-2.1/edit`, and generate a scene illustration that has a character reference. Confirm the reference is used. Repeat with a character whose avatar file is over 1 MB. The image should still generate, and the server log should show no SpicyAPI 413 or 400 error. 7. Open an image connection whose service is **OpenAI (DALL-E)** and whose Base URL is on `spicyapi.ai`. Switch its service to **SpicyAPI** and confirm that **Test Image** now works. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Updated `docs/media/image-providers.md`. The `[docs-i18n]` follow-up is #7491. Per the 2026-10-12 policy, `CHANGELOG.md` is untouched, and the release note comes from **What changed** above. ## UI evidence (if applicable) None captured. The only UI change is one more card in the existing image service grid, plus a key link. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added SpicyAPI as an image-generation provider, with model selection, connection testing, and model discovery. * Added support for provider-specific image settings, task polling and resumption, and reference images on compatible edit models. * Added SpicyAPI setup guidance and API-key access in the connection editor. Oversized reference images are reduced to meet provider limits. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:07:13 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7757
No description provided.