SDKs and tools

Use the server SDK for Node, Bun, Deno and edge runtimes, or import the OpenAPI spec into Postman or a code generator to work in any other language.

Last updated:

Server SDK

One file with no dependencies. It needs fetch and Web Crypto, which every current runtime has. It retries rate limits and server errors on safe requests, never retries a create without an idempotency key, and ships with TypeScript types.

import { DTAI, DTAIError } from "./dtai-server.mjs"

const dtai = new DTAI(process.env.DTAI_SECRET_KEY, {
  maxRetries: 2,     // retries 429 and 5xx on safe requests
  timeoutMs: 20_000,
})

try {
  const session = await dtai.sessions.create(
    { amount: 49.99, order_id: "1001", success_url: "https://shop.example/thanks", cancel_url: "https://shop.example/cart" },
    { idempotencyKey: "order-1001" },
  )
  console.log(session.checkout_url)
} catch (error) {
  if (error instanceof DTAIError) console.error(error.status, error.message)
  else throw error
}
  • dtai.me()Confirm the key, mode and webhook setup.
  • dtai.sessions.create(params, { idempotencyKey })Create a checkout session.
  • dtai.sessions.retrieve(id)Fetch one session. Pending sessions are checked on-chain.
  • dtai.sessions.list(params)One page of sessions.
  • dtai.sessions.iterate(params)An async iterator over every page.
  • dtai.sessions.expire(id)Cancel a pending session.
  • dtai.webhooks.test()Send a signed test event to your endpoint.
  • dtai.webhooks.deliveries(params)List recent webhook deliveries.
  • dtai.webhooks.redeliver(id)Send a delivery again.
  • DTAI.constructEvent(raw, header, secret)Verify a webhook and return the parsed event.

OpenAPI and Postman

The spec is public and kept in step with the API reference. In Postman or Insomnia choose Import and paste https://digitaltoken.ai/api/v1/openapi.json, then set a Bearer token to your test secret key.

# Generate a typed client in your language with any OpenAPI tool, for example:
npx @openapitools/openapi-generator-cli generate \
  -i https://digitaltoken.ai/api/v1/openapi.json \
  -g python -o ./dtai-client

Browser embed

The Pay with DTAI button is a separate script at /sdk/v1/dtai.js that only uses your publishable key. See the quickstart for the snippet.