> ## Documentation Index
> Fetch the complete documentation index at: https://repost.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure the TypeScript Client

> Client options, credential resolution, HTTP transport tuning, and the injectable clock and id generators.

`createRepostClient()` snapshots and validates its configuration. Fixed credentials and the API URL are resolved at construction; an `apiKeyProvider` is resolved once for each admitted send.

## Client options

```ts theme={"languages":{"custom":["/languages/repost.json"]}}
const repost = createRepostClient({
  apiKey: process.env.REPOST_SEND_API_KEY,
  apiUrl: process.env.REPOST_API_URL,
});
```

| Option       | Resolution when omitted                                                          |
| ------------ | -------------------------------------------------------------------------------- |
| `apiKey`     | `REPOST_SEND_API_KEY`, then `REPOST_TOKEN`, snapshotted at construction.         |
| `apiUrl`     | `REPOST_API_URL`, then `https://api.repost.sh`, snapshotted at construction.     |
| `transport`  | The one-attempt transport. Pass a custom transport or `stubTransport` for tests. |
| `generators` | Real clock and id generators. Override for determinism.                          |
| `token`      | Deprecated alias for `apiKey`, checked after it and before the environment.      |

With no key available, a send throws `RepostConfigurationError` with error code `CONFIGURATION` and delivery state `NOT_SENT`.

Every request goes to `POST <apiUrl>/v1/messages` with `authorization: Bearer`, `content-type: application/json`, and `idempotency-key` headers.

## Transport tuning

Retries and operation deadlines belong to the client runtime. Network and connection-pool settings belong under `httpTransportOptions`:

```ts theme={"languages":{"custom":["/languages/repost.json"]}}
import { createRepostClient } from "./generated/repost";

const repost = createRepostClient({
  maxAttempts: 4,
  retryBaseDelayMs: 250,
  attemptTimeoutMs: 30_000,
  operationTimeoutMs: 120_000,
  httpTransportOptions: { http2: true, maxConnectionsPerOrigin: 32 },
});
```

| Option                  | Default  | Meaning                                                            |
| ----------------------- | -------- | ------------------------------------------------------------------ |
| `maxAttempts`           | 4        | Total attempts, including the initial attempt.                     |
| `retryBaseDelayMs`      | 250      | Exponential backoff base.                                          |
| `attemptTimeoutMs`      | 30000    | Maximum time for one attempt.                                      |
| `operationTimeoutMs`    | 120000   | Deadline shared by the entire send, including retries and backoff. |
| `maxInFlightOperations` | 256      | Admission limit; excess sends fail with `OVERLOADED`.              |
| `maxBufferedBytes`      | 67108864 | Shared request/response byte budget.                               |

The deprecated `maxRetries`, `baseDelayMs`, and `timeoutMs` fields are still translated when they appear inside `httpTransportOptions` on the client. Passing them directly to `createHttpTransport()` or `createNodeTransport()` is rejected because a transport executes exactly one attempt.

## Generators

The runtime asks three injectable functions for values it has to invent: `now` for the envelope timestamp and `@default(now())`, `uuid` for `@default(uuid())` and minted idempotency keys, and `cuid` for `@default(cuid())`.

```ts theme={"languages":{"custom":["/languages/repost.json"]}}
const repost = createRepostClient({
  generators: {
    now: () => "2026-01-01T00:00:00.000Z",
  },
});
```

Defaults are `new Date().toISOString()`, `crypto.randomUUID()`, and cuid2. Only the functions you set are overridden. `now` is called once per send and memoized, so the envelope timestamp and any `now()` default inside the same event always match.

## Continue

<Columns cols={3} className="gap-y-4">
  <Card title="Reliability" icon="shield-check" href="/docs/send/typescript/reliability" cta="Errors" arrow="true">
    Retries, idempotency, and the error surface in detail.
  </Card>

  <Card title="Testing" icon="flask-conical" href="/docs/send/typescript/testing" cta="Test" arrow="true">
    The stub transport and deterministic generators in practice.
  </Card>

  <Card title="HTTP API" icon="globe" href="/docs/send/publishing" cta="Raw API" arrow="true">
    The endpoint these options point the client at.
  </Card>
</Columns>
