Manage API Keys

Authentication

The SuiPay SDK uses API keys for authentication. This guide explains how to configure authentication in your application using the SDK.

SDK Authentication Setup

The SDK handles authentication automatically once you provide your API key during client initialization. No need to manually set headers or manage tokens.

import { SuiPayClient } from '@suipay/api';

const client = new SuiPayClient({
  apiKey: 'sk_your_api_key_here'
});

API Key Format

API keys are prefixed with sk_ and generated using cryptographically secure random bytes. A typical API key looks like:

sk_1234567890abcdef1234567890abcdef

Getting Your API Key

API keys should be created through the SuiPay dashboard:

  1. Login to SuiPay: Visit https://demo2.suipay.net and sign in to your account

  2. Navigate to Dev API Keys: Go to the "Dev API Keys" section in your dashboard

  3. Create New API Key: Click "Create API Key" and give it a descriptive name

  4. Copy and Store: Your API key will be shown once - copy it immediately and store it securely

Configuration Options

Basic Configuration

Environment Variables

Use environment variables for better security:

Testing Authentication

Use the ping() method to verify your API key is working:

User Access Control

API keys are scoped to specific users and their resources:

  • Each API key can only access the user account it was created for

  • You cannot access other users' data with your API key

  • All resources (payment links, withdrawals, bank accounts) are tied to the user associated with your API key

Example access control:

  1. API Key A is created for User 1

  2. API Key B is created for User 2

  3. API Key A can only access User 1's data and resources

  4. API Key B can only access User 2's data and resources

Authentication Errors

The SDK provides specific error types for authentication issues:

Common Authentication Errors

Error
Description
Solution

Invalid API key

API key format is incorrect

Ensure API key starts with sk_

API key not found

API key doesn't exist

Check your API key in the dashboard

API key deactivated

API key has been disabled

Create a new API key

Unauthorized

Missing or malformed API key

Verify client initialization

Security Best Practices

1. Environment Variables

2. Separate Keys per Environment

3. Key Validation

4. Error Handling

Best Practices Summary

  1. Store API keys securely using environment variables

  2. Never commit API keys to version control

  3. Use different API keys for development and production

  4. Test authentication before using the client

  5. Handle authentication errors gracefully

  6. Rotate API keys regularly

  7. Monitor API key usage in the dashboard

  8. Deactivate unused API keys promptly

Last updated