# Gather Creator API JavaScript client

Dependency-free ESM client for Node.js 20+ and runtimes with `fetch`. TypeScript declarations are included. This directory is distributed as source; it is not published to npm. Copy it into your application and import `index.js`, or install this directory as a local package. The client defaults to the public Gather Creator API.

A human must create a Gather account, complete any required creator eligibility or verification, and generate a creator API key in **Settings → AI access → Generate key**. The human then securely provides the key to the agent's secret store or `GATHER_API_KEY` runtime variable. The agent uses this key to act on behalf of that account.

```js
import { GatherCreatorClient, GatherApiError } from './creator-api/index.js';

const api = new GatherCreatorClient({
  apiKey: process.env.GATHER_API_KEY,
  timeoutMs: 30_000,
  maxRetries: 2,
});

const me = await api.me();

for await (const page of api.pages('drops', { query: { limit: 20 } })) {
  // Process this page without assuming that an empty page ends pagination.
  console.log(page);
}
```

Keep the key in a server-side secret store. Do not embed it in browser bundles. The live `/openapi.json` and `GET /me` describe available operations and permissions. Check `GET /me` capabilities before relying on a gated feature.

For each logical create, persist an idempotency key and the exact request body **before** sending the request. Pass the same pair after a timeout or process restart:

```js
// Load these from your application's durable operation record.
const { body, idempotencyKey } = savedPublishOperation;
const preview = await api.createDrop(body, { idempotencyKey, dryRun: true });
// Inspect the preview and publish within the user's authorization.
const receipt = await api.createDrop(body, { idempotencyKey });
```

The client automatically retries GET/HEAD reads, PUT and DELETE requests, keyed creates, and keyed webhook-secret rotations within the request deadline, after a network failure or a 429, 500, 502, 503 or 504. It uses exponential backoff with jitter; when Retry-After is present, jitter is added above that minimum. The create methods (`createDrop`, `createHunt`, `createCardTemplate`, `createAward`, `createWebhook`, `retryWebhookDelivery`) always send an Idempotency-Key: yours when you pass `idempotencyKey`, otherwise a random key for that one call, so the call's own retries are safe but a second call without your persisted key is a new create. A DELETE retried after its first attempt already committed answers as a repeated delete does (`deleteDrop` 404 not_found, `revokeAward` 409 conflict with details.reason ALREADY_REVOKED, `archiveHunt` 409 conflict), so read the resource before treating that as a failure. Unkeyed POST requests sent through `request`, ordinary PATCH requests, and action POSTs such as pause or renew are not automatically retried. A publish receipt is asynchronous: poll `getDrop` and report the observed state. A reconciliation error requires investigation; creating a new key can create a second drop.

Methods accept an `AbortSignal` and per-request `timeoutMs`. `GatherApiError` exposes `status`, `code`, `details`, `requestId` (including Gateway request IDs), `retryAfter` (milliseconds, or null when the response carried no Retry-After header), and, when applicable, `idempotencyKey`. Error messages are fixed client sentences: the API's own `error.message` is not exposed, so diagnose with the machine code, details and retryAfter. Some POST /drops refusals differ only in the API message: a 409 conflict with no details.reason and no retryAfter can be a reused key with a different body, a bare backend conflict, or a publish that needs support reconciliation, and this client cannot tell them apart. Never mint a new key for one: confirm your persisted body is unchanged, then look the drop up with `listDrops` or `getDrop` before doing anything else. Preserve these diagnostic fields without logging credentials, signed URLs, award tokens, or webhook signing secrets.

`upload` obtains signed URLs, sends only the returned upload headers to storage, and polls validation. `pages` follows each resource's cursor convention. For `awards` it sends `limit=500` unless you pass your own `limit`, so every page carries `nextToken` and the walk reads the whole ledger; a bare `listAwards(id)` with no query gets the original single-page body instead (the newest 500 rows, `partial: true` when more exist, and no cursor), so pass `{ limit: 500 }` to page it yourself. Use `completionPages` for resumable drop-completion feeds: pass the `nextToken` you persisted from the last page you processed, and persist each yielded page's `nextToken`. Drains that keep resuming from the persisted `nextToken` receive every completion recorded through normal automatic delivery at least once (unless it is revoked first). Delivery is at least once, so a page can repeat a completion an earlier page already carried, and the first page of a later drain can repeat one the previous drain yielded, however much later it runs; de-duplicate on `fanRef` plus `completedAt` for the life of your integration, not just within one drain. The drain ends at an empty page or at a non-empty page that adds no completion it has not already yielded, and it waits `minIntervalMs` (default 1000) before a request that follows a page shorter than `limit`, so it never spins against the rate limit. An empty page means caught up (on a drop with 25,000 or more completions inside fifteen minutes it can also mean the poll used up its read budget partway through a replay of late completions, and the next drain carries on from there). A drain that ends on a non-empty page with nothing new means nothing new on this pass, not caught up: in a burst re-deliveries can fill a page while newer completions are still pending, and a later drain from the `nextToken` you persisted picks them up, so run the next drain later rather than treating the end of one as the end of the feed. Each item's `completionOrder` is the feed's numbering, and ranks on a resumed chain can shift (after a late arrival or a revocation, for example); `getDropHoldings` or a fresh listing without a token is authoritative for rank. Partial holdings pages raise `partial_page` rather than silently presenting an incomplete audience.

Download the client files together: [index.js](index.js), [index.d.ts](index.d.ts), [schema.d.ts](schema.d.ts), and [package.json](package.json). Read [the declarations](index.d.ts) for all methods.
