> ## Documentation Index
> Fetch the complete documentation index at: https://fal.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent SDK quickstart

> Install the TypeScript SDK, run your first task, and read the result.

Generate an image from a Node.js application. Use Node.js 22.22 or later for these examples.

## Install

The Agent SDK is in alpha. Install the version used in this guide:

```bash theme={null}
npm install @fal-ai/client@1.11.0-alpha.4
npm install --save-dev tsx
```

## Configure your credentials

Create a fal API key with the **AGENT** permission preset.
Set your API key in the environment:

```bash theme={null}
export FAL_KEY="YOUR_API_KEY"
```

Replace `YOUR_API_KEY` with your key.
The SDK sends Agent requests to `https://fal.ai/api/agent-v2/sdk`.
Keep the API key on your server. Do not include it in browser code.

## Create a client

Create `client.ts`. The other examples in this guide import this client.

```ts theme={null}
import { createFalClient } from "@fal-ai/client";

export const agent = createFalClient().agent;
```

## Run your first task

Create `agent.mts` next to `client.ts`:

```ts theme={null}
import { agent } from "./client.ts";

const response = await agent.run({
  input:
    "Generate a product photo of a blue ceramic mug.",
});

console.log(response.status, response.output_text);
console.log(
  response.artifacts,
  response.pending_inputs,
  response.error,
);
```

Run the file:

```bash theme={null}
npx tsx agent.mts
```

`run()` returns when execution stops or needs user input. Check `status` and `fal.phase` before using the result.
Media generation can incur charges.

## Stream progress

Use `stream()` to observe updates as the task runs:

```ts theme={null}
import { agent } from "./client.ts";

for await (const response of agent.stream({
  input: "Photograph a blue mug.",
})) {
  console.log(response.output_text);
}
```

Each update contains the complete response snapshot.
Replace the displayed text on each update instead of appending it.
This example starts a new task. Use `responses.stream(responseId)` to observe an existing task.

## Continue the conversation

Replace `CONVERSATION_ID` with `response.fal.conversation_id` from the earlier response:

```ts theme={null}
import { agent } from "./client.ts";

const response = await agent.run({
  conversation: "CONVERSATION_ID",
  input:
    "Make another version with warmer lighting.",
});

console.log(response.output_text);
```

A follow-up creates a new response in the same conversation.
To answer a pending question, use `responses.answer()` with the existing response ID.

## Next steps

* [Save response IDs and recover interrupted requests](/docs/documentation/agent/sdk/responses).
* [Answer questions and approvals](/docs/documentation/agent/sdk/inputs).
* [Edit and run a plan](/docs/documentation/agent/sdk/plans).
* [Reuse generated media](/docs/documentation/agent/sdk/media).
