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_1234567890abcdef1234567890abcdefGetting Your API Key
API keys should be created through the SuiPay dashboard:
Login to SuiPay: Visit https://demo2.suipay.net and sign in to your account
Navigate to Dev API Keys: Go to the "Dev API Keys" section in your dashboard
Create New API Key: Click "Create API Key" and give it a descriptive name
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:
API Key A is created for User 1
API Key B is created for User 2
API Key A can only access User 1's data and resources
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
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
Store API keys securely using environment variables
Never commit API keys to version control
Use different API keys for development and production
Test authentication before using the client
Handle authentication errors gracefully
Rotate API keys regularly
Monitor API key usage in the dashboard
Deactivate unused API keys promptly
Last updated