TypeScript SDK

TypeScript SDK v0.0.17

The OpenPay TypeScript SDK (@getopenpay/client) provides a fully typed interface to the OpenPay API. It abstracts HTTP requests, handles serialization, and normalizes errors—making it easy to interact with OpenPay resources in TypeScript projects.

This guide covers installation, configuration, and usage examples.

SDK Architecture

The OpenPay SDK is auto-generated from an OpenAPI schema and includes:

  • A Configuration class for API key and environment setup

  • Resource-specific API classes such as CustomersApi and SubscriptionsApi

  • Fully typed method inputs and outputs via interfaces like CustomerCreateParams

This structure ensures type safety and consistent API access throughout your TypeScript project.

Installation

npm install @getopenpay/client
yarn add @getopenpay/client

Initialize the SDK

You must create a Configuration instance and use it to instantiate each API class.

import { Configuration } from '@getopenpay/client';

const config = new Configuration({
  basePath: 'https://connto.getopenpay.com',       // REQUIRED: OpenPay API base
  accessToken: 'sk_test_abc123',                   // REQUIRED: your secret key
});

You then pass this config to an API client:

import { CustomersApi } from '@getopenpay/client';

const customers = new CustomersApi(config);

Examples

Create a customer

const createdCustomer = await customers.createCustomer({
  createCustomerRequest: {
    email: 'opemipo@disu.com',
  },
});

Note:

  • The argument must match the exact structure expected, for example, an object with a createCustomerRequest property.

Create a subscription

import { SubscriptionsApi } from '@getopenpay/client';

const subscriptions = new SubscriptionsApi(config);

const result = await subscriptions.createSubscription({
  createSubscriptionRequest: {
    customerId: 'cus_abc123',
    subscriptionItems: [
      {
        priceId: 'price_xyz456',
      },
    ],
  },
});

Reminder:

  • priceId and customerId must refer to existing resources. These are typically created using the PricesApi and CustomersApi, respectively.

List subscriptions

The listSubscriptions method requires a non-empty object with a subscriptionQueryParams key.

const result = await subscriptions.listSubscriptions({
  subscriptionQueryParams: {},
});

If you remove subscriptionQueryParams, or pass undefined, TypeScript will throw an error.

Type safety & autocompletion

Every method expects a named object input, and the SDK ships with full types like:

import type { CustomerCreateParams } from '@getopenpay/client';

const payload: CustomerCreateParams = {
  name: 'Jane Doe',
  email: 'jane@example.com',
};

This enables full IntelliSense and compile-time validation.

Error handling

The SDK throws a ResponseError when an HTTP error occurs:

import { ResponseError } from '@getopenpay/client';

try {
  await customers.getCustomer({ customer_id: 'invalid-id' });
} catch (error) {
  if (error instanceof ResponseError) {
    const body = await error.response.json();
    console.error('OpenPay API Error:', body);
  } else {
    console.error(error);
  }
}

Example project structure

// openpayClient.ts
import {
  Configuration,
  CustomersApi,
  SubscriptionsApi,
} from '@getopenpay/client';

const config = new Configuration({
  basePath: '<https://connto.getopenpay.com>',
  accessToken: process.env.OPENPAY_SECRET_KEY!,
});

export const OpenPay = {
  customers: new CustomersApi(config),
  subscriptions: new SubscriptionsApi(config),
};

Then in your app:

import { OpenPay } from './openpayClient';

await OpenPay.customers.createCustomer({
  customerCreateParams: { name: 'Ope', email: 'ope@example.com' }
});

Notes

  • Most methods follow the pattern:

    api.method({ methodSpecificParams: {...} })

  • The SDK is designed to make direct REST interactions easier while preserving OpenPay’s API shape and constraints.

  • You can inspect request/response bodies from your OpenPay dashboard or logs.

Reference

OpenPay SDKs

In this directory, you'll find OpenPay's official SDKs designed to simplify your integration with our APIs.