Skip to main content

API Authentication

Secure your Pelago API integration with proper authentication.

API Keys

Pelago uses a dual-key authentication system:

Key TypePurposeExample
Public KeyIdentifies your accountpk_live_xxxxx
Secret KeySigns requestssk_live_xxxxx

Getting Your Keys

  1. Log into the Pelago Dashboard
  2. Navigate to SettingsAPI Keys
  3. Click Generate New Key Pair
  4. Store the secret key securely (shown only once)

Environment Keys

EnvironmentKey PrefixPurpose
Sandboxpk_test_ / sk_test_Development & testing
Productionpk_live_ / sk_live_Live transactions

Authentication Methods

curl -X POST https://api.pelago.tech/v1/payments \
-H "Authorization: Bearer pk_live_xxxxx" \
-H "X-Api-Secret: sk_live_xxxxx" \
-H "Content-Type: application/json" \
-d '{"amount": 100, "currency": "USD"}'

SDK Authentication

JavaScript:

import { PelagoClient } from '@pelago/sdk';

const pelago = new PelagoClient({
apiKey: process.env.PELAGO_API_KEY, // pk_live_xxxxx
apiSecret: process.env.PELAGO_API_SECRET, // sk_live_xxxxx
environment: 'production'
});

Python:

from pelago import PelagoClient
import os

pelago = PelagoClient(
api_key=os.environ['PELAGO_API_KEY'],
api_secret=os.environ['PELAGO_API_SECRET'],
environment='production'
)

Go:

import "github.com/polyflow/pelago-go"

client := pelago.NewClient(pelago.Config{
APIKey: os.Getenv("PELAGO_API_KEY"),
APISecret: os.Getenv("PELAGO_API_SECRET"),
Environment: pelago.Production,
})

Request Signing

For enhanced security, sign your requests:

import crypto from 'crypto';

function createSignedRequest(
method: string,
path: string,
body: object,
apiSecret: string
) {
const timestamp = Date.now();
const payload = `${timestamp}.${method}.${path}.${JSON.stringify(body)}`;

const signature = crypto
.createHmac('sha256', apiSecret)
.update(payload)
.digest('hex');

return {
'X-Pelago-Timestamp': timestamp.toString(),
'X-Pelago-Signature': signature
};
}

// Usage
const body = { amount: 100, currency: 'USD' };
const signatureHeaders = createSignedRequest(
'POST',
'/v1/payments',
body,
apiSecret
);

fetch('https://api.pelago.tech/v1/payments', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Api-Secret': apiSecret,
'Content-Type': 'application/json',
...signatureHeaders
},
body: JSON.stringify(body)
});

Key Security Best Practices

DO ✅

  • Store keys in environment variables
  • Use different keys for sandbox/production
  • Rotate keys every 90 days
  • Restrict key permissions if possible

DON'T ❌

  • Commit keys to version control
  • Share keys via insecure channels
  • Use production keys in development
  • Expose keys in client-side code

Key Rotation

Rotate your API keys regularly:

// 1. Generate new keys in dashboard
// 2. Update your environment variables
// 3. Verify new keys work
const test = await pelago.payments.list({ limit: 1 });

// 4. Delete old keys from dashboard

Scoped Keys (Enterprise)

For enterprise accounts, create scoped keys with limited permissions:

ScopePermissions
payments:readView payments only
payments:writeCreate & manage payments
settlements:readView settlements
refunds:writeProcess refunds
// Scoped key example
const pelago = new PelagoClient({
apiKey: 'pk_live_xxxxx_scoped',
apiSecret: 'sk_live_xxxxx',
environment: 'production'
});

// This key can only read payments
await pelago.payments.list(); // ✓ Works
await pelago.payments.create({...}); // ✗ Forbidden

Troubleshooting

Common Errors

ErrorCauseSolution
401 UnauthorizedInvalid/missing keysCheck key values
403 ForbiddenKey lacks permissionUse correct scope
429 Too Many RequestsRate limitedReduce request rate

Next Steps