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

# TypeScript SDK

> Use the versioned local image contract from TypeScript and JavaScript.

# TypeScript SDK

## What this lets you do

Create durable local image turns from TypeScript or JavaScript.

## What you need

* Node.js and pnpm
* A DreamLayer clone
* A running local runtime

## Steps

### 1. Install from the clone

```bash theme={null}
pnpm add ./packages/typescript-client
```

### 2. Create a local conversation

```ts theme={null}
import { readFile } from "node:fs/promises";
import { homedir } from "node:os";
import { join } from "node:path";

import { RuntimeClient } from "@dreamlayer/sdk";

const runtimeToken = (await readFile(
  join(homedir(), ".dreamlayer-runtime", "runtime-token"),
  "utf8",
)).trim();
const runtime = new RuntimeClient("http://127.0.0.1:8000", { runtimeToken });

const accepted = await runtime.createConversation({
  client_request_id: crypto.randomUUID(),
  prompt: "A glass greenhouse at dusk",
  operation: "text_to_image",
  orchestration_mode: "reference",
  aspect_ratio: "1:1",
});

await runtime.watchJob(accepted.job.job_id, job => {
  console.log(job.stage);
});
```

Run this local capability-token example only in trusted server code on the same machine as the runtime. Browser applications use `openSession` with the one-time bootstrap token from the complete URL printed by `./dreamlayer`; they must never embed the local token or a DreamLayer key in a browser bundle.

## Confirm it worked

The callback prints durable job stages and ends with `completed`, `failed`, or `cancelled`. A completed turn contains one image asset.

## Common errors

* `401`: read the current local token after starting `./dreamlayer`; do not reuse a token from another machine or state directory.
* Connection refused: start `./dreamlayer` and use its loopback origin.
* Invalid request: keep `operation` within the supported V1 operations.
* Browser key exposure: move managed API calls to trusted server code.

## Troubleshooting

Read canonical job state before retrying after a timeout or disconnect. Do not create a second logical request automatically.

## Next steps

* [Use DreamLayer WebUI](/webui)
* [Install the Image Agent MCP Server](/mcp)
* [Review DreamLayer Agent API](/agent-api)
