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#
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:
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()).
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.