> For the complete documentation index, see [llms.txt](https://docs.flora.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flora.ai/api/recipes/iterate-on-outputs.md).

# Iterate on outputs

Re-run a FLORA Technique with your favorite earlier outputs as image references, so new variants build on what already works.

After a grid, the natural next step is "more like #4 and #7". Technique image inputs take URLs, so earlier outputs can drive new runs with no re-upload. Use this recipe after [Generate a grid](https://docs.flora.ai/api/recipes/generate-a-grid.md) when you've picked favorites.

**What you'll build:** a function that takes favorite output URLs and a direction, and runs a Technique with them as references.

## Match your Technique's inputs

Every Technique defines its own inputs, and the API rejects input IDs a Technique doesn't have. Read them first:

```ts
import { FloraClient } from "@flora-ai/flora"

const client = new FloraClient()

const technique = await client.techniques.retrieve({ techniqueId: "your-technique-slug" })
console.log(technique.inputs)
// [
//   { id: "brief", name: "Brief", type: "text" },
//   { id: "reference_1", name: "Reference 1", type: "imageUrl" },
//   { id: "reference_2", name: "Reference 2", type: "imageUrl", optional: true },
// ]
```

A Technique that takes several references has one `imageUrl` input per reference slot. Pass one URL per slot.

## TypeScript

Save as `iterate.mts` and run with `npx tsx iterate.mts`. The function fills the first text input with your direction and the image inputs, in order, with your favorites.

```ts
import { FloraClient } from "@flora-ai/flora"

const client = new FloraClient()
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))

async function iterate(slug: string, favorites: string[], direction: string): Promise<string[]> {
  const technique = await client.techniques.retrieve({ techniqueId: slug })
  const textInput = technique.inputs.find((input) => input.type === "text")
  const imageInputs = technique.inputs.filter((input) => input.type === "imageUrl")
  if (!textInput || imageInputs.length === 0) {
    throw new Error(`${slug} needs a text input and at least one image input`)
  }

  const references = favorites.slice(0, imageInputs.length)
  const run = await client.techniques.runs.create({
    techniqueId: slug,
    inputs: [
      { id: textInput.id, type: "text", value: direction },
      ...references.map((url, i) => ({ id: imageInputs[i].id, type: "imageUrl" as const, value: url })),
    ],
    mode: "async",
  })

  let result = await client.techniques.runs.retrieve({ techniqueId: slug, runId: run.run_id })
  while (result.status === "pending" || result.status === "running") {
    await sleep(15_000)
    result = await client.techniques.runs.retrieve({ techniqueId: slug, runId: run.run_id })
  }
  if (result.status === "failed") throw new Error(`${result.error_code}: ${result.error_message}`)
  return (result.outputs ?? []).map((output) => output.url)
}

// URLs from a previous run's outputs
const favorites = [
  "https://example.com/flora/run_abc123/output_3.png", // #4
  "https://example.com/flora/run_abc123/output_6.png", // #7
]

const moreLikeThese = await iterate(
  "your-technique-slug",
  favorites,
  "Keep the lighting and composition from the references. Explore copy and color.",
)
console.log(moreLikeThese)
```

If the Technique has more required image inputs than you have favorites, the run is rejected with `input_validation_error`; fill the rest or pick a Technique with optional slots. For several variants, start several runs in parallel as in [Generate a grid](https://docs.flora.ai/api/recipes/generate-a-grid.md).

## Compose iterations

The pattern repeats cleanly: iterate, pick new favorites, iterate again.

```ts
let pool = await generateGrid("your-technique-slug", "Smart living, simple. Warm minimalism.")

for (let round = 0; round < 3; round++) {
  const favorites = await pickFavorites(pool) // your own UI or CLI prompt
  pool = await iterate("your-technique-slug", favorites, "Tighten the composition.")
}
```

## Without a Technique

To iterate with a single model instead, start a [generation](https://docs.flora.ai/api/guides/generations.md) and pass the favorite's canvas node in `reference_node_ids`, or its URL in the model's image parameter (such as `image_url`, listed in `GET /models`).

## URL lifetime

Output URLs are long-lived but not permanent, so re-running this weeks later with the same URLs may fail. For long-lived workflows, either:

1. Generate again from the original brief, or
2. Download your favorites and [upload them as assets](https://docs.flora.ai/api/recipes/upload-an-asset.md), then reference those URLs.

## Related

* [Generate a grid](https://docs.flora.ai/api/recipes/generate-a-grid.md): produce the first set of options.
* [Upload an asset](https://docs.flora.ai/api/recipes/upload-an-asset.md): bring in your own reference images.
* [Batch from a CSV](https://docs.flora.ai/api/recipes/batch-from-csv.md): scale this across many inputs.
* Iterating from an AI client instead? See [Iterate on favorites](https://docs.flora.ai/mcp/recipes/iterate.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flora.ai/api/recipes/iterate-on-outputs.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
