--- title: TypeScript | FLORA API description: Install the FLORA TypeScript SDK and run your first Technique. --- The `@flora-ai/flora` SDK is a thin, type-safe wrapper around the [FLORA REST API](/api/index.md). It runs in Node 18+ and the browser (server-only — never ship an API key to the client). ## Install Terminal window ``` npm install @flora-ai/flora # pnpm add @flora-ai/flora # yarn add @flora-ai/flora ``` ## Configure Set your API key in the environment: Terminal window ``` export FLORA_API_KEY="sk_live_XXXX" ``` The SDK reads it automatically: ``` import Flora from '@flora-ai/flora'; const client = new Flora({ apiKey: process.env['FLORA_API_KEY'], }); ``` You can also pass the key explicitly: `new Flora({ apiKey: 'sk_live_XXXX' })`. ## First run, end to end The full discover → run → poll loop in one snippet: ``` import Flora from '@flora-ai/flora'; const client = new Flora({ apiKey: process.env['FLORA_API_KEY'] }); // 1. List your Techniques for await (const technique of client.techniques.list()) { console.log(technique.slug, technique.name); } // 2. Inspect a specific Technique's inputs const technique = await client.techniques.retrieve('thumbnail-v3'); console.log(technique.inputs); // 3. Start a run const run = await client.techniques.runs.create('thumbnail-v3', { inputs: [ { id: 'prompt', type: 'text', value: 'Smart living, simple — warm minimalism' }, ], mode: 'async', }); // 4. Poll until completion let status = run.status; let result = run; while (status === 'pending' || status === 'running') { await new Promise((r) => setTimeout(r, 2000)); result = await client.techniques.runs.retrieve(run.runId, { techniqueId: 'thumbnail-v3', }); status = result.status; } if (status === 'completed') { for (const output of result.outputs) { console.log(output.url); } } else { console.error('Run failed:', result.errorMessage); } ``` ## Pagination `list()` returns an async iterator that auto-paginates: ``` for await (const technique of client.techniques.list({ limit: 10 })) { // iterates across all pages } ``` For a single page: ``` const page = await client.techniques.list({ limit: 10 }); console.log(page.data, page.hasNextPage); ``` ## Idempotency Pass `idempotency_key` on any mutation that you might retry: ``` const run = await client.techniques.runs.create('thumbnail-v3', { inputs: [...], mode: 'async', idempotency_key: `q3-thumb-${marketCode}`, }); ``` Same key + same body = same run. See [Idempotency](/platform/idempotency/index.md) for the full semantics. ## Errors The SDK throws typed errors with status codes and request IDs: ``` import Flora, { APIError } from '@flora-ai/flora'; try { await client.techniques.runs.create('thumbnail-v3', { inputs: [], mode: 'async' }); } catch (err) { if (err instanceof APIError) { console.error(err.status, err.code, err.message, err.requestID); } else { throw err; } } ``` See [Errors](/platform/errors/index.md) for every code and recovery guidance. ## What’s next - **[Authentication](/platform/authentication/index.md)** — keys, rotation, security. - **[Recipes](/recipes/generate-a-grid/index.md)** — common end-to-end patterns in code. - **[API Reference](/api/typescript/index.md)** — every method, parameter, and response type.