> ## 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.

# Run your first workflow

> Run a sample workflow on Comfy Cloud and download its output with Python or TypeScript.

Run a complete workflow from code and save its output as `first-result.png`. This sample creates a **512 × 512 solid blue image** using two built-in nodes. It verifies authentication, workflow execution, and output download without requiring a model, an input image, or custom nodes.

To generate an image by calling a hosted model directly, start with the [Comfy Router quickstart](/development/comfy-router/quickstart).

## Before you start

* A [Comfy API key](/development/api-development/getting-an-api-key).
* A [paid Comfy Cloud subscription](/development/deploy/cloud). Cloud workflow API access is not included in the free tier.
* Python 3.10 or newer, or Node.js 22.18 or newer for the TypeScript example.

This guide uses Comfy Cloud, the SDKs' default target. If you previously set `COMFY_BASE_URL`, unset it to use Cloud. For an existing Comfy API deployment or a self-hosted instance, see [Choosing a base URL](/development/api-development/sdks#choosing-a-base-url).

## 1. Download the sample

Create a folder for the example. Download [workflow\_api.json](/files/api-first-result/workflow_api.json) and the script for your language into that folder:

* [Python: first\_workflow.py](/files/api-first-result/first_workflow.py)
* [TypeScript: first\_workflow.mts](/files/api-first-result/first_workflow.mts)

The workflow is already in API format. Node `"1"` creates the blue image and node `"2"` saves it. The scripts read outputs from that exact SaveImage node, so you do not need to find or edit a node ID.

## 2. Install the SDK and set your key

Open a terminal in the folder where you saved the files.

<CodeGroup>
  ```bash Python theme={null}
  python -m venv .venv
  source .venv/bin/activate
  python -m pip install comfy-sdk
  ```

  ```bash TypeScript theme={null}
  npm init -y
  npm install @comfyorg/sdk
  ```
</CodeGroup>

On Windows, activate the Python environment with `.venv\Scripts\Activate.ps1` in PowerShell.

Set your key in the same terminal:

<CodeGroup>
  ```bash macOS / Linux theme={null}
  export COMFY_API_KEY="comfyui-your-key"
  ```

  ```powershell Windows PowerShell theme={null}
  $env:COMFY_API_KEY = "comfyui-your-key"
  ```
</CodeGroup>

Keep your API key in your server environment. Do not include it in browser code or commit it to source control.

## 3. Run and view the result

<CodeGroup>
  ```bash Python theme={null}
  python first_workflow.py
  ```

  ```bash TypeScript theme={null}
  node first_workflow.mts
  ```
</CodeGroup>

The script submits the workflow, waits for it to finish, and downloads the image. When it prints `Saved` followed by a path, open `first-result.png` from that location. You should see a solid blue square. Running the sample again replaces that local file.

<Note>
  This is a workflow connection check. It does not use a generative model. The same submit, wait, and download steps work with your own generation workflows.
</Note>

### If the request fails

* **Missing key or unauthorized:** check that `COMFY_API_KEY` is set in the terminal running the script and contains an active key.
* **Access or credit error:** check your Cloud subscription and available credits before retrying.
* **Workflow file not found:** keep `workflow_api.json` next to the downloaded script.
* **Unexpected endpoint:** check `COMFY_BASE_URL`. Unset it for this Cloud example.

For error handling and job progress, see the [SDK guide](/development/api-development/sdks).

## 4. Run your own generation workflow

Build or choose a workflow in the ComfyUI editor, run it successfully there, and [export it in API format](/development/api-development/workflow-api-format). Replace `workflow_api.json` with your export and update `get_outputs("2")` in Python or `getOutputs("2")` in TypeScript to use your workflow's SaveImage node ID. Check that the target environment has the models and custom nodes your workflow uses.

To host workflows with your own models and custom nodes, create a [Comfy API deployment](/development/serverless/overview). To change workflow inputs, upload files, or watch progress, continue to [Comfy SDKs](/development/api-development/sdks).
