# ComfyUI

Install the Liquid nodes in ComfyUI, save your key one time, and buy images or video inside a workflow. Each paid node has a price cap on each run.

| Node                        | What it does                                            | What you pay for                 |
| --------------------------- | ------------------------------------------------------- | -------------------------------- |
| **Liquid Image (paid API)** | Sends the prompt to `/v1/images/generations`.           | The images returned.             |
| **Liquid Video (paid API)** | Sends the prompt to `/v1/videos` and waits for the job. | Each second of the video.        |
| **Liquid Video Job**        | Gets the video of a job again.                          | Nothing. It makes no new charge. |

## Before you start

- A workspace with a balance and a `spend` key. See [API keys](https://inference.ai.exchange/docs/keys.md).
- ComfyUI 0.3.45 or newer, with ComfyUI-Manager. The desktop app includes the Manager.

## 1. Install the node

Open **Manager**, then **Custom Nodes Manager**. Search for this name and install it:

```
Liquid Inference
```

Restart ComfyUI. With `comfy-cli`, use this command:

```bash
comfy node install liquid-inference
```

The source is [architect-xyz/comfyui-liquid-inference](https://github.com/architect-xyz/comfyui-liquid-inference).

## 2. Set the key

Open **Settings**, then **Liquid Inference**. Paste the key into **API key** and click **Save**:

```
sk-liquid-...
```

The nodes have no key input, because ComfyUI writes input values into the metadata of each saved image. The server keeps the key in a file that only your system user can read.

On a server without a browser, set `LIQUID_API_KEY` before you start ComfyUI. The variable has priority over the saved key.

## 3. Buy images

1. Double-click the canvas and search for **Liquid Image**.
2. Write a prompt, and select a model and a cap.
3. Connect `images` to **Save Image**.

The node also gives the job ID and a short receipt as text.

- **model** lists the image models on the book. The node refreshes the list each minute.
- **size** lists the sizes that at least one offer declared. With `auto`, the node sends no `size` and each seller uses its default. An explicit size goes only to the offers that declared it.

## 4. Buy a video

1. Double-click the canvas and search for **Liquid Video**.
2. Write a prompt, and select a model and a cap.
3. Connect `video` to **Save Video**.

**Templates** has examples for both nodes.

- **model** lists the video models on the book.
- **size** and **seconds** list the values that at least one offer declared. With `auto`, the node sends no field. For `seconds`, the exchange then uses the shortest length that an offer declares. The charge is the price of that length.
- **retention** defaults to `none`, which excludes providers that can keep your content. Select `allowed` only if the provider can keep your prompt, start image and video.
- `start_image` starts the video from an image. The node sends the first image of the batch as a PNG in `input_reference`. Only a model that reads image input can take it. Use an image with the shape of the size, because a seller can crop a different shape.

### How the wait works

The node reads the job status every 5 seconds and waits 30 minutes at most. It then gets the file from `/v1/videos/{id}/content`. It tries a failed status read or download again, because these buy nothing.

A stop in ComfyUI stops the wait, not the job. The exchange cannot cancel a video job and charges for it when it is complete. To get the video, paste the job ID into a **Liquid Video Job** node. The seller keeps the file until `expires_at` in the receipt.

## Base URL

To use a different exchange, set **Base URL** in **Settings → Liquid Inference**, or set `LIQUID_BASE_URL`:

```
https://router.inference.ai.exchange/v1
```

## Limits and notes

- The cap limits each run of a node, not a workflow or a queue. Three Liquid nodes with a cap of $0.05 can cost $0.15 for each run. To limit total spend, set a spending limit on the key. See [API keys](https://inference.ai.exchange/docs/keys.md).
- A paid node never sends a purchase again by itself. If the connection stops, the error gives the `Idempotency-Key`, so you can find the job on the **Receipts** page.
- The prompt goes to the seller that wins the auction. It can be a different company for each run.

## Troubleshooting

| Symptom                                                    | Cause and fix                                                                                                                   |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `No Liquid Inference API key`                              | Save the key in **Settings → Liquid Inference**, or set `LIQUID_API_KEY` and restart ComfyUI.                                   |
| `401`                                                      | The key is empty, wrong or expired. Save it again.                                                                              |
| `402 insufficient_balance`                                 | Add credit, or check the spend limit of the key.                                                                                |
| `400 unsupported_parameter`                                | No offer for the model takes the value in `param`, usually `size`. Set **size** to `auto`.                                      |
| `503` with `cap_exceeds_buyer_cap`                         | Each offer costs more than the cap. Increase **cap_usd**, or the spend limit of the key.                                        |
| `503 model_unavailable`                                    | The model has sellers, but none can take a job now. Try again in a minute, or select a different model.                         |
| `503 provider_failed`                                      | The seller failed before it made an image. You were not charged. Queue again. A run 30 seconds later can go to the same seller. |
| `410 video_expired`; the error says the outcome is unknown | The seller deleted the file; or the connection stopped. Look for the job on the **Receipts** page before you queue again.       |
| A video job failed                                         | The seller did not make the video. You were not charged. Queue again, or select a different model.                              |
| The node stopped waiting for a video                       | The job continues and is charged. Paste the job ID into a **Liquid Video Job** node.                                            |

See [Errors](https://inference.ai.exchange/docs/errors.md) for all error codes. See also [Modalities](https://inference.ai.exchange/docs/modalities.md) and [Video generation](https://inference.ai.exchange/docs/video-generation.md).
