# Quickstart

This page takes a new account to a workflow run you can see on
`<app>.durablesdk.com`. It teaches `npx durable-sdk init`, `durable-sdk
login`, `durable-sdk apps create`, `durable-sdk deploy --prod` and
`durable-sdk logs`.

You need Node 20 or newer and a package manager. Nothing else: the
platform runs the database and the cron.

## 1. Sign up

Open [durablesdk.com/sign-up](https://durablesdk.com/sign-up) and join
with an email and a code. Your first organization is made for you (you
are its admin) on the Free tier in the `us-east` region; rename it on the
dashboard. An agent working from a key skips the browser: see
[log in with a key](#log-in-with-a-key).

## 2. Scaffold the app

```bash
npx durable-sdk init my-app
cd my-app
```

`init` judges the name under the hostname grammar (3 to 40 characters,
`a-z`, `0-9` and `-`, a letter first, no reserved word; see
[Hosting](https://durablesdk.com/docs/hosting.md#the-hostnames)), writes the template, installs
the dependencies and prints the next commands (the file list is cut
here; the CLI prints all thirty):

```text
durable-sdk init: wrote 30 files under my-app (template 0.1.0)
  package.json
  vercel.json
  tsconfig.json
  durable.config.ts
  durable.guards.ts
  platform.ts
  src/durable.ts
  src/events/catalog.ts
  src/workflows/hello.ts
  …
next:
  cd my-app
  durable-sdk login
  durable-sdk apps create my-app
  durable-sdk deploy --prod
```

The tree is the one every hosted app runs: `durable.config.ts`,
`src/workflows/hello.ts` (a ten-line keyed workflow), `src/events/catalog.ts`
(its one fact, `hello.said`), `src/listeners.ts`, the engine's handlers
under `api/`, `api/hello.ts` (an example door that executes the
workflow), `tests/hello.test.ts` and an `AGENTS.md` that tells an agent
everything. [Writing a workflow](https://durablesdk.com/docs/guide/writing-a-workflow.md) reads
`hello.ts` line by line.

Run the tests before anything is deployed: `hello.test.ts`'s three
cases (one run per intent, a failing step waits for a redrive, a crash
resumes on attempt 2) and the template's five guard files, whose lines
follow this one:

```bash
pnpm test
```

```text
 ✓ tests/hello.test.ts (3 tests)
```

## 3. Log in

```bash
durable-sdk login
```

```text
open https://durablesdk.com/cli/authorize?code=WXYZ-2345 and confirm the code WXYZ-2345
durable-sdk login: acme as durable-sdk on moe-laptop, scope deploy, expires 2027-01-27T12:04:31.000Z; stored for https://durablesdk.com
```

The browser opens when one is there. The page shows the client, the
hostname, the organization and the scope before you press Approve. The
CLI stores the key it receives under `~/.config/durable-sdk/credentials.json`
(mode 0600) and never prints it. `durable-sdk whoami` says who you are;
`durable-sdk logout` forgets the key. [Accounts and keys](https://durablesdk.com/docs/operate/accounts-and-keys.md)
has the scopes and the device flow in full.

### Log in with a key

An agent or a CI holds a key a person minted on the dashboard
(`/dashboard/keys`). Give it on stdin, never as an argument:

```bash
printf '%s' "$DURABLE_API_KEY" | durable-sdk login --with-key
```

Or set `DURABLE_API_KEY` in the environment and skip `login`: the
variable wins over the file.

## 4. Create the app

```bash
durable-sdk apps create my-app
```

```text
Creating my-app in us-east…
  database      ready
  project       ready
  first build   ready
  hostname      https://my-app.durablesdk.com
my-app is active.
```

`apps create` reserves the slug (global: one `my-app` across every
account), makes the app's database with its `preview` branch, the
project, the platform's variables and the hostname, and deploys the
template once. It writes `.durable-sdk/app.json` (`{ "app": "my-app",
"plane": "https://durablesdk.com" }`, commit it) so every later verb
knows the app. A taken slug is refused `plane.app.slug_taken`; pick
another. [Hosting](https://durablesdk.com/docs/hosting.md) says what each line made.

## 5. Deploy your tree

```bash
durable-sdk deploy --prod
```

```text
durable-sdk deploy: my-app production: 30 files, 1240 KB packed, sha256 7f3c2a1e9b4d
durable-sdk deploy: 7f3c2a1e queued
durable-sdk deploy: 7f3c2a1e building
durable-sdk deploy: 7f3c2a1e checking
durable-sdk deploy: 7f3c2a1e promoted at https://my-app.durablesdk.com
```

The build runs the migrations against the app's database before it
compiles; a production build is aliased, checked and promoted (the
default rule `auto`). Exit 0 means promoted. [Deploy](https://durablesdk.com/docs/hosting/deploy.md)
has the states, previews, `--json` and CI.

## 6. See it answer

```bash
curl https://my-app.durablesdk.com/health
```

```json
{
  "ok": true,
  "commit": "7f3c2a1e",
  "environment": "production",
  "role": "production"
}
```

Run the `hello` workflow through the example door the template ships:

```bash
curl -X POST https://my-app.durablesdk.com/api/hello \
  -H "Content-Type: application/json" \
  -d '{"name":"world"}'
```

```json
{ "runId": "01J…", "status": "COMPLETED" }
```

The door mints a `requestId`, executes `hello.say { name, requestId }`
and answers the run. Send the same body twice: two runs, because the
request id differs. Send the same `requestId` twice (the door accepts one
in the body) and the second answer is the first run's.

## 7. Read the run

Open `https://durablesdk.com/dashboard/apps/my-app` and the Console
tab: the run, its one step with its before and after image, the fact
`hello.said` and the listener's run beside it. The same read on the
command line:

```bash
durable-sdk logs
```

```text
12:04:31 info  run hello.say 01J… COMPLETED in 18 ms
12:04:31 info  fact hello.said delivered to listener hello.record
```

[Logs](https://durablesdk.com/docs/hosting/logs.md) says what the stream carries and
[Console](https://durablesdk.com/docs/operate/console.md) what the tab shows.

## What next

- Change `src/workflows/hello.ts`, run `pnpm test`, `durable-sdk deploy
--prod` again. [Changing a workflow](https://durablesdk.com/docs/guide/changing-a-workflow.md)
  says what a change over runs in flight needs.
- `durable-sdk doctor --host` before each deploy: the rules a Durable
  tree keeps, one line per finding. [The doctor](https://durablesdk.com/docs/guide/the-doctor.md).
- Give the app a secret: `printf '%s' "$VALUE" | durable-sdk secrets set
STRIPE_KEY`. [Secrets](https://durablesdk.com/docs/hosting/secrets.md).
- Read the database from your laptop: `durable-sdk db read-string`.
  [Database](https://durablesdk.com/docs/hosting/database.md).
- Every page here is Markdown at `/docs/<slug>.md`; an agent starts at
  [`/llms.txt`](https://durablesdk.com/llms.txt).

---

Prompt for an agent:

```text
Read https://durablesdk.com/docs/quickstart.md, then scaffold a Durable app and deploy it to durablesdk.com; run durable-sdk doctor --host before and after; a refused line is a refusal id: durable-sdk explain <id>
```
