Skip to main content
Robust error handling is essential for production Serverless endpoints. It prevents your workers from crashing silently and ensures that useful error messages are returned to the client, making debugging significantly easier.

Basic error handling

The simplest way to handle errors is to wrap your handler logic in a try...except block. This ensures that even if your logic fails, the worker remains stable and returns a readable error message.

Structured error responses

For more complex applications, you should return consistent error objects. This allows the client consuming your API to programmatically handle different types of errors, such as validation failures versus unexpected server errors.

Timeout handling

You can also set an execution timeout in your endpoint settings to automatically terminate a job after a certain amount of time.
For long-running operations, you may want to implement timeout logic within your handler. This prevents a job from hanging indefinitely and consuming credits without producing a result.