Configuration

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

const repost = createRepostClient({
  apiKey: process.env.REPOST_SEND_API_KEY,
  apiUrl: process.env.REPOST_API_URL,
});
OptionResolution when omitted
apiKeyREPOST_SEND_API_KEY, then REPOST_TOKEN, snapshotted at construction.
apiUrlREPOST_API_URL, then https://api.repost.sh, snapshotted at construction.
transportThe one-attempt transport. Pass a custom transport or stubTransport for tests.
generatorsReal clock and id generators. Override for determinism.
tokenDeprecated 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 },
});
OptionDefaultMeaning
maxAttempts4Total attempts, including the initial attempt.
retryBaseDelayMs250Exponential backoff base.
attemptTimeoutMs30000Maximum time for one attempt.
operationTimeoutMs120000Deadline shared by the entire send, including retries and backoff.
maxInFlightOperations256Admission limit; excess sends fail with OVERLOADED.
maxBufferedBytes67108864Shared 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.

Continue