Authentication
Learn how to authenticate with the PayGate API.
Authentication
The PayGate API uses API keys to authenticate requests. You can view and manage your API keys in the Dashboard.
API Keys
Your API keys carry many privileges, so be sure to keep them secure. Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth.
Security Warning: Never expose your secret API key in client-side code or public repositories.
Key Types
| Key Type | Prefix | Description |
|---|---|---|
| Secret Key (Test) | sk_test_ | Use for server-side test mode requests |
| Secret Key (Live) | sk_live_ | Use for server-side production requests |
| Publishable Key (Test) | pk_test_ | Use for client-side test mode (checkout) |
| Publishable Key (Live) | pk_live_ | Use for client-side production (checkout) |
Making Authenticated Requests
Include your API key in the Authorization header using Bearer authentication:
curl https://api.44.200.142.19.nip.io/v1/payments \
-H "Authorization: Bearer sk_test_..." \
-H "Content-Type: application/json"import PayGate from '@paygate/node'
// The SDK handles authentication automatically
const paygate = new PayGate('sk_test_...')
const payments = await paygate.payments.list()import paygate
# The SDK handles authentication automatically
client = paygate.Client('sk_test_...')
payments = client.payments.list()<?php
$paygate = new \PayGate\PayGate('sk_test_...');
// The SDK handles authentication automatically
$payments = $paygate->payments->list();import "github.com/paygate/paygate-go"
// The SDK handles authentication automatically
client := paygate.New("sk_test_...")
payments, _ := client.Payments.List(nil)Error Responses
If authentication fails, you'll receive a 401 Unauthorized response:
{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "Invalid API key provided. Check that your API key is correct."
}
}Common Authentication Errors
| Error Code | Description | Solution |
|---|---|---|
invalid_api_key | The API key is invalid | Check your API key is correct |
expired_api_key | The API key has expired | Generate a new key in the Dashboard |
revoked_api_key | The API key was revoked | Generate a new key in the Dashboard |
test_key_on_live | Using test key for live endpoint | Use your live API key |
Best Practices
- Use environment variables - Store API keys in environment variables, never in code
- Rotate keys regularly - Generate new keys periodically for security
- Use separate keys - Use different keys for different environments/services
- Monitor usage - Review API logs in the Dashboard for unusual activity
// .env
PAYGATE_SECRET_KEY=sk_live_...
// app.ts
const paygate = new PayGate(process.env.PAYGATE_SECRET_KEY!)Webhook Signature Verification
For webhooks, we use a different authentication mechanism. Each webhook includes a signature in the X-PayGate-Signature header that you should verify. See Handling Webhooks for details.