Getting Started
This guide walks you through installing the Kard TypeScript SDK, authenticating with the Kard API, and making your first request.
Prerequisites
- Node.js 18+ or a supported runtime
KARD_CLIENT_IDandKARD_CLIENT_SECRET- Package manager:
npm,yarn, orpnpm
Supported runtimes: Node.js 18+, Vercel, Cloudflare Workers, Deno v1.25+, Bun 1.0+, React Native
Install the SDK
Create a Client
Import and instantiate the KardApiClient using your credentials.
You can also configure the SDK using environment variables.
If KARD_CLIENT_ID and KARD_CLIENT_SECRET are set in your runtime environment, the SDK will automatically use them, so you can initialize the client without passing credentials explicitly.
The client automatically handles authentication, retries, and timeouts.
Make Your First API Calls
1. Creating a User:
3. Submitting Transaction for User:
All SDK methods return typed responses and throw typed errors.
Type Safety
The SDK exports all request and response types for full TypeScript support.
Handling Errors
If an API request fails (4xx or 5xx), the SDK throws a KardApiError.
Common Configuration Options
Add Custom Headers
Add Query Parameters
Configure Retries
Retries are enabled by default (max 2 attempts).
Set a Timeout
Abort a Request
Access Raw HTTP Responses
To inspect headers or status codes, use withRawResponse():
Enable Logging
Logging is disabled by default. Enable it during development to debug requests.
Customize Fetch Client
The SDK provides a way for you to customize the underlying HTTP client / Fetch function.