Testing your handler locally before deploying saves time and helps you catch issues early. The Runpod SDK provides multiple ways to test your handler function without consuming cloud resources.Documentation Index
Fetch the complete documentation index at: https://runpod-b18f5ded-promptless-remove-flash-beta-notification.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Basic testing
The simplest way to test your handler is by running it directly with test input.Inline JSON
Pass test input directly via the command line:Test file
For more complex or reusable test inputs, create atest_input.json file in the same directory as your handler:
test_input.json
test_input.json file.
If you provide both a
test_input.json file and the --test_input flag, the command-line input takes precedence.Local API server
For more comprehensive testing, start a local API server that simulates your Serverless endpoint. This lets you send HTTP requests to test your handler as if it were deployed. Start the local server:http://localhost:8000.
Send requests to the server
Once your local server is running, send HTTPPOST requests from another terminal to test your function:
The
/run endpoint only returns a fake request ID without executing your code, since async mode requires communication with Runpod’s system. For local testing, use /runsync to execute your handler and get results immediately.Testing concurrency
To test how your handler performs under parallel execution, use the--rp_api_concurrency flag to set the number of concurrent workers.
This command starts your local server with 4 concurrent workers:
Testing concurrent requests
Send multiple requests simultaneously to test concurrency:Handling concurrency in your code
If your handler uses shared state (like global variables), use proper synchronization to avoid race conditions:Debugging
Log levels
Control the verbosity of console output with the--rp_log_level flag:
ERROR: Only show error messages.WARN: Show warnings and errors.INFO: Show general information, warnings, and errors.DEBUG: Show all messages, including detailed debug information.
Enable the debugger
Use the--rp_debugger flag for detailed troubleshooting:
Server configuration
Customize the local API server with these flags:Port
Set a custom port (default is 8000):Host
Set the hostname (default is “localhost”):Flag reference
Here’s a complete reference of all available flags for local testing:| Flag | Description | Default | Example |
|---|---|---|---|
--rp_serve_api | Starts the local API server | N/A | --rp_serve_api |
--rp_api_port | Sets the server port | 8000 | --rp_api_port 8080 |
--rp_api_host | Sets the server hostname | ”localhost” | --rp_api_host 0.0.0.0 |
--rp_api_concurrency | Sets concurrent workers | 1 | --rp_api_concurrency 4 |
--rp_log_level | Controls log verbosity | INFO | --rp_log_level DEBUG |
--rp_debugger | Enables the debugger | Disabled | --rp_debugger |
--test_input | Provides test input as JSON | N/A | --test_input '{"input": {}}' |
Combined example
You can combine multiple flags to create a customized local testing environment:- Starts the local API server on port 8080.
- Uses 4 concurrent workers.
- Sets the log level to
DEBUGfor maximum information. - Enables the debugger for troubleshooting.