Authentication

Learn how to securely authenticate your SDK requests.

API Keys

The SDK uses API keys for authentication. You can obtain an API key from your dashboard.

Important: Never expose your API keys in client-side code or commit them to version control.

Basic Authentication

Pass your API key when initializing the SDK:

auth.ts
import { SDK } from "our-sdk";
const sdk = new SDK({
apiKey: process.env.SDK_API_KEY,
});

Environment Variables

Store your API key in environment variables:

Terminal

Then access it in your code:

auth.ts
const sdk = new SDK({
apiKey: process.env.SDK_API_KEY,
});

Testing vs Production

Use different API keys for testing and production:

environment-config.ts
const sdk = new SDK({
apiKey:
process.env.NODE_ENV === "production"
? process.env.SDK_API_KEY_PROD
: process.env.SDK_API_KEY_TEST,
environment:
process.env.NODE_ENV === "production" ? "production" : "development",
});

Key Rotation

If your API key is compromised:

  1. Generate a new key in your dashboard
  2. Update your environment variables
  3. Revoke the old key
  4. Restart your application

If you believe your API key has been compromised, rotate it immediately.

Best Practices

✅ Do

  • Store keys in environment variables
  • Use different keys for different environments
  • Rotate keys periodically
  • Use server-side code for sensitive operations

❌ Don't

  • Commit keys to version control
  • Share keys between projects
  • Use production keys in development
  • Expose keys in client-side code

Custom Headers

You can add custom headers for additional security:

custom-headers.ts
const sdk = new SDK({
apiKey: process.env.SDK_API_KEY,
options: {
headers: {
"X-Custom-Header": "value",
},
},
});

Rate Limiting

API keys are subject to rate limits:

  • Free tier: 100 requests/minute
  • Pro tier: 1,000 requests/minute
  • Enterprise: Custom limits

Handle rate limit errors gracefully:

rate-limit-handling.ts
try {
await sdk.getData({ id: "123" });
} catch (error) {
if (error instanceof SDK.RateLimitError) {
console.log("Rate limit exceeded. Retry after:", error.retryAfter);
// Implement exponential backoff
}
}

Next Steps