Back to Guides

Authentication

Learn about API key types, environments, header formats, key rotation, and security best practices for the TrustRails API.

8 min read

Overview

The TrustRails API uses API keys for authentication. Each request must include a valid API key in the Authorization header. This guide covers everything you need to know about managing and using your API keys securely.

API Key Types

TrustRails provides three types of API keys, each designed for specific use cases:

Public Key (pk_)

Widget Only

Used exclusively for the TrustRails widget. Safe to include in frontend code.

tr_test_pk_abc123...

Secret Key (sk_)

Server Only

Used for server-side widget authentication. Exchange for a session token via the auth endpoint.

tr_test_sk_xyz789...

API Key (ak_)

Full API Access

Full access to the REST API. Create rollovers, query status, execute actions, and configure webhooks.

tr_test_ak_VG5oFY...

Environments

API keys are environment-specific. The key prefix indicates which environment it belongs to:

EnvironmentPrefixBase URLUse Case
Test / Sandboxtr_test_uat-api.trust-rails.comDevelopment & testing
Live / Productiontr_live_api.trust-rails.comProduction transactions

Authentication Header

Include your API key in the Authorization header using the Bearer scheme:

curl -X GET "https://api.trust-rails.com/v1/rollovers" \
-H "Authorization: Bearer tr_test_ak_YOUR_API_KEY" \
-H "Content-Type: application/json"

Alternatively, you can use the X-API-Key header:

Bash
curl -X GET "https://api.trust-rails.com/v1/rollovers" \
-H "X-API-Key: tr_test_ak_YOUR_API_KEY"

Key Rotation

Regular key rotation is a security best practice. To rotate your API key:

  1. Generate a new API key in the Integration Portal
  2. Update your application to use the new key
  3. Verify the new key works correctly
  4. Revoke the old key in the Integration Portal
Integration Portal showing how to revoke an old API key

Security Best Practices

Use Environment Variables

Never hardcode API keys in your source code. Use environment variables instead.

Bash
# .env file (never commit this!)
TRUSTRAILS_API_KEY=tr_test_ak_YOUR_API_KEY
# In your code
const apiKey = process.env.TRUSTRAILS_API_KEY;

Restrict Key Permissions

Only request the minimum permissions your application needs. If you only need to read rollover status, don't use a key with write permissions.

Monitor API Usage

Regularly review your API usage in the Integration Portal. Unusual patterns may indicate a compromised key.

Use IP Allowlisting

For production keys, consider enabling IP allowlisting to restrict which servers can use your API key.

Revoke Compromised Keys Immediately

If you suspect a key has been compromised (e.g., committed to a public repo), revoke it immediately in the Integration Portal and generate a new one.

Want Access to All Guides?

Schedule a call to get your API keys and full access to our integration guides.