Learn how to securely authenticate with the PDFen API using tokens, manage credentials, and follow security best practices.
PDFen API uses Bearer token authentication with Laravel Sanctum. Tokens are secure, easy to manage, and can be revoked instantly without changing your password.
Recommended Method
API tokens are the recommended authentication method for both v1 and v2 APIs. Username/password authentication (v1 only) will be disabled after 6 months.
curl https://pdfen.com/api/v2/user \
-H "Authorization: Bearer 1|abc123def456..."
Token Security
The token is displayed only once. Store it securely. If lost, you'll need to generate a new token.
Never hardcode tokens in your source code.
# .env file
PDFEN_API_TOKEN=1|abc123def456...
// PHP
$token = getenv('PDFEN_API_TOKEN');
Create separate tokens for development, staging, and production.
Add .env to your .gitignore file.
Each developer/server should have its own token.
Generate new tokens every 90 days for security.
Delete tokens that are no longer needed.
requests per hour
requests per hour
HTTP/1.1 200 OK
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 950
X-RateLimit-Reset: 1705320000
<?php
$response = $client->request('GET', '/api/v2/user');
$remaining = $response->getHeader('X-RateLimit-Remaining')[0];
if ($remaining < 10) {
// Slow down requests
sleep(60);
}
{
"error": "Unauthenticated",
"message": "Invalid or missing API token"
}
Solution: Check your token is correct and not revoked.
{
"error": "Rate limit exceeded",
"retry_after": 3600
}
Solution: Wait for the specified time or upgrade your account.
{
"error": "Insufficient permissions",
"required_ability": "convert:create"
}
Solution: Generate a new token with the required permissions.
For maximum security, rotate your API tokens every 90 days. Here's how to do it without downtime:
<?php
// Check token age
$tokenCreatedAt = strtotime($token->created_at);
$daysSinceCreation = (time() - $tokenCreatedAt) / 86400;
if ($daysSinceCreation > 90) {
// Trigger alert for manual rotation
notify_admins('API token needs rotation');
}