Generate a grid
Run a FLORA Technique several times from one brief with the API, wait for every run, and lay the results out as a 3×3 grid.
The most common FLORA API job: take a brief, run a Technique several times, and get back a set of variants to choose from. A 3×3 grid of nine is the classic shape. Use this recipe for one brief; for many briefs from a spreadsheet, use Batch from a CSV.
What you'll build: a script that starts nine runs of a Technique in parallel and returns their image URLs.
TypeScript
Save as grid.mts and run with npx tsx grid.mts. The script fills the Technique's first text input with the brief; if your Technique needs other inputs, add them from technique.inputs.
import { FloraClient } from "@flora-ai/flora"
const client = new FloraClient()
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
async function generateGrid(slug: string, brief: string, count = 9): Promise<string[]> {
const technique = await client.techniques.retrieve({ techniqueId: slug })
const textInput = technique.inputs.find((input) => input.type === "text")
if (!textInput) throw new Error(`${slug} has no text input`)
console.log(`Estimated cost: $${(technique.run_cost * count).toFixed(2)} for ${count} runs`)
// Start every run at once
const runs = await Promise.all(
Array.from({ length: count }, () =>
client.techniques.runs.create({
techniqueId: slug,
inputs: [{ id: textInput.id, type: "text", value: brief }],
mode: "async",
}),
),
)
return waitForAll(slug, runs.map((run) => run.run_id))
}
async function waitForAll(slug: string, runIds: string[]): Promise<string[]> {
const pending = new Set(runIds)
const urls = new Map<string, string[]>()
// Each poll is one request against the workspace rate limit
const intervalMs = Math.max(15_000, 2_000 * runIds.length)
while (pending.size > 0) {
await sleep(intervalMs)
for (const runId of [...pending]) {
const result = await client.techniques.runs.retrieve({ techniqueId: slug, runId })
if (result.status === "completed") {
urls.set(runId, (result.outputs ?? []).map((output) => output.url))
pending.delete(runId)
} else if (result.status === "failed") {
console.error(`${runId} failed: ${result.error_code} ${result.error_message ?? ""}`)
pending.delete(runId)
}
}
}
return runIds.flatMap((runId) => urls.get(runId) ?? [])
}
const urls = await generateGrid(
"your-technique-slug",
"Smart living, simple. Audience 25-40, design-conscious. Warm minimalism, soft shadows. No clip-art, no gradients.",
)
console.log(urls)CLI
Display the grid
In a React app, render the URLs as a three-column grid:
Save the grid as files
Variations
Several outputs per run. Some Techniques return more than one output per run. Check
technique.outputsand start fewer runs.Aspect ratio and other settings. If the Technique exposes an input for them, it's in
technique.inputs; pass it like any other input.Reference images. Pass image URLs as
imageUrlinputs; see Iterate on outputs.
Tips
Check the cost before you start: the total is
run_cost × count, in US dollars.Output URLs are long-lived but not permanent. Download anything you need to keep.
For more than a handful of briefs, use Batch from a CSV, which adds idempotency keys and backoff.
Related
Iterate on outputs: re-run with your favorites as references.
Upload an asset: use your own image as an input.
Batch from a CSV: many runs from structured input.
Last updated
Was this helpful?