[GH-ISSUE #5746] [Feature]: Add Civitai (Orchestration API) as a native Image Generation service #3176

Closed
opened 2026-10-21 06:00:14 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @rabbit-of-caerbannog on GitHub (Sep 2, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5746

What problem does this solve?

Marinara supports a wide range of image backends, but not Civitai. Civitai is
where a lot of this userbase already goes for checkpoints, LoRAs and character
art, and its Orchestration API will run generation on Civitai's GPUs — so a
user with no local VRAM, no checkpoint downloads and no disk headroom can still
generate images, against the exact model catalogue they already browse.

Today the only way to reach it from Marinara is an out-of-tree sidecar.

Proposed solution

A native civitai image service, sitting alongside the other cloud services
(Venice, Z.AI, Atlas):

  • an entry in IMAGE_GENERATION_SOURCES (packages/shared/src/constants/model-lists.ts)
  • a case "civitai": in the generateImageUncapped dispatch and the
    EXPLICIT_IMAGE_SOURCES set (packages/server/src/services/image/image-generation.ts)
  • a civitai-image.ts service, roughly the shape of venice-image.ts but with
    a poll loop, since Orchestration is job-based rather than synchronous
  • connection-test and model-fetch branches in connections.routes.ts

As far as I can tell this needs no new connection type, no schema migration and
no new secret handling — Orchestration authenticates with
Authorization: Bearer <token>, which is the shape apiKeyEncrypted already
carries, and imageService is a free-form string column.

Alternatives considered

An A1111-shaped sidecar, which is what I actually run: a small local server
on :7860 that answers the four SDAPI endpoints Marinara calls
(/sdapi/v1/options, /sdapi/v1/sd-models, /sdapi/v1/txt2img,
/sdapi/v1/img2img) and translates each request into a Civitai workflow.

This works today with an unmodified Marinara, and I want to note that it works
because of choices already made here — the top-level model field added for
non-A1111 SDAPI routers (#2817), inferImageSource treating :7860 as
automatic1111, and automatic1111 being in LOCAL_IMAGE_BACKENDS so loopback
URLs pass the SSRF guard. So this is not a bug report; the escape hatch is real
and it's good.

It's just a second process to run, and it can only express what the A1111 API
can express.

Additional context

I'm not claiming this work and I'm not planning to open a PR — I'm staying
on the sidecar. I'm filing this so the field notes are on the record for
whoever picks it up, if anyone does. Everything below is something I got wrong
first and fixed against the live API.

Traps in the Civitai Orchestration API

  1. sourceImageDenoiseStrenght. The denoise field is misspelled in
    Civitai's API. Spelling it ...Strength is silently ignored and you get the
    default denoise, which looks like "img2img isn't respecting my strength
    slider" rather than a typo.

  2. There is no img2img endpoint. A textToImage step with sourceImage
    set is the img2img path. sourceImage accepts a URL, a data URI or raw
    base64. Worth knowing that Marinara sends init_images[0] as either a bare
    base64 string or a data: URL depending on how the reference reached the
    request, so it needs normalising.

  3. Dimensions must be divisible by 64. Anything else is rejected outright.
    This bites Marinara specifically: the default background/game size is
    1280x720, and 720 is not a multiple of 64. Snap to the nearest multiple.

  4. allowMatureContent is a body field on the workflow. There is a query
    parameter of the same name and it is ignored. Setting only the query param
    gets you safe-mode results with no error to explain why.

  5. Polling: unknown status means "keep waiting", not "failed". Only treat
    succeeded/failed/expired/canceled/cancelled as terminal. I
    originally treated anything unrecognised as a failure and it broke on
    preparing. Statuses get added over time, so an allowlist of terminal
    states is the safe read.

  6. Tolerate transient poll failures. A 5xx or a dropped connection while
    polling does not mean the job died — it's still running on Civitai's side.
    Swallow it and retry until your deadline; only let 4xx (bad id, auth)
    propagate. Aborting on the first hiccup kills jobs that would have finished.

  7. Result URLs 301 before the blob. Follow redirects, and keep the
    Authorization header on. Also gate on the image's available flag before
    downloading.

  8. outputFormat defaults to jpeg. Marinara hardcodes image/png on every
    A1111-shaped reply, so it's worth asking for png explicitly to keep the
    declared type honest.

  9. LoRA weights parse from the right. Using the A1111 <lora:NAME:weight>
    convention with a Civitai AIR as the name means the name itself contains
    colons (urn:air:sdxl:lora:civitai:1234@5678). Split the weight off the
    right-hand side, not the first colon.

  10. The scheduler enum is not the A1111 sampler list. Several common A1111
    sampler names are rejected rather than approximated, so they need mapping
    to a near neighbour before the request goes out.

Cost note

Generation spends Buzz, and mature requests bill against yellow (purchased)
Buzz while safe ones use blue (free) Buzz. That's a per-user billing
consideration, same category as NovelAI's Anlas.

References

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @rabbit-of-caerbannog on GitHub (Sep 2, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5746 ## What problem does this solve? Marinara supports a wide range of image backends, but not Civitai. Civitai is where a lot of this userbase already goes for checkpoints, LoRAs and character art, and its Orchestration API will run generation on Civitai's GPUs — so a user with no local VRAM, no checkpoint downloads and no disk headroom can still generate images, against the exact model catalogue they already browse. Today the only way to reach it from Marinara is an out-of-tree sidecar. ## Proposed solution A native `civitai` image service, sitting alongside the other cloud services (Venice, Z.AI, Atlas): - an entry in `IMAGE_GENERATION_SOURCES` (`packages/shared/src/constants/model-lists.ts`) - a `case "civitai":` in the `generateImageUncapped` dispatch and the `EXPLICIT_IMAGE_SOURCES` set (`packages/server/src/services/image/image-generation.ts`) - a `civitai-image.ts` service, roughly the shape of `venice-image.ts` but with a poll loop, since Orchestration is job-based rather than synchronous - connection-test and model-fetch branches in `connections.routes.ts` As far as I can tell this needs no new connection type, no schema migration and no new secret handling — Orchestration authenticates with `Authorization: Bearer <token>`, which is the shape `apiKeyEncrypted` already carries, and `imageService` is a free-form string column. ## Alternatives considered **An A1111-shaped sidecar**, which is what I actually run: a small local server on `:7860` that answers the four SDAPI endpoints Marinara calls (`/sdapi/v1/options`, `/sdapi/v1/sd-models`, `/sdapi/v1/txt2img`, `/sdapi/v1/img2img`) and translates each request into a Civitai workflow. This works today with an unmodified Marinara, and I want to note that it works *because of* choices already made here — the top-level `model` field added for non-A1111 SDAPI routers (#2817), `inferImageSource` treating `:7860` as `automatic1111`, and `automatic1111` being in `LOCAL_IMAGE_BACKENDS` so loopback URLs pass the SSRF guard. So this is not a bug report; the escape hatch is real and it's good. It's just a second process to run, and it can only express what the A1111 API can express. ## Additional context **I'm not claiming this work and I'm not planning to open a PR** — I'm staying on the sidecar. I'm filing this so the field notes are on the record for whoever picks it up, if anyone does. Everything below is something I got wrong first and fixed against the live API. ### Traps in the Civitai Orchestration API 1. **`sourceImageDenoiseStrenght`.** The denoise field is misspelled in Civitai's API. Spelling it `...Strength` is silently ignored and you get the default denoise, which looks like "img2img isn't respecting my strength slider" rather than a typo. 2. **There is no img2img endpoint.** A `textToImage` step with `sourceImage` set *is* the img2img path. `sourceImage` accepts a URL, a data URI or raw base64. Worth knowing that Marinara sends `init_images[0]` as either a bare base64 string or a `data:` URL depending on how the reference reached the request, so it needs normalising. 3. **Dimensions must be divisible by 64.** Anything else is rejected outright. This bites Marinara specifically: the default background/game size is 1280x720, and 720 is not a multiple of 64. Snap to the nearest multiple. 4. **`allowMatureContent` is a body field on the workflow.** There is a query parameter of the same name and it is ignored. Setting only the query param gets you safe-mode results with no error to explain why. 5. **Polling: unknown status means "keep waiting", not "failed".** Only treat `succeeded`/`failed`/`expired`/`canceled`/`cancelled` as terminal. I originally treated anything unrecognised as a failure and it broke on `preparing`. Statuses get added over time, so an allowlist of terminal states is the safe read. 6. **Tolerate transient poll failures.** A 5xx or a dropped connection while polling does not mean the job died — it's still running on Civitai's side. Swallow it and retry until your deadline; only let 4xx (bad id, auth) propagate. Aborting on the first hiccup kills jobs that would have finished. 7. **Result URLs 301 before the blob.** Follow redirects, and keep the `Authorization` header on. Also gate on the image's `available` flag before downloading. 8. **`outputFormat` defaults to jpeg.** Marinara hardcodes `image/png` on every A1111-shaped reply, so it's worth asking for `png` explicitly to keep the declared type honest. 9. **LoRA weights parse from the right.** Using the A1111 `<lora:NAME:weight>` convention with a Civitai AIR as the name means the name itself contains colons (`urn:air:sdxl:lora:civitai:1234@5678`). Split the weight off the right-hand side, not the first colon. 10. **The scheduler enum is not the A1111 sampler list.** Several common A1111 sampler names are rejected rather than approximated, so they need mapping to a near neighbour before the request goes out. ### Cost note Generation spends Buzz, and mature requests bill against yellow (purchased) Buzz while safe ones use blue (free) Buzz. That's a per-user billing consideration, same category as NovelAI's Anlas. ### References - Orchestration getting started: https://developer.civitai.com/orchestration/guide/getting-started - API reference: https://developer.civitai.com/orchestration/reference/ ## Template check - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@Gunterlie commented on GitHub (Sep 2, 2026):

I will close this for now, we will revisit when the Lead Dev is back from Vacation :)

See also Info here: https://github.com/Pasta-Devs/Marinara-Engine/issues/5779

<!-- gh-comment-id:5514607138 --> @Gunterlie commented on GitHub (Sep 2, 2026): I will close this for now, we will revisit when the Lead Dev is back from Vacation :) See also Info here: https://github.com/Pasta-Devs/Marinara-Engine/issues/5779
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#3176
No description provided.