Loading...

502 bad gateway error

The HTTP 502 Bad Gateway server error response code indicates that the server, while functioning as a gateway or proxy, has received an invalid response from the upstream server.

The cause of 502 bad gateway error

The occurrence of a 502 error is often related to either

  • Timeout: We support either 30 seconds or 120 seconds depends on the region.
  • Exceeding the maximum payload size: We support either 1 MB or 6 MB for the payload size depends on the region.

Each region has its own specific maximum response size and timeout, please find out more the limitations in the API Reference.

Question: I'm using an endpoint that supports up to 1 MB payload, so why am I still getting a 502 error message even though my PDF is only 866 KB?

The PDF binary is encoded in base64 between our app function and the load balancer/APIGateway. Base64 encoding causes an overhead of 33–37% (33% due to the encoding itself, and up to 4% more due to inserted line breaks). If a file is about 866 KB and you are using an endpoint with a maximum payload size of 1 MB, it is likely to exceed the 1 MB limit.

Solutions of bad gateway error

There are four potential solutions to address the 502 error:

1. Use export_type: json: If are using export_type: file and getting a 502 error, please consider using the export_type: json. By using export_type: json, the generated PDFs can be stored in our CDN rather than directly returned as a response. This approach helps bypass the limitations imposed by response size restrictions.

2. Async PDF generation : if the PDF generation takes a long time(>30 seconds or more) please consider using our async API to generate PDFs asynchronously.

3. Switch to an alternative region: Another option is to switch to an alternative region that supports a higher maximum response size or longer timeout. This can be a suitable choice when the current region's response size or timeout limitations are consistently reached. You can find out the limitations of each region here.

4. JSON data payload exceeds the maximum allowed payload size: please use the load_data_from paramater to load your JSON data from an external URL.