# Run the API locally

URL: https://skywake.dev/docs/self-hosting/local-api

Run only the API from source on your laptop, for development or to try the SDKs.

Use this setup when you want only the API, built from source, on your own machine. It is meant for development or for trying the SDKs.

```bash norun
docker compose -f docker/dev/compose.yaml up -d    # Postgres on :5433, object storage on :9100

export SKYWAKE_API_DATABASE=postgres://skywake:skywake-dev@localhost:5433/skywake
export SKYWAKE_STORE=s3://skywake AWS_ENDPOINT=http://localhost:9100 AWS_ALLOW_HTTP=true \
       AWS_ACCESS_KEY_ID=skywake AWS_SECRET_ACCESS_KEY=skywake-dev AWS_REGION=us-east-1
export SKYWAKE_API_ADMIN_TOKEN=$(openssl rand -hex 32)

pnpm install
pnpm --filter @skywake/engine build
node apps/api/src/main.ts                           # http://localhost:8080
```

Run these commands from the repository's root. You need Node 22.18 or later, and Rust to build the engine. The API creates its tables when it starts.

The credentials above belong to the dev compose file and are meant for your machine only. For a server, use [Docker Compose](./docker-compose.mdx).

## Make an organization [#make-an-organization]

The admin token is what creates organizations. The response holds the organization's first key: an `admin` key for every environment, shown only once.

```bash norun
curl -X POST localhost:8080/v1/orgs \
  -H "authorization: Bearer $SKYWAKE_API_ADMIN_TOKEN" -H "content-type: application/json" \
  -d '{"name": "acme"}'
# {"id": "...", "key": "sw_..."}
```

Creating organizations has no v2 route; it stays on `/v1` for now. Organization names are unique across the whole server, ignoring case, whether the API or the console created them. Creating a second `acme` (or `ACME`) fails with `409` and ``organization `acme` exists``.

## Point the tools at it [#point-the-tools-at-it]

The SDKs, the CLI and the [MCP server](../agents/mcp.mdx) read `SKYWAKE_URL` and `SKYWAKE_API_KEY`:

```bash norun
export SKYWAKE_URL=http://localhost:8080 SKYWAKE_API_KEY=sw_...
```

Then check that it answers and knows the key:

```bash tab="CLI"
curl -s "$SKYWAKE_URL/health"
echo

curl -s "$SKYWAKE_URL/v2/whoami" -H "authorization: Bearer $SKYWAKE_API_KEY"
echo

skywake whoami
```

To keep the server next to Skywake Cloud, save it as its own CLI profile instead. `skywake login` saves the key with that profile's URL, and `--profile` (or `SKYWAKE_PROFILE`) picks it later:

```bash norun
skywake login --profile local --url http://localhost:8080 --paste
skywake whoami --profile local
```

Without a console, paste the organization's key or a key made from it. With the console running, `skywake login --profile local --url http://localhost:8080` signs in through the browser instead, once the API knows where the console is (`SKYWAKE_API_CONSOLE_URL`).

## Settings [#settings]

| Variable                  | Meaning                                                                                                                  |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `SKYWAKE_API_DATABASE`    | Postgres URL. Required.                                                                                                  |
| `SKYWAKE_STORE`           | Where data goes: `s3://bucket` or a local folder. Required.                                                              |
| `AWS_*`                   | The bucket's keys, region and endpoint. `AWS_ALLOW_HTTP=true` for a local `http` one.                                    |
| `SKYWAKE_API_ADMIN_TOKEN` | Creates organizations. At least 16 characters.                                                                           |
| `SKYWAKE_API_LISTEN`      | Where to listen. `0.0.0.0:8080` by default.                                                                              |
| `SKYWAKE_API_CONSOLE_URL` | The console's address, with its base path. `skywake login` sends people there to allow a key, and billing returns there. |

For every setting, see the API's README.

## A second API [#a-second-api]

Postgres records which disks exist and where their data is. So if you run a second, separate API on the same Postgres, such as a test run next to your dev server, give it its own database:

```bash norun
docker compose -f docker/dev/compose.yaml exec postgres createdb -U skywake skywake2
export SKYWAKE_API_DATABASE=postgres://skywake:skywake-dev@localhost:5433/skywake2
export SKYWAKE_API_LISTEN=127.0.0.1:8081
```

Copies of one API that use the same store share one database. See [Docker Compose](./docker-compose.mdx#update).

## With the console [#with-the-console]

To also run zero-cache and the web console on `http://localhost:3100`, use `scripts/dev.sh`. It installs Node.js, Rust and Docker if they are missing, then starts all of the above as well.

## Next [#next]

<Cards>
  <Card href="./docker-compose.mdx" />
  <Card href="../getting-started/first-branch.mdx" />
  <Card href="../security/api-keys.mdx" />
</Cards>