Skip to main content

TypeScript SDK

The official Oproto SDK for TypeScript and JavaScript applications.

npm npm downloads

Installation​

npm install @oproto/sdk

Requirements​

  • Node.js 18+ (or compatible runtime)
  • TypeScript 5.0+ (recommended)

Quick Start​

import { OprotoClient } from '@oproto/sdk';

// Initialize the client
const client = new OprotoClient({
accessToken: 'your-access-token',
});

// Make API calls
const companies = await client.companies.list();

Authentication​

The SDK supports OAuth 2.0 authentication. You can provide credentials in several ways:

Access Token​

const client = new OprotoClient({
accessToken: 'your-access-token',
});

Token Refresh​

For long-running applications, configure automatic token refresh:

const client = new OprotoClient({
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
tokenEndpoint: 'https://auth.oproto.io/oauth/token',
});

Configuration Options​

OptionTypeDescription
accessTokenstringOAuth access token
clientIdstringOAuth client ID for token refresh
clientSecretstringOAuth client secret for token refresh
baseUrlstringAPI base URL (defaults to production)
timeoutnumberRequest timeout in milliseconds

Error Handling​

The SDK throws typed errors for API failures:

import { OprotoClient, OprotoError } from '@oproto/sdk';

try {
const company = await client.companies.get('invalid-id');
} catch (error) {
if (error instanceof OprotoError) {
console.error(`API Error: ${error.code} - ${error.message}`);
}
}

Resources​