{ "success": true, "data": { "id": "key_abc123", "name": "Production Integration", "key": "abc12345-xyz789def456ghi123jkl456mno789pqr", "prefix": "abc12345", "permissions": [ "linkedin:schedule", "linkedin:upload", "leads:read", "leads:write" ], "isActive": true, "createdAt": "2024-01-15T10:30:00Z", "expiresAt": "2025-01-15T10:30:00Z", "usageCount": 0 }, "message": "API key created successfully. Please store the key securely as it won't be shown again."}
Create a new API key for your account with granular permissions and optional expiration. This endpoint allows you to generate API keys programmatically for different use cases and team members.
You need an existing API key to create new ones. If you don’t have any API
keys yet, create your first one through the Buena.ai
dashboard.
# Use environment variablesexport BUENA_API_KEY="abc12345-xyz789..."# Never commit to version controlecho "BUENA_API_KEY=abc12345-xyz789..." >> .envecho ".env" >> .gitignore
Principle of Least Privilege
Only grant the minimum permissions needed:
Copy
// ❌ Too broadpermissions: ["*"]// ✅ Specific to use casepermissions: ["linkedin:schedule", "leads:read"]
Regular Rotation
Rotate keys regularly, especially for production:
Copy
// Rotate every 90 daysconst newKey = await createAPIKey({ name: "Production Key - Q1 2024", permissions: existingPermissions, expiresInDays: 90});// Update your application configuration// Deactivate old key after transition
{ "error": true, "code": "RATE_LIMIT_EXCEEDED", "message": "Too many API key creation requests", "version": "2.0", "timestamp": "2024-01-20T15:30:00Z", "retryAfter": 300}
Important Security Note: The full API key is only returned once during
creation. Store it immediately in a secure location. If you lose the key,
you’ll need to regenerate it or create a new one.