Trust Rails
Solutions
About
Log in
Back to Guides

Authentication

Everything you need to securely authenticate with the TrustRails API — key types, environments, and best practices for production.

8 min read

Overview

Every request to the TrustRails API must include a valid API key in the Authorization header (Bearer scheme) or the X-API-Key header. Keys are scoped by environment and type, so you can safely separate development from production.

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 and GraphQL 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:

You can rotate keys via the Integration Portal or programmatically via the API:

cURL
curl -X POST "https://api.trust-rails.com/v1/api-keys/rotate" \
-H "Authorization: Bearer tr_test_ak_YOUR_CURRENT_KEY"

If you prefer the portal, follow these steps:

  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

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;

Use the Right Key Type

Use the most restrictive key type for your use case. If you only need the widget, use a public key (pk_). Reserve API keys (ak_) for server-side integrations that need full access.

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.

Ready to Get Started?

Explore more guides or request sandbox access to start building on TrustRails