Overview

This guide covers battle-tested patterns for building reliable, scalable, and secure integrations with the Bluma API. Follow these practices to avoid common pitfalls and build production-grade applications.

Security

API Key Management

Environment Variables

Always store API keys in environment variables

Never Commit Keys

Add to .gitignore:

Rotate Regularly

Rotate production keys quarterly:
  1. Create new key
  2. Update application
  3. Deploy
  4. Delete old key

Separate Keys

Use different keys per environment:
  • Development: bluma_test_dev
  • Staging: bluma_test_staging
  • Production: bluma_live_prod

Webhook Security

Always verify webhook signatures:
Never skip signature verification in production. Unverified webhooks are a major security risk.

Client-Side Security

Never expose API keys in client-side code
Solution: Proxy requests through your backend:

Error Handling

Comprehensive Error Handling

Retry Logic with Exponential Backoff

Handling Rate Limits

Performance Optimization

Request Batching

Instead of making many sequential requests:
Batch them in parallel:
Respect rate limits when batching. If you hit rate limits, use a queue-based approach.

Request Queue

For high-volume applications, implement a queue:

Caching

Cache frequently accessed data:
What to cache:
  • ✅ Template list (changes rarely)
  • ✅ Your credit balance (update every 5-10 minutes)
  • ✅ Template details (static information)
What NOT to cache:
  • ❌ Video status (needs to be real-time)
  • ❌ Download URLs (expire after 1 hour)
  • ❌ API keys

Webhook Best Practices

Respond Immediately

Implement Idempotency

Monitor Delivery Failures

Monitoring & Logging

Structured Logging

Metrics Tracking

Usage Monitoring

Data Validation

Validate Inputs

Sanitize User Input

Configuration Management

Environment-Based Config

Feature Flags

Testing

Integration Tests

Mock for Unit Tests

Deployment Checklist

Before deploying to production:
  • API keys stored in environment variables
  • .env files added to .gitignore
  • Using production API key (bluma_live_*)
  • Error handling implemented for all API calls
  • Retry logic with exponential backoff
  • Rate limit handling configured
  • Webhook signature verification enabled
  • Webhook idempotency implemented
  • Logging configured (errors + info)
  • Monitoring/metrics tracking set up
  • Credit usage alerts configured
  • Integration tests passing
  • Load testing completed
  • Security audit performed
  • Rollback plan documented
  • On-call rotation established
  • Documentation updated

Common Anti-Patterns

❌ Polling Too Frequently

Solution: Use webhooks or poll every 5-10 seconds:

❌ Not Handling Async Errors

Solution: Always handle promise rejections:

❌ Ignoring Rate Limits

Solution: Use a queue or check rate limit headers:

Next Steps

Generate Your First Video

Complete video generation tutorial

Set Up Webhooks

Implement real-time event notifications

Test vs Production

Understand environment differences

Error Handling

Complete error reference

Summary

Following these best practices will help you build:
  • Secure integrations that protect API keys and verify webhooks
  • Reliable systems with proper error handling and retries
  • Scalable applications that respect rate limits and use queuing
  • Observable services with comprehensive logging and monitoring
  • Maintainable codebases with clean patterns and tests
Remember: Test thoroughly in the test environment before deploying to production!