# Quickstart

The examples use `curl`; any HTTPS client or AI agent can make the same requests.

## Obtain an API key

A human must create a Gather account, generate a creator API key, and provide it to the agent:

1. Create a Gather account and sign in. Complete any creator eligibility or verification required for API access.
2. In the Gather app, open **Settings → AI access** and select **Generate key**.
3. Copy the full `gth_` key when it is shown; the full key is displayed only once.
4. Securely provide the key to the agent through its credential or secret store, or set `GATHER_API_KEY` in the agent's runtime.

The agent acts on behalf of the human's account, within the key's permissions and Gather's limits. Account signup and key generation are completed by the human. If no key is configured, the agent should ask the human to complete these steps before making authenticated requests.

Keep the key out of prompts, screenshots, logs, source files, and browser frontends. If **AI access** is unavailable, check the account's creator eligibility and whether API access is available for that account.

## 1. Discover the account and contract

```sh
export GATHER_BASE_URL='https://843nov3j7f.execute-api.us-east-1.amazonaws.com/v1'
# Set GATHER_API_KEY securely in your environment.
curl --fail-with-body "$GATHER_BASE_URL/me" \
  -H "Authorization: Bearer $GATHER_API_KEY"
curl --fail-with-body "$GATHER_BASE_URL/openapi.json"
```

Check `creatorId`, `scopes`, `capabilities`, and `limits`. `limits.publish.dailyRemaining` is the effective remaining daily headroom; the underlying budgets can differ. Use the current supply limits from this response. A key's scopes cannot grant permissions above its role or access another creator's resources.

## 2. Upload and validate art

```sh
curl --fail-with-body "$GATHER_BASE_URL/uploads" \
  -H "Authorization: Bearer $GATHER_API_KEY" \
  -H 'Content-Type: application/json' \
  --data '{"files":[{"filename":"card.png","purpose":"card"}],"createOnly":true}'
```

The response has `uploads[]`, each with `uploadId`, `uploadUrl`, `publicUrl`, `method`, `headers`, and `expiresInSeconds`. `headers` always carries `Content-Type`, `Cache-Control` and `Content-Disposition`; because this request sent `createOnly: true`, it also carries `If-None-Match: *` whenever the URL was signed create-only. PUT the raw image bytes to `uploadUrl` using **every returned header exactly**. Do not send your Gather Authorization header to that URL. The URL normally expires after 900 seconds. For example, substitute the returned values:

```sh
curl --fail-with-body -X PUT 'RETURNED_UPLOAD_URL' \
  -H 'Content-Type: RETURNED_CONTENT_TYPE' \
  -H 'Cache-Control: RETURNED_CACHE_CONTROL' \
  -H 'Content-Disposition: RETURNED_CONTENT_DISPOSITION' \
  -H 'If-None-Match: *' \
  --data-binary @card.png
```

Include the `If-None-Match: *` line only when `headers` returned it. `Content-Type`, `Content-Disposition` and a returned `If-None-Match: *` are signed: omitting or changing one makes the PUT fail with HTTP 403. `Cache-Control` is not signature-checked, but send it as returned so the stored art keeps its caching directive. A create-only URL creates its object once; replaying a successful PUT returns HTTP 412. Without `createOnly: true` the URL carries only the three headers and is not create-only. After an uncertain PUT, poll the same upload ID to check whether it succeeded. If a new upload is needed, request a new upload URL. Never remove or weaken the returned condition.

Poll the validation result with a short delay between requests:

```sh
curl --fail-with-body "$GATHER_BASE_URL/uploads/RETURNED_UPLOAD_ID" \
  -H "Authorization: Bearer $GATHER_API_KEY"
```

Continue only after `status: "valid"`. `pending` means wait; `rejected` is terminal and includes a reason; `error` requires re-uploading. A successful PUT alone is insufficient. For multiple uploads use `GET /uploads?ids=ID1,ID2`; it returns `items[]`. Up to 12 files can be presigned together. Card art accepts JPEG, PNG, WebP, and GIF; cover art excludes GIF. Card art must be exactly 2:3 portrait and at least 1080x1620; cover art must be exactly 2.5:1 landscape and at least 1500x600. Files are limited to 10 MB and 8192 px per side. Other sizes are `rejected`, and the reason states the size to use.

Use a fresh raw upload within its 24-hour validation-evidence window. For later reuse, save/reuse a card template or upload again. Do not overwrite an already validated object: publication checks the actual validated bytes. If an older GIF is refused because its validation evidence is no longer sufficient, upload a new copy and wait for `valid`.

## 3. Prepare and preview one immutable publish request

Generate a UUID once and persist it with the request body before submitting. Use this same key and body for every retry of this logical publish, including after a timeout or process restart. Resend the key byte for byte: the value is case-sensitive, so a key that differs only in letter case is a different key and can publish a second drop.

```sh
export GATHER_PUBLISH_KEY='REPLACE_WITH_ONE_PERSISTED_UUID'
```

Create `drop.json` with the validated `publicUrl`. This sample uses a supply of 100; adjust it to the current `GET /me.limits.direct` window before submitting.

```json
{
  "name": "First collection",
  "type": "direct",
  "perFanLimit": 1,
  "rarityMode": "tiered",
  "totalSupply": 100,
  "cards": [
    {"name": "First card", "rarity": "COMMON", "imageUrl": "RETURNED_PUBLIC_URL"}
  ]
}
```

Preview the computed supplies and validation results:

```sh
curl --fail-with-body "$GATHER_BASE_URL/drops" \
  -H "Authorization: Bearer $GATHER_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Idempotency-Key: $GATHER_PUBLISH_KEY" \
  -H 'X-Dry-Run: true' --data-binary @drop.json
```

A successful preview returns HTTP 200 with `dryRun`, `wouldPublish`, and `checks`. Inspect `wouldPublish.cards`, `printedSupply`, `reservedSupply`, `claimableSupply`, and `totalCardCopies`. Read `checks.notValidated`: a preview does not reserve capacity or test the idempotency record's current state. It consumes no daily publish slot.

## 4. Publish and verify

Once the request matches your intent, repeat it without the dry-run header:

```sh
curl --fail-with-body -D publish-headers.txt "$GATHER_BASE_URL/drops" \
  -H "Authorization: Bearer $GATHER_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Idempotency-Key: $GATHER_PUBLISH_KEY" \
  --data-binary @drop.json
```

HTTP 202 returns an accepted receipt containing `dropId` and `pollAfterSeconds`. Save the ID immediately. After that delay, GET the canonical resource:

```sh
curl --fail-with-body "$GATHER_BASE_URL/drops/RETURNED_DROP_ID" \
  -H "Authorization: Bearer $GATHER_API_KEY"
```

Poll with bounded backoff until `status` is `live` or `publish_failed`. While `processing`, use `slotGeneration` when present for progress. A scheduled drop can already be `live` while `lifecycle` is `upcoming`; check `claimable`, `claimBlockedReason`, and `claimRequiresEventToken` before telling fans they can claim. Return the server's `shareUrl`, not a hand-built link.

On timeout, connection failure, or 5xx, the publish may already exist. Retry the exact persisted key and body; never switch keys merely to get past an uncertain result. One 503 is not uncertain: when its message says the publish failed and `details.dropId` names a drop, that drop is `publish_failed` and the same key will keep returning this 503. GET the drop; a replacement publish is a new operation with a new key. Follow [Troubleshooting](troubleshooting.md) for terminal failure or reconciliation messages.
