SDKs
Official SDKs are coming soon. Call the REST API directly for now.
The official SDKs are not published to npm yet. Until they are, call the REST API
(https://api.k-otp.dev/v1) directly with fetch or curl, as in the examples throughout these
docs.
Planned packages
| Package | Runtime | Features | Key |
|---|---|---|---|
@k-otp/sdk-core | Browser | issue, verify | pk_ |
@k-otp/sdk-server | Server (Node.js, etc.) | The full public API: issue, verify, status, history, ledger, balance, templates | sk_ |
React, Vue, and Svelte bindings are on the roadmap.
Preview
The API shape below is under development and may change before release.
import { createOtpClient } from "@k-otp/sdk-core";
const client = createOtpClient({
baseUrl: "https://api.k-otp.dev",
apiKey: "pk_...",
});
// The SDK requires idempotencyKey in the body; a blank key fails with BAD_REQUEST before any request.
const { issueId } = await client.issue({
phoneNumber: "01012345678",
purpose: "login",
idempotencyKey: crypto.randomUUID(),
});
const result = await client.verify({ issueId, code: "123456" });import { createOtpServerClient } from "@k-otp/sdk-server";
const client = createOtpServerClient({
baseUrl: "https://api.k-otp.dev",
apiKey: process.env.KOTP_SECRET_KEY!,
});
const status = await client.otp.status({ issueId });
const balance = await client.otp.balance({});SDK errors are thrown as OtpApiError (code, status, message, data). code follows Errors; anything else (including INTERNAL_SERVER_ERROR) is normalized to UNKNOWN.