Authentication overview
Bruzu's API authentication system is designed to provide secure access to its services, primarily through API keys. This method ensures that only authorized applications can interact with the Bruzu Dynamic Image API and other services, protecting both user data and system resources. When an API key is included in a request, it acts as a unique identifier and credential, allowing the Bruzu server to verify the sender's identity and determine their permissions. This approach is common in RESTful API design due to its simplicity and effectiveness for server-to-server communication and client-side applications where the key can be securely stored or managed.
The authentication process involves obtaining a unique API key from the Bruzu dashboard and then including this key in the headers of all API requests. Bruzu's documentation provides detailed instructions and examples for integrating these keys into various programming languages and SDKs, simplifying the development process for engineers. Adhering to secure handling practices for these keys is essential to prevent unauthorized access to your Bruzu account and the resources it manages.
Supported authentication methods
Bruzu primarily supports API Key authentication for all its API endpoints. This method involves using a secret key, generated from your Bruzu account, to authenticate your requests.
API Keys are typically passed in the Authorization header of an HTTP request as a Bearer token. This widely adopted standard for token-based authentication is defined in RFC 6750 for Bearer Token usage, which specifies how clients can use bearer tokens to access protected resources.
The table below summarizes the supported authentication method and its characteristics:
| Method | When to Use | Security Level |
|---|---|---|
| API Key (Bearer Token) | Programmatic access, server-side applications, limited client-side applications (with secure storage) | High (when managed securely) |
This method is suitable for most integration scenarios, including backend services, command-line tools, and web applications where the API key can be kept confidential. For client-side implementations, developers must ensure the key is not exposed to unauthorized users, often by routing requests through a secure backend or using environment variables during development.
Getting your credentials
To authenticate with Bruzu's API, you need to obtain an API key from your Bruzu account dashboard. The process typically involves these steps:
- Log into your Bruzu Account: Navigate to the Bruzu homepage and log in using your registered email and password. If you don't have an account, you will need to sign up first. Bruzu offers a free tier with 50 API calls per month, which is useful for initial testing and development.
- Access the Dashboard: After logging in, you will be directed to your user dashboard.
- Locate API Key Section: Within the dashboard, look for a section related to 'API Keys', 'Developer Settings', or 'Integrations'. The exact naming may vary, but it will typically be in a prominent location for developers. Consult the Bruzu official documentation for API key generation if you encounter difficulties.
- Generate a New API Key: You might have an existing key, or you may need to generate a new one. It's a good practice to generate distinct API keys for different applications or environments (e.g., development, staging, production) to enhance security and simplify key rotation. When generating a new key, you may be prompted to provide a name or description for it, which helps in identifying its purpose later.
- Copy the API Key: Once generated, the API key will be displayed. It is crucial to copy this key immediately and store it securely, as it may not be displayed again for security reasons. Treat your API key like a password.
Bruzu's API keys are long, alphanumeric strings designed to be unique identifiers and secure tokens. They grant access to your account's API resources, so their confidentiality is paramount. If you suspect an API key has been compromised, you should revoke it immediately from your Bruzu dashboard and generate a new one.
Authenticated request example
Once you have your API key, you can include it in your API requests. For Bruzu, this key is typically passed in the Authorization header with the Bearer scheme. Below are examples in Node.js and Python, two of Bruzu's primary language examples, demonstrating how to make an authenticated request to a hypothetical Bruzu endpoint.
Node.js Example
This Node.js example uses the node-fetch library to make an HTTP POST request to a Bruzu image generation endpoint.
const fetch = require('node-fetch');
const BRUZU_API_KEY = 'YOUR_BRUZU_API_KEY'; // Replace with your actual API key
const BRUZU_API_ENDPOINT = 'https://api.bruzu.com/v2/image'; // Example endpoint
async function createBruzuImage() {
try {
const response = await fetch(BRUZU_API_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${BRUZU_API_KEY}`,
},
body: JSON.stringify({
template_id: 'your_template_id',
data: {
title: 'Hello Bruzu',
subtitle: 'Generated with API Key'
}
}),
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(`Bruzu API error: ${response.status} ${response.statusText} - ${JSON.stringify(errorData)}`);
}
const imageData = await response.json();
console.log('Successfully created image:', imageData);
// The 'imageData' typically contains a URL to the generated image.
} catch (error) {
console.error('Error generating Bruzu image:', error);
}
}
createBruzuImage();
Python Example
This Python example uses the built-in requests library to make an HTTP POST request to the same Bruzu image generation endpoint.
import requests
import json
BRUZU_API_KEY = 'YOUR_BRUZU_API_KEY' # Replace with your actual API key
BRUZU_API_ENDPOINT = 'https://api.bruzu.com/v2/image' # Example endpoint
def create_bruzu_image():
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {BRUZU_API_KEY}',
}
payload = {
'template_id': 'your_template_id',
'data': {
'title': 'Hello Bruzu',
'subtitle': 'Generated with API Key'
}
}
try:
response = requests.post(BRUZU_API_ENDPOINT, headers=headers, data=json.dumps(payload))
response.raise_for_status() # Raises an HTTPError for bad responses (4xx or 5xx)
image_data = response.json()
print('Successfully created image:', image_data)
# The 'image_data' typically contains a URL to the generated image.
except requests.exceptions.HTTPError as http_err:
print(f'Bruzu API HTTP error: {http_err}')
print(f'Response content: {response.text}')
except Exception as err:
print(f'An unexpected error occurred: {err}')
if __name__ == '__main__':
create_bruzu_image()
In both examples, 'YOUR_BRUZU_API_KEY' should be replaced with your actual API key. It is critical to store this key securely, preferably using environment variables or a secret management system, rather than hardcoding it directly into your source code.
Security best practices
Securing your Bruzu API keys and ensuring the integrity of your API interactions is paramount. Adhering to these best practices helps mitigate common security risks:
- Keep API Keys Confidential: Treat your API key like a password. Never hardcode it directly into client-side code (e.g., JavaScript in browsers), public repositories, or send it directly from client-side applications without proxying through a secure backend.
- Use Environment Variables or Secret Management: Store API keys in environment variables for server-side applications or use dedicated secret management services (e.g., Google Cloud Secret Manager, AWS Secrets Manager) for more robust security. This prevents keys from being exposed in source code and simplifies rotation.
- Restrict Key Permissions (if applicable): While Bruzu's API keys currently offer full access to your account's API resources, always check if future updates allow for granular permissions. If so, create keys with the minimum necessary permissions for each application.
- Rotate API Keys Regularly: Periodically generate new API keys and revoke old ones. This practice limits the window of exposure if a key is ever compromised. A common rotation schedule might be every 90 days, or immediately if a compromise is suspected. Bruzu's dashboard provides features for managing your API keys, including revocation.
- Monitor API Usage: Regularly review your API usage patterns from the Bruzu dashboard. Unusual spikes in activity or requests from unexpected locations could indicate unauthorized use of your API key.
- Use HTTPS/TLS Everywhere: Ensure all communications with the Bruzu API are encrypted using HTTPS (TLS). This prevents eavesdropping and tampering with requests and responses. Bruzu's API endpoints are designed to only accept HTTPS connections, but it's important to confirm this in your client-side implementation.
- Implement Rate Limiting and Circuit Breakers: While Bruzu implements its own rate limiting to protect its infrastructure, implementing client-side rate limiting and circuit breakers in your application can prevent excessive API calls due to errors or malicious activity, potentially saving your API call quota and protecting your application from cascading failures.
- Validate and Sanitize Inputs: Always validate and sanitize any user-supplied data before incorporating it into API requests. This prevents injection attacks and ensures that your requests conform to the expected format, reducing the likelihood of errors or security vulnerabilities.
- Leverage SDKs: Use the official Bruzu SDKs (Node.js, Python, PHP, Ruby, Java, Go) when available. These SDKs are designed to handle authentication and other API interaction details securely and efficiently, reducing the risk of common implementation errors.
By consistently applying these security best practices, developers can significantly enhance the protection of their Bruzu integrations and the data they handle, ensuring a more secure and reliable operation.