<!-- sourceHash:80b07a089136a855 -->
# Developer authentication for a first deploy

## Deploy with two HTTP calls

Use curl or your standard library. Start with a fresh random UUID in place of `YOUR_RANDOM_UUID`.

```bash
curl -sS https://api.somewhere.cloud/v1/auth/temp-create \
  -H 'Content-Type: application/json' \
  -d '{"request_key":"YOUR_RANDOM_UUID"}'
```

Save `data.key` as `KEY` in your shell. Keep it private. If signup is interrupted, retry with the same request body.

```bash
curl -sS https://api.somewhere.cloud/v1/deploy \
  -H "Authorization: Bearer $KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "hello-somewhere",
    "files": {"index.html": "<!doctype html><title>Hello</title><h1>Hello from Somewhere</h1>"},
    "functions": {"api/hello.ts": "export default () => Response.json({ hello: true })"}
  }'
```

This example deploys a page and an API function so you can try SQL. Replace the example name and source with your app. Deploying again with the same key and name updates the same project. Put server handlers such as `api/hello.ts` in `functions`.

Use the live URL exactly as returned. Give the human `data.url`, `data.claim_url`, and the time in `data.expires_at`. Opening the claim link and signing in keeps the app. The key lets you deploy and use logs, recent errors, and SQL for this account's projects. Sending email from the app and managing environment variables or secrets require a claimed account.

## Deploy a project folder

From the project folder, stream its source as a tar.gz with the same key.

```bash
tar --exclude=node_modules --exclude=.git -czf - . | \
  curl -sS https://api.somewhere.cloud/v1/deploy \
    -H "Authorization: Bearer $KEY" \
    -F name=my-app \
    -F 'source=@-;filename=app.tgz'
```

Use either `name` or `project_id` as a form field. The upload replaces the
project's files and functions, and returns the same fields as the JSON form.
To update a live project, read its `data.active_release_id` from
`GET /v1/deploy/status?project_id=PROJECT_ID` and send it in the
`base_release_id` form field.
Keep source under 20 MiB total and 5 MiB per file. The upload and expanded
archive each have the 40 MiB deploy request limit.

The server skips dependencies, Git files, secret paths such as `.env`, and
local files matched by `.somewhereignore` or `.gitignore`. Check the response's
warnings for exclusions. Archives with links or paths outside the folder
are refused.

## Inspect the deployed project

Set `PROJECT_ID` to the deploy response's `data.project_id`. Use the same key with each call.

```bash
curl -sS "https://api.somewhere.cloud/v1/logs?project_id=$PROJECT_ID" \
  -H "Authorization: Bearer $KEY"

curl -sS "https://api.somewhere.cloud/v1/errors/recent?project_id=$PROJECT_ID" \
  -H "Authorization: Bearer $KEY"

curl -sS https://api.somewhere.cloud/v1/db/query \
  -H "Authorization: Bearer $KEY" \
  -H 'Content-Type: application/json' \
  -d "{\"project_id\":\"$PROJECT_ID\",\"sql\":\"SELECT 1 AS proof\"}"
```

Successful calls return `ok: true` and put the result in `data`. On failure, read `error` for the code and `message` for the next step. To keep using a temporary app past its returned expiry, give its claim link to the human before that time.

To preview a rollback after a second deploy, send `POST /v1/promote/rollback` with the same key and a JSON body containing `project_id` and `"preview": true`.

## Email the claim link

After deploy, if the human asks you to email the claim link, send it to the
address they give you. Use an address that can receive external mail.
Project test inboxes cannot receive claim links.

```bash
curl -sS https://api.somewhere.cloud/v1/auth/claim \
  -H "Authorization: Bearer $KEY" \
  -H 'Content-Type: application/json' \
  -d '{"email":"ADDRESS_FROM_THE_HUMAN"}'
```

A successful response confirms acceptance. The human gets the link by email,
then opens it and signs in to keep the app.

## After claim

Keep the temporary key private. When the human chooses **Save and connect agent**, the same key keeps working on the projects they saved. **Save only** saves the projects and disconnects the key. Send the key as a bearer to `GET /v1/auth/temp-claim/status`. It returns `unclaimed` with the expiry, `claimed_connected` with the allowed `project_ids` and deploy status for each project, or `claimed_disconnected` when the key has lost project access. The human can disconnect it from their dashboard at somewhere.cloud/app. The connection expires after 30 days without work.

Use one of the returned project IDs for deploy, logs, errors, and SQL. If a project says `can_deploy: false` with `reason: "private_configuration"`, publishing and SQL are paused. Its live version stays up, and you can still read its logs and errors. Tell the human “You’ve added private configuration to this project. To let me keep publishing or using SQL, sign me in with `somewhere login` or connect Somewhere in this chat.”

## Connect with a code

If the person gives you a Somewhere connect code, send `POST https://api.somewhere.cloud/v1/auth/connect-codes/redeem` with `Content-Type: application/json` and `{"connect_code":"CODE_FROM_THE_PERSON"}`. A code works once and expires in ten minutes. If it was used, expired, or revoked, ask for a new code.

Keep the returned `data.key` private. Use it as a bearer to call `POST /v1/projects` with `{"name":"my-app"}`. Call `POST /v1/deploy` with the source and use the project's returned `data.id` as `project_id`. Give the person the live URL returned by the deploy. The key can work only on projects it creates, and `data.projects_remaining` from redemption tells you how many projects it can create. The owner can disconnect the key from their dashboard at somewhere.cloud/app.

If private configuration pauses publishing or SQL, keep using the project's logs and errors and ask the owner to sign you in with `somewhere login` or connect Somewhere in this chat.

## Use the CLI for ongoing work

The CLI also has a local dev loop, generated types, and verification tools.

```bash
npx -y @somewhere-cloud/cli@latest deploy
```

With the CLI signed in, the same HTTP paths are available through `somewhere api <METHOD> <PATH>`, for example `somewhere api GET "/v1/logs?project_id=$PROJECT_ID"`. Use `-d` to send JSON with a POST.
