This guide walks you through diagnosing and fixing HTTP 403 (Forbidden) and 429 (Too Many Requests) errors when calling the html2pdf app API. You’ll learn the most common causes, how to confirm each one, and the exact steps to resolve them—so your PDF generation works reliably again.
What You’ll Need
- Access to the server or client code that makes the html2pdf API request
- The API key or authentication token you use (if any)
- A tool to inspect HTTP requests/responses (browser DevTools, Postman, or curl)
- Your html2pdf account dashboard (to check quotas and usage)
Step-by-Step
- Reproduce the error and capture the full response. Make the same API call that fails and note the exact status code, response body, and any headers like
Retry-AfterorX-RateLimit-Remaining. If using curl, add-vto see headers. - Check your API key or authentication. For 403 errors, the most common cause is an invalid, expired, or missing API key. Confirm the key is correctly set in your request header (often
Authorization: Bearer YOUR_KEY) and that it hasn’t been rotated or revoked. Test the key directly with a minimal request to isolate the issue. - Verify your IP address is allowed. Some html2pdf plans restrict API access to specific IP addresses. If you’re behind a VPN, proxy, or a server with a dynamic IP, the request may be blocked. Check your account settings for an IP allowlist and add your current public IP.
- Check for CORS or origin restrictions (browser calls). If you call the API from a browser, a 403 can be caused by a missing or incorrect
Originheader. The API may only accept requests from domains you’ve registered. Ensure your domain is listed in the app dashboard and that your request includes the correctOriginheader. - Examine the request payload for forbidden content. Some html2pdf endpoints reject HTML that contains certain tags or scripts (like
<script>or external resources) for security reasons. Try a minimal HTML snippet to see if the 403 disappears. If it does, sanitize your HTML—remove scripts, iframes, or external URLs. - For 429 errors, check your rate limit and quota. Log into your html2pdf dashboard and look at your current usage. 429 means you’ve exceeded the allowed number of requests per minute/hour or the monthly quota. Note the limit and your current usage.
- Implement exponential backoff and retry logic. If you’re hitting rate limits, add a retry mechanism that waits longer after each failed attempt. For example, wait 1 second, then 2, 4, 8 seconds, up to a maximum. Respect any
Retry-Afterheader the API returns—it tells you exactly how long to wait. - Reduce the number of requests. Combine multiple HTML snippets into one request if possible, or cache generated PDFs so you don’t regenerate the same document repeatedly. Batch processing can also lower request frequency.
- Check if the API is down or under maintenance. A 403 or 429 might be a temporary server-side issue. Visit the html2pdf status page or try again after a few minutes. If the error persists, contact support with your request ID and timestamps.
- Review your code for accidental infinite loops. If your code retries automatically, a bug might cause it to fire requests in a tight loop, triggering 429. Add logging to see how many requests you’re actually sending per minute.
Common Mistakes
- Hardcoding API keys in client-side code. This exposes your key and can lead to 403 if it’s revoked, or 429 if someone else uses it. Always proxy requests through a server.
- Ignoring the
Retry-Afterheader. Many developers retry immediately after a 429, which makes the problem worse. Always wait the specified time. - Not checking the plan limits. Free or low-tier plans have strict quotas. You might be hitting a monthly cap that resets on a specific date.
- Sending HTML with unsupported tags. Some tags like
<script>are blocked by default. This is a security feature, not a bug. - Using a shared IP address. If you’re on a shared hosting server, other users’ traffic might exhaust the IP-based rate limit, causing 429 for you.
Tips
- Always use environment variables for your API key, never hardcode it.
- Log every API response with status, timestamp, and request ID. This makes debugging much faster.
- Test with a simple HTML string (like “
<p>Hello</p>”) to rule out content issues. - Set a user-agent header that identifies your application. Some APIs treat missing or generic user-agents as suspicious.
- Monitor your usage on the dashboard regularly, especially before peak usage times.
- Use a queue system for bulk PDF generation to stay within rate limits.
Troubleshooting
If the 403 persists after checking your key and IP: Try the request from a different network (e.g., mobile hotspot) to see if your IP is blocked. If it works, contact your network admin or html2pdf support to unblock you.
If you still get 429 even though your usage seems low: Check if you’re using a shared API key across multiple applications. Each app might be consuming the same quota. Create separate keys per application.
If the error occurs intermittently: It might be due to concurrent requests. Ensure your code isn’t sending multiple requests simultaneously without queuing.
If you’re behind a corporate proxy: The proxy might be adding headers or modifying your request, causing a 403. Try bypassing the proxy or whitelisting the html2pdf domain.
If the API returns a 403 with a message like “Invalid signature”: You might be using a signed request (e.g., HMAC). Double-check the signing algorithm and that your timestamp is within the allowed skew.
Frequently Asked Questions
Q: Can I increase my rate limit? Yes, usually by upgrading your html2pdf plan. Check the pricing page or contact sales.
Q: What does the 403 error message mean? It varies, but common messages include “Invalid API key,” “IP not allowed,” or “Origin not allowed.” Read the response body for details.
Q: How long does a rate limit last? It depends on the plan. Some limits reset every minute, others hourly or monthly. The Retry-After header gives the specific wait time.
Q: Can I use a wildcard in the allowed IP list? Some plans allow CIDR notation (e.g., 192.168.1.0/24). Check your dashboard.
Q: Does html2pdf have a sandbox or test environment? Many APIs offer a sandbox. Check the documentation for a test endpoint or a separate test API key.
Q: What should I do if the problem is on their side? Wait a few minutes and retry. If it’s still down, check their status page and contact support with your request ID.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Custom Alphanumeric Passcode iPhone: How to Set
- HomePod Software Update: How to Install
- How to Shuffle Photos in Slideshow on iPhone
- Quick Look Not Working on Mac? Fixes That Work
- How to See Deleted WhatsApp Messages on iPhone
- cat, head, or tail: Which Linux Command to Use