> ## Documentation Index
> Fetch the complete documentation index at: https://docs.comfy.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Submit a Kling 4.0 image-to-video task in Kling's native shape.

> Optional provider-native alternative to `/v2/models/kling/kling-4.0`: the body is Kling's own image-to-video request and the answer is Kling's own task response shape. Poll the task on `GET /v2/native/kling/tasks`. Admission, limits and billing are the same as for the text-to-video submit, at the Kling 4.0 Router list price. `callback_url` and `external_task_id` are never forwarded to Kling, so poll by the task id the submit returns (`data.id`). Only `application/json` bodies are accepted. This pass-through is enabled per workspace; where it is not enabled the route answers `404`.



## OpenAPI

````yaml /router-openapi.yaml post /v2/native/kling/image-to-video/kling-4.0
openapi: 3.0.2
info:
  title: Comfy Router
  description: >-
    Comfy Router's public contract: the model catalog and the model-ID-addressed
    invocation routes, with the error buckets they return. Projected from the
    canonical Comfy API contract.
  version: '1.0'
servers:
  - url: https://api.comfy.org
security: []
tags:
  - name: Comfy Router
    description: Comfy Router's canonical, model-ID-addressed routes.
paths:
  /v2/native/kling/image-to-video/kling-4.0:
    post:
      tags:
        - Comfy Router
      summary: Submit a Kling 4.0 image-to-video task in Kling's native shape.
      description: >-
        Optional provider-native alternative to `/v2/models/kling/kling-4.0`:
        the body is Kling's own image-to-video request and the answer is Kling's
        own task response shape. Poll the task on `GET /v2/native/kling/tasks`.
        Admission, limits and billing are the same as for the text-to-video
        submit, at the Kling 4.0 Router list price. `callback_url` and
        `external_task_id` are never forwarded to Kling, so poll by the task id
        the submit returns (`data.id`). Only `application/json` bodies are
        accepted. This pass-through is enabled per workspace; where it is not
        enabled the route answers `404`.
      operationId: createRouterNativeKlingImageToVideo
      requestBody:
        description: Kling's native Kling 4.0 image-to-video request.
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/KlingV4Image2VideoRequest'
      responses:
        '200':
          description: OK - the task-creation response, in Kling's own shape.
          headers:
            X-Comfy-Request-Id:
              $ref: '#/components/headers/RouterRequestIdHeader'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KlingV2CreateTaskResponse'
        '400':
          $ref: '#/components/responses/RouterNativeRequestError'
        '401':
          $ref: '#/components/responses/RouterNativeRequestError'
        '403':
          $ref: '#/components/responses/RouterNativeRequestError'
        '404':
          $ref: '#/components/responses/RouterNativeRequestError'
        '413':
          $ref: '#/components/responses/RouterRequestError'
        '415':
          $ref: '#/components/responses/RouterRequestError'
        '429':
          $ref: '#/components/responses/RouterNativeRequestError'
        '500':
          $ref: '#/components/responses/RouterNativeRequestError'
        '503':
          $ref: '#/components/responses/RouterNativeRequestError'
        default:
          $ref: '#/components/responses/RouterNativeRequestError'
      security:
        - BearerAuth: []
        - ApiKeyAuth: []
components:
  schemas:
    KlingV4Image2VideoRequest:
      type: object
      description: >-
        Request body for a Kling 4.0 image-to-video generation from first,
        middle and last frame images. The aspect ratio follows the images. The
        prompt is a `contents` item of type "prompt"; a top-level `prompt` is
        refused rather than ignored. `settings.duration` and
        `settings.resolution` are required so the request never falls back to
        Kling's own defaults, which are the most expensive configuration.
      required:
        - contents
        - settings
      properties:
        contents:
          type: array
          minItems: 1
          maxItems: 11
          description: >-
            The prompt and up to 10 frame images. Each item's type is one of
            "prompt", "first_frame", "middle_frame" or "last_frame".
          items:
            $ref: '#/components/schemas/KlingV4Content'
        settings:
          type: object
          description: Output configuration such as resolution and duration.
          required:
            - duration
            - resolution
          properties:
            resolution:
              type: string
              enum:
                - 720p
                - 1080p
                - 4k
              description: >-
                Resolution of the generated video. One of "720p", "1080p" or
                "4k". Required.
            dynamic_range:
              type: string
              enum:
                - sdr
                - hdr
              nullable: true
              description: >-
                Dynamic range of the generated video. One of "sdr" or "hdr".
                Default "sdr". "hdr" needs a "1080p" or "4k" resolution and is
                refused at "720p". An HDR video costs more per output second. An
                explicit null is treated as absent, as the /proxy Kling 4.0
                check and Kling do.
            duration:
              type: integer
              minimum: 3
              maximum: 30
              description: Video length in seconds, 3 through 30. Required.
        options:
          type: object
          allOf:
            - $ref: '#/components/schemas/KlingV4Text2VideoOptions'
          nullable: true
          description: >-
            General configuration such as watermark options.
            `options.callback_url` and `options.external_task_id` are not
            supported on Kling 4.0; Comfy Router refuses a request that sets
            either inside `options`. An explicit null `options` is treated as
            absent.
    KlingV2CreateTaskResponse:
      type: object
      description: Response returned when a Kling 3.0 Turbo task is created.
      properties:
        code:
          type: integer
          description: Error code. 0 indicates success.
        message:
          type: string
          description: Error message.
        request_id:
          type: string
          description: Request ID generated by the system.
        data:
          type: object
          properties:
            id:
              type: string
              description: The created task ID.
            status:
              type: string
              description: >-
                Task status. One of "submitted", "processing", "succeeded" or
                "failed".
            create_time:
              type: integer
              format: int64
              description: Task creation time. Unix timestamp in milliseconds.
            update_time:
              type: integer
              format: int64
              description: Task update time. Unix timestamp in milliseconds.
            external_id:
              type: string
              description: The custom task ID for this task, if any.
    KlingV4Content:
      type: object
      description: >-
        One item of a Kling 4.0 `contents` array. The fields present depend on
        `type`: a "prompt" item carries `text`; a frame, "refer_image",
        "feature_video" or "base_video" item carries `url`; an "element" item
        carries `element_id` and a "voice" item carries `voice_id`, each with
        its own `id` so the prompt can refer to it.
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - prompt
            - first_frame
            - middle_frame
            - last_frame
            - refer_image
            - feature_video
            - base_video
            - element
            - voice
          description: >-
            Input type. Image-to-video accepts only "prompt", "first_frame",
            "middle_frame" and "last_frame", and refuses any other type. Omni
            video also accepts "refer_image", "feature_video" (a reference
            video), "base_video" (the video to edit, at most one), "element" (a
            subject, named by `element_id`) and "voice" (a voice, named by
            `voice_id`). Kling 4.0 Flash, both on its /proxy image-to-video and
            omni-video routes and as the Comfy Router id kling/kling-4.0-flash,
            takes a narrower set than Kling 4.0: "prompt" and "first_frame" for
            image-to-video, and "prompt", "first_frame", "refer_image",
            "feature_video", "base_video" and "element" for omni video, with no
            "voice".
        text:
          type: string
          description: >-
            Text prompt, when type is "prompt". Up to 26,000 English characters
            or 11,000 non-English characters; comfy-api enforces 1 to 26,000
            characters, and Kling itself refuses longer non-English text. Refer
            to another item by writing @ followed by that item's `id`: with an
            element item whose `id` is "hero" and a voice item whose `id` is
            "narrator", write for example "@hero walks into the room and
            @narrator says hello".
        url:
          type: string
          description: >-
            Image or video URL, when type is a frame, "refer_image",
            "feature_video" or "base_video". Images may also be Base64. Images
            are .jpg, .jpeg or .png up to 30MB, at least 300px per side, with an
            aspect ratio between 2:5 and 5:2. Videos are .mp4 or .mov up to
            300MB and 3 to 30 seconds long.
        id:
          type: string
          description: >-
            Reference ID for this input, chosen by the caller, that the prompt
            uses as @id. Must be unique within the task. Required for "element"
            and "voice".
        element_id:
          type: string
          description: >-
            Kling element ID, when type is "element". An element is a subject (a
            character or an object) that already exists on Kling; this item
            names it and does not upload it. Kling scopes element IDs to the
            Kling account that created them, so an ID created on another Kling
            account does not resolve. Up to 7 elements per omni video request. A
            video character element bills at the video-input rate; comfy-api
            cannot tell one from the `element_id`, so the estimate can count it
            at the lower rate.
        voice_id:
          type: string
          description: >-
            Kling voice ID, when type is "voice": a Kling preset voice or a
            custom voice. Kling scopes custom voice IDs to the Kling account
            that created them. Up to 3 voices per omni video request. Kling 4.0
            Flash (its /proxy routes and the Router id kling/kling-4.0-flash)
            does not accept voice items.
    KlingV4Text2VideoOptions:
      type: object
      additionalProperties: false
      x-go-type: KlingV2Options
      description: >-
        General configuration such as watermark options. `options.callback_url`
        and `options.external_task_id` are not supported on Kling 4.0; Comfy
        Router refuses a request that sets either inside `options`. A top-level
        `callback_url` or `external_task_id` is not part of this schema and is
        removed before the request reaches Kling.
      properties:
        watermark_info:
          type: object
          nullable: true
          description: >-
            Whether to generate watermarked results simultaneously. Custom
            watermarks are not supported. An explicit null is treated as absent,
            as the /proxy Kling 4.0 check and Kling do.
          properties:
            enabled:
              type: boolean
              description: >-
                true means generate watermarked result, false means do not
                generate. Default false.
    RouterErrorType:
      type: string
      description: >-
        Coarse, machine-readable bucket for a Router failure, mirrored on the
        `X-Comfy-Error-Type` response header so a caller can branch without
        parsing the body. The set is closed at twenty-five values: the seven
        request-level buckets `invalid_input`, `content_policy_violation`,
        `provider_error`, `provider_timeout`, `insufficient_credits`,
        `budget_exceeded` and `model_not_found`, plus the transport-level
        `unauthorized`, `forbidden`, `concurrency_limit_exceeded`,
        `client_disconnected`, `internal_error`, `deadline_exceeded`,
        `not_enabled`, `service_unavailable`, `budget_check_unavailable`,
        `rate_limited`, `cancelled`, `queue_timeout`, `request_not_found`,
        `queue_backlog_full` and `result_expired`, plus the request-level
        `byok_credential_rejected`, `no_output` and `persist_outputs_forbidden`.
        Closed describes the set as documented today, not a bound that holds
        forever: the set is expected to grow, which is why this is deliberately
        a plain string and not an `enum`, so a client must treat an unrecognised
        value as `internal_error` rather than switch exhaustively over the list
        above and break on the next addition.
      example: invalid_input
      x-comfy-error-types:
        - value: invalid_input
          tier: request
          meaning: >-
            The request was rejected before it reached the model - a malformed
            body, a malformed or expired pagination cursor, an input the model's
            own schema does not accept, or an `Idempotency-Key` that cannot
            serve this request (already used for a different request - the
            method, the path and query, or the body differ - or already consumed
            by a call whose response cannot be replayed). Sent with `409` in the
            key cases and with `400`/`422` in the others; the status says which,
            and the key cases are the ones answered by using a new key rather
            than by editing the request.
        - value: content_policy_violation
          tier: request
          meaning: >-
            The provider refused the request on content-policy grounds. A
            refusal of the caller's input is deterministic: re-sending the same
            input will be refused again. On the synchronous route, when Router
            can tell that the provider refused the model's own generated output
            instead, `detail` says so and what may succeed: a changed prompt or
            references, or for some providers the same input retried. The queued
            collect says so only for the providers whose same input may succeed
            on a retry.
        - value: provider_error
          tier: request
          meaning: >-
            The partner provider reported a failure of its own, or returned a
            response Router could not interpret as a result.
        - value: provider_timeout
          tier: request
          meaning: >-
            The partner provider did not answer within its deadline. This bucket
            is the provider timing out and never Router's own server deadline,
            which is reported as `deadline_exceeded` - the two share `504` and
            are separated because they name different causes: this one says the
            partner failed, that one says Comfy stopped holding the connection.
        - value: insufficient_credits
          tier: request
          meaning: The calling workspace does not have enough credits to run the model.
        - value: budget_exceeded
          tier: request
          meaning: A hard spend cap has been reached. The HTTP status is 402.
        - value: budget_check_unavailable
          tier: transport
          meaning: >-
            A hard spend cap could not be checked. Retry a 503 after the
            Retry-After delay.
        - value: model_not_found
          tier: request
          meaning: >-
            The `{provider}/{model}` ID names no model Router can run: an
            unknown provider, an unenrolled id, one the catalog has retired past
            its sunset date, or a catalogued ID the provider does not currently
            serve for Comfy. A retired id's `detail` reads `<id> was retired on
            <YYYY-MM-DD>; use <successor>` when a successor is recorded and not
            withheld, or just `<id> was retired on <YYYY-MM-DD>` when it is not,
            instead of a suggestion list; the successor named for a retired id
            is always a live catalog ID you can re-point the call at, and a
            successor is dropped from `detail` either because the table records
            none, or because the recorded one is currently withheld behind an
            embargo the caller cannot see. A model whose sunset is still in the
            future is not withdrawn: it stays listed by `GET /v2/models` and
            stays runnable until the date, so a listing taken today remains the
            answer to what runs today. Otherwise `detail` carries up to three
            suggestions drawn from the models the caller is entitled to see,
            except for a catalogued ID the provider does not currently serve for
            Comfy, whose response carries no suggestions.
        - value: unauthorized
          tier: transport
          meaning: The request carried no usable credential.
        - value: forbidden
          tier: transport
          meaning: >-
            The credential is valid but is not entitled to this model or this
            operation.
        - value: concurrency_limit_exceeded
          tier: transport
          meaning: >-
            The workspace already has as many calls in flight as it is allowed;
            retry once one of them finishes. It carries one further condition on
            the run route, on a `409` rather than the `429` above: another call
            is already in flight for the `Idempotency-Key` this request
            presented. Re-send the same key after `Retry-After` seconds to
            collect that call's result.
        - value: client_disconnected
          tier: transport
          meaning: >-
            The caller closed the connection before Router could return a
            result. It is logged rather than delivered - there is no socket left
            to write it to - and it is an attribution, not a billing outcome: a
            provider generation that completed is billed regardless of whether
            the caller received the response.
        - value: internal_error
          tier: transport
          meaning: >-
            Router itself failed. It is also the value a client should treat any
            unrecognized bucket as, so a later addition to the set does not
            break a client generated before it.
        - value: deadline_exceeded
          tier: transport
          meaning: >-
            Comfy stopped holding the connection at its own configured bound
            before an answer arrived. It shares `504` with `provider_timeout`
            and the pair says which side ran out of time; this one is Comfy's
            own bound, so nothing about the request was rejected and the same
            request may be retried. It says nothing about the charge: a provider
            generation that completed is billed regardless of whether the caller
            received the response. Retry it with the same `Idempotency-Key`:
            when the provider had already accepted the generation, the retry
            collects that generation rather than dispatching another, and a
            `Retry-After` on the `504` says when to ask.
        - value: not_enabled
          tier: transport
          meaning: >-
            Comfy Router is not switched on for this caller yet. Nothing about
            the request is wrong and the model exists, which is why this is not
            `model_not_found`; it shares `403` with `forbidden` and is not the
            same thing, because `forbidden` is an entitlement decision about the
            caller while this is a state of the rollout. It is terminal: do not
            retry, and do not treat it as an outage. The one exception to "about
            the caller" is the queued submit, which also answers `not_enabled`
            for a model whose partner answers a generation directly as bytes:
            that model cannot yet be queued, so it is the model and not the
            caller that is refused, nothing is queued or charged, and the
            synchronous route `POST /v2/models/{provider}/{model}` runs it
            instead.
        - value: service_unavailable
          tier: transport
          meaning: >-
            A service Comfy Router depends on is temporarily unavailable and the
            caller did nothing wrong. Retry it with backoff: it is the one
            bucket here whose condition clears on its own, without the caller
            changing the request and without a concurrency slot freeing, which
            is what distinguishes it from the other retryable answers
            (`concurrency_limit_exceeded`, `deadline_exceeded`). It is separate
            from `internal_error` - which is a `500` and means Router itself
            failed - so a client can tell "come back shortly" from "this call is
            not going to work".
        - value: rate_limited
          tier: transport
          meaning: >-
            The caller has spent an allowance measured over a window and must
            wait for that window to roll, or the model provider throttled the
            call before starting any generation. It shares `429` with
            `concurrency_limit_exceeded` and is not the same thing: that one
            clears the moment one of the caller's own in-flight calls finishes,
            so retrying in seconds is right, whereas nothing the caller does
            drains this one early. `detail` names the window, and `Retry-After`
            the seconds to wait. On a provider's limit,
            `X-Comfy-Upstream-Status` carries its `429`, and `Retry-After`
            carries the provider's own wait only when it sent one.
        - value: cancelled
          tier: transport
          meaning: >-
            A queued request was withdrawn — through the cancel route, or by an
            operator — before it produced a result; it is terminal, and it is
            not by itself a statement about the charge. Cancelling stops Comfy
            waiting and it does not always stop the partner working, so a
            request cancelled while it was still `IN_QUEUE` was never dispatched
            and cannot be charged, whereas one cancelled after it was admitted
            may still be charged — a partner generation that completes is
            charged whether or not anyone collected it, which is why the cancel
            route calls the ask a request rather than a guarantee. It is not
            `client_disconnected`: that one says nobody is listening any more
            while a generation may still be running and billable, whereas this
            says the request itself was withdrawn. A caller polling the status
            read sees `200` with this in the body, because the request ended and
            so the read succeeded. Collecting the result of such a request
            answers `409` in Router's error envelope: that read also worked, and
            what it found is a request whose terminal state - the caller's own
            decision - leaves nothing to return. It is deliberately not `410`,
            which on that route means the result aged out of its retention
            window, and not a `5xx`, which would report the caller's own
            cancellation as a Router fault and read to a polling client as worth
            retrying.
        - value: queue_timeout
          tier: transport
          meaning: >-
            A queued request waited past its queue timeout without ever being
            admitted. Terminal, unbilled, and it never took a concurrency slot —
            the job never reached a provider. Deliberately not
            `deadline_exceeded`, which is the synchronous route's connection
            bound: a `deadline_exceeded` generation may be running and billable,
            whereas this one provably never started. It is returned under `504`,
            which it shares with `provider_timeout` and `deadline_exceeded`
            because a status can only say that a clock ran out; which clock -
            the partner's, Comfy's connection bound, or the queue's admission
            bound - is what `error_type` carries. The request itself is
            terminal, so submit a new one rather than re-reading this one.
        - value: request_not_found
          tier: transport
          meaning: >-
            The `request_id` names no request of the caller's under this model.
            It is the second of the two conditions the queued reads' `404`
            covers; the first is the `{provider}/{model}` ID resolving to no
            partner model, which is `model_not_found` and carries fuzzy model
            suggestions. It also covers the right-id / wrong-model URL the path
            shape refuses, and it is deliberately indistinguishable from a
            request in another workspace, so a probe with a guessed id learns
            nothing. A request that has merely aged out of its retention window
            is `410`, not this.
        - value: queue_backlog_full
          tier: transport
          meaning: >-
            The caller already has too many queued requests waiting to run, so
            this submit was refused. It shares `429` with
            `concurrency_limit_exceeded` and is not the same thing: that one is
            the synchronous route's answer for too many calls in flight at once,
            whereas the queue accepts a submit at that limit and parks it, and
            this bucket is the separate bound on how many a caller may leave
            waiting so that parking cannot mean enqueuing without end. It clears
            as the caller's own queued requests finish, so retry once some of
            them complete.
        - value: result_expired
          tier: transport
          meaning: >-
            The request existed and finished, but its result is no longer
            stored, so the collect has nothing to return. It is returned under
            `410` and is permanent for that id: re-reading will answer the same
            way, so do not retry it. It is deliberately not `request_not_found`,
            which would tell you the id was never valid and invite re-submitting
            a generation that has already run. Running the model again means
            submitting a new request. If Comfy could not copy a result's files
            to its own storage, the result keeps the provider's own short-lived
            link instead; such a result is served for only 5 minutes after the
            request finishes and then answers this way, so collect it promptly
            and save the output on your side. For a workspace under a
            zero-data-retention agreement, a queued request's result is not kept
            after it is delivered: it is removed shortly after the first
            collect, and an uncollected result is removed after a grace period
            once the request finishes, so store the result on your side when you
            first collect it.
        - value: byok_credential_rejected
          tier: request
          meaning: >-
            The provider rejected the key supplied for this call. It is returned
            under `401`. Check the key stored for this provider; sending the
            same key again will be refused the same way. An upstream `403` is
            the same refusal and is returned as this `401`, with the provider's
            own status on `X-Comfy-Upstream-Status`. This names the caller's
            provider key, not the caller's Comfy credential (`unauthorized`,
            `forbidden`) and not an outage of the provider (`provider_error`).
            The provider's response body is not included.
        - value: no_output
          tier: request
          meaning: >-
            The model finished without producing the image it was asked for and
            named no content policy for it, so the request is retryable, and
            `detail` says whether a retry with the same `Idempotency-Key` runs
            it again. The provider answered successfully; this is returned under
            `502` because nothing about the request was wrong, and the same
            request usually succeeds. `detail` names the model's finish reason
            when the provider gave one. When no attempt of a synchronous request
            was billed, the key is released, `detail` says so, and a retry with
            the same key runs the request again. Otherwise retry with a new
            `Idempotency-Key`; a retry with the same key does not run the
            request again. On a queued request a resubmit with the same key can
            be answered with this stored failure rather than run again, so
            resubmit with a new key. It is distinct from
            `content_policy_violation`, which says a retry of the same input is
            pointless, and from `provider_error`, which says the provider
            failed. Outside the released case it says nothing about the charge.
        - value: persist_outputs_forbidden
          tier: request
          meaning: >-
            A queued submit asked for `persist_outputs=true` from a workspace
            that has zero data retention enabled. Saving an output into the
            workspace would keep it, so such a workspace can never use the
            option. It is returned under `403`, which it shares with `forbidden`
            and `not_enabled`: it is not a judgement about the credential and
            not a rollout state, and it does not clear on its own. Nothing was
            queued and nothing was charged. Submit again without
            `persist_outputs` to run the request without saving its output, or
            ask a workspace admin about the workspace's retention setting.
    RouterNativeErrorResponse:
      description: >-
        The native pass-through's error body: `RouterErrorResponse` when the
        pass-through raised the refusal (`X-Comfy-Error-Type` is set),
        `RouterNativeKlingErrorResponse` when Kling's own error is returned,
        otherwise `RouterNativeGatewayErrorResponse`.
      anyOf:
        - $ref: '#/components/schemas/RouterErrorResponse'
        - $ref: '#/components/schemas/RouterNativeGatewayErrorResponse'
        - $ref: '#/components/schemas/RouterNativeKlingErrorResponse'
    RouterErrorResponse:
      type: object
      description: >-
        Router's request-level error body: what is returned when the request
        never reached the model, or failed for a reason the model itself did not
        report - auth, quota, an unknown model ID, or provider transport. A
        model-level validation failure has its own shape,
        `RouterValidationErrorResponse`, because flattening a FastAPI `detail[]`
        array into this `detail` string would destroy the per-field granularity
        an SDK branches on.
      properties:
        detail:
          type: string
          description: >-
            Human-readable description of the failure, safe to surface to an end
            user. Not machine-parsed - branch on `error_type` instead. For
            `model_not_found` on a retired model, `detail` reads `<id> was
            retired on <YYYY-MM-DD>; use <successor>` when a successor is
            recorded and visible to the caller, or just `<id> was retired on
            <YYYY-MM-DD>` when it is not, instead of the usual suggestion list.
            A successor named here is always a live catalog ID the call can be
            re-pointed at. A model whose sunset date is still in the future is
            not retired: it stays listed by `GET /v2/models` and stays runnable
            until that date. Like the rest of `detail`, this retirement wording
            is for display and carries no compatibility guarantee.
        error_type:
          $ref: '#/components/schemas/RouterErrorType'
        upstream_detail:
          type: string
          description: >-
            A bounded, sanitized reason for an `invalid_input` rejection, or the
            provider's moderation sentence for a `content_policy_violation`. On
            the synchronous route it is the reason the model provider gave, and
            it is present only when `X-Comfy-Upstream-Status` is a provider
            `4xx` or `2xx` and one of two things holds. Either `error_type` is
            `invalid_input` - i.e. the provider refused the request as malformed
            and said why - or `error_type` is `content_policy_violation` and the
            provider's refusal is one of a fixed set of moderation sentences
            Router recognizes, such as `Azure MAI blocked this request through
            content moderation.`; Router never forwards a refusal's free-form
            text. Usually that status is a `4xx`; it is a `2xx` for a provider
            that reports a rejected generation inside a success envelope (a
            BytePlus failed-task poll is HTTP `200` with the reason in its
            body). Router reads the reason of some providers only, so branch on
            its presence. It is absent on every other failure, including
            provider `5xx`, transport failures, other content-policy refusals
            and any refusal Router raised about itself, and it mirrors the
            `X-Comfy-Upstream-Detail` header. The queued collect (`GET
            /v2/models/{provider}/{model}/requests/{request_id}`) of a run that
            ended `invalid_input` or `content_policy_violation` carries the same
            reason in this field on its first collect, which then deletes it
            from the request: a later collect normally answers the same
            `error_type` and `detail` without it, so read it from the first
            collect. That read sends neither header. The queued collect also
            uses this field for Router's own reason when Router refused the
            request before sending it to the provider and can state why in one
            sentence, which the synchronous route answers in `detail`; a refusal
            that names individual fields carries none.
        refusal_subject:
          type: string
          description: >-
            Which input or output a content-policy refusal was about, as a
            Router-level closed vocabulary: `input`, `output`, `input_text`,
            `input_image`, `input_video`, `input_audio`, `output_text`,
            `output_image`, `output_video`, `output_audio`. The bare `input` /
            `output` values name the side when the provider did not name a
            modality. Present only when `error_type` is
            `content_policy_violation` and the provider named the refused
            subject with a machine-readable code; absent otherwise. Never
            provider text. Named today for BytePlus, Runway, BFL, Gemini, Veo,
            Vertex, xAI and Wan refusals, and for the MiniMax Router's Nano
            Banana legs' Gemini refusals; a provider whose refusal does not say
            which side it was about leaves it absent. A queued request's result
            read names it too, except for BytePlus, whose queued refusals leave
            it absent. It mirrors the `X-Comfy-Refusal-Subject` header.
        budget:
          $ref: '#/components/schemas/RouterSpendBudgetDetail'
        blocking_budgets:
          type: array
          description: All exhausted hard budgets, visible to the workspace Owner.
          items:
            $ref: '#/components/schemas/RouterSpendBudgetDetail'
        denied_reason:
          type: string
          description: >-
            Billing's policy branch for a partner-node spend denial - `no_funds`
            when the billed wallet is empty, `unspecified` when the call was
            refused without a funds reading saying so. Present only when
            `error_type` is `insufficient_credits` and the deployment reports
            wallet facts; absent otherwise. A machine-readable code, not display
            text: show `detail`, branch on this.
        billed_workspace:
          $ref: '#/components/schemas/RouterBilledWorkspace'
        credential_kind:
          type: string
          description: >-
            How the refused request authenticated - `personal_api_key`,
            `team_api_key`, `personal_session` or `team_session`. Answers "which
            credential do I switch to bill the other wallet?". It is not a
            permission and grants nothing. Present only alongside
            `denied_reason`.
      required:
        - detail
        - error_type
    RouterNativeGatewayErrorResponse:
      type: object
      description: >-
        The generic error body a shared gateway check answers with on the native
        pass-through, before the request reaches it, and the body of the `404`
        for a poll of a task the caller did not submit. It carries either a
        top-level `message` or an `error` object; it has no `error_type`, and
        `X-Comfy-Error-Type` is not sent.
      properties:
        message:
          type: string
          description: Human-readable description of the refusal.
        error:
          $ref: '#/components/schemas/RouterNativeGatewayError'
    RouterNativeKlingErrorResponse:
      type: object
      description: >-
        Kling's own error body, returned as Kling sent it once a native call has
        reached Kling. `X-Comfy-Error-Type` is not sent.
      properties:
        code:
          type: integer
          description: Kling's error code.
        message:
          type: string
          description: Kling's human-readable error message.
        request_id:
          type: string
          description: Kling's request ID for the failed call.
    RouterSpendBudgetDetail:
      type: object
      required:
        - scope_kind
        - resets_at
        - set_by
      properties:
        scope_kind:
          type: string
        resets_at:
          type: string
          format: date-time
        set_by:
          type: string
        id:
          type: string
        scope_id:
          type: string
        mode:
          type: string
        limit_micro_usd:
          type: integer
          format: int64
        spent_micro_usd:
          type: integer
          format: int64
        limit_credits:
          type: integer
          format: int64
        spent_credits:
          type: integer
          format: int64
      description: >-
        The exhausted budget. Identifiers, mode and amounts are visible to
        workspace Owners.
    RouterBilledWorkspace:
      type: object
      description: >-
        The wallet a refused call would have charged, on
        `RouterErrorResponse.billed_workspace`. Answers "which wallet is empty?"
        - it is not necessarily the workspace the caller's UI currently has
        selected, and a team member's personal credential names their personal
        wallet here even while a funded team is open. Present only alongside
        `denied_reason`.
      properties:
        id:
          type: string
          description: The Cloud workspace id. Absent on the legacy rail.
        type:
          type: string
          description: >-
            `personal` or `team`. An open string: treat any other value as
            personal.
        rail:
          type: string
          description: >-
            `legacy` when the call bills the caller's pre-workspace Metronome
            customer rather than a Cloud workspace; that customer has no
            workspace id. Absent for a Cloud workspace.
      required:
        - type
    RouterNativeGatewayError:
      type: object
      description: The refusal, when the gateway check reports it as an object.
      properties:
        message:
          type: string
          description: Human-readable description of the refusal.
        code:
          type: string
          description: Machine-readable refusal code, when the check sets one.
        type:
          type: string
          description: Machine-readable refusal type, when the check sets one.
        provider:
          type: string
          description: The provider the refusal concerns, when the check names one.
  headers:
    RouterRequestIdHeader:
      description: >-
        Server-generated identifier for this call, present on every Router
        response - success, 4xx and 5xx alike, because an error response is
        exactly when a user needs an id to quote in a support request. The same
        value is written into the call's usage/audit event, which is what lets a
        complaint about a charge be joined to the charge itself instead of
        searched for by timestamp.
      required: true
      schema:
        type: string
        format: uuid
        example: 6f1a1a6e-6a53-4a5f-9d3a-2b3b0a1f9c21
    RouterErrorTypeHeader:
      description: >-
        Coarse, machine-readable bucket for the failure, set by Router on every
        error response. It carries the same value as
        `RouterErrorResponse.error_type`, and on the `422` it is the only
        machine-readable bucket, because that body is the FastAPI `detail[]`
        shape and has no `error_type` field of its own. A client can therefore
        branch on this header alone, before deciding which of the two Router
        error bodies it received.
      required: true
      schema:
        $ref: '#/components/schemas/RouterErrorType'
  responses:
    RouterNativeRequestError:
      description: >-
        An error on the native pass-through. A refusal the pass-through itself
        raises is `RouterErrorResponse`, with the bucket repeated on
        `X-Comfy-Error-Type`. A refusal from a shared gateway check that runs
        before it (missing or invalid credentials, provider availability,
        workspace provider governance) uses the gateway's generic error body
        instead and sends no `X-Comfy-Error-Type`. Once the call has reached
        Kling, Kling's answer is returned as Kling sent it, so a Kling error
        keeps Kling's own error body, also with no `X-Comfy-Error-Type`; a poll
        for a task the caller did not submit answers `404` with the generic
        error body.
      headers:
        X-Comfy-Error-Type:
          description: >-
            The Router error bucket, sent only when the pass-through itself
            raised the refusal; absent on a gateway refusal and on an answer
            returned from Kling.
          required: false
          schema:
            $ref: '#/components/schemas/RouterErrorType'
        X-Comfy-Request-Id:
          $ref: '#/components/headers/RouterRequestIdHeader'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RouterNativeErrorResponse'
    RouterRequestError:
      description: >-
        A Router request-level failure - the request never reached the model, or
        failed for a reason the model itself did not report. The body is
        `RouterErrorResponse` and the bucket is repeated on
        `X-Comfy-Error-Type`.
      headers:
        X-Comfy-Error-Type:
          $ref: '#/components/headers/RouterErrorTypeHeader'
        X-Comfy-Request-Id:
          $ref: '#/components/headers/RouterRequestIdHeader'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RouterErrorResponse'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Bearer token authentication. Normally a Firebase or Cloud JWT. A
        'comfyui-' prefixed API key is also accepted in this header: the prefix
        classifies the value as an API key and it is validated exactly as if it
        had been sent in X-API-Key.
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: >-
        API key authentication. Send the key in the X-API-Key header; keys are
        prefixed with 'comfyui-' and are generated from user account settings.
        The same 'comfyui-' key is also accepted in Authorization: Bearer (see
        BearerAuth), and when both headers carry a key, X-API-Key wins.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.