Skip to main content

SDK Identification Headers and Automatic Idempotency Keys in TypeScript v4 SDKs (Beta)

· 2 min read

TypeScript v4 SDKs now identify themselves on every request and protect non-idempotent calls against accidental replay, matching the C# and Python v4 SDKs.

Details​

Identification headers​

Every request carries a User-Agent and the X-APIMatic-* headers that name the SDK, its version, the generator version, the operating system and the JavaScript runtime it is running on. The operating system and runtime are detected when the client is built, so the same package reports correctly under Node.js, Deno, Bun, Cloudflare Workers and the browser. The values sit at the lowest header layer, so a header an operation declares in the specification takes precedence.

Idempotency keys​

Every non-GET request is sent with an Idempotency-Key header holding a UUID minted once per call, and every retry of that call carries the same key. An API that honors the header can recognize a retried request and avoid applying it twice.

Example Request​

A request sent by the SDK on Node.js carries these headers with no setup:

POST /payments HTTP/1.1
User-Agent: PaymentsClient/1.0.0 TypeScript
X-APIMatic-Lang: TypeScript
X-APIMatic-Package-Version: 1.0.0
X-APIMatic-Gen-Version: 4.0.0
X-APIMatic-OS: linux x64
X-APIMatic-Runtime: Node.js/22.11.0
Idempotency-Key: 6f1c2e8a-4b7d-4a39-9c1e-2f5d8b3a7c41

The first four values are fixed when the SDK is generated, and the OS and runtime are detected from the host. On Deno, X-APIMatic-Runtime reads Deno/2.1.4, and a runtime that exposes neither fact sends neither header. A GET request carries the same identification headers but no Idempotency-Key.

This feature is available in the TypeScript v4 SDK (beta). Generate it from the APIMatic CLI:

apimatic sdk generate --language=typescript --codegen-version=v4 --stability=beta

For the full set of flags and options, see the APIMatic CLI documentation.