Prerequisites
Before using the Runpod Go SDK, ensure that you have:- Installed the Runpod Go SDK.
- Configured your API key.
Set your Endpoint Id
Set your Runpod API key and your Endpoint Id as environment variables.Run the Endpoint
Run the Endpoint using either the asynchronousrun
or synchronous runSync
method.
Choosing between asynchronous and synchronous execution hinges on your task’s needs and application design.
Run synchronously
To execute an endpoint synchronously and wait for the result, use therunSync
method on your endpoint. This method blocks the execution until the endpoint run is complete or until it times out.
Run asynchronously
Asynchronous execution allows for non-blocking operations, enabling your code to perform other tasks while waiting for an operation to complete. For non-blocking operations, use therun
method on the endpoint. This method allows you to start an endpoint run and then check its status or wait for its completion at a later time.
Get results from an asynchronous run
The following example shows how to get the results of an asynchronous run.Stream
Stream allows you to stream the output of an Endpoint run. To enable streaming, your handler must support the"return_aggregate_stream": True
option on the start
method of your Handler. Once enabled, use the stream
method to receive data as it becomes available.
The maximum size for a payload that can be sent using yield to stream results is 1 MB.
Health check
Monitor the health of an endpoint by checking its status, including jobs completed, failed, in progress, in queue, and retried, as well as the status of workers.Status
Use thestatus
method and specify the id
of the run to get the status of a run.
Cancel
You can cancel a Job request by using thecancel()
function on the run request. You might want to cancel a Job because it’s stuck with a status of IN_QUEUE
or IN_PROGRESS
, or because you no longer need the result.
Timeout
You can set the maximum time to wait for a response from the endpoint using theRequestTimeout
field in the RunInput
struct.
Execution policy
You can specify the TTL (Time-to-Live) and ExecutionTimeout values for the job using theInput
map of the JobInput
struct.
Purge Queue
Create an instance of thePurgeQueueInput
struct and set the desired values. Call the PurgeQueue
method of the Endpoint with the PurgeQueueInput
instance.
PurgeQueue()
doesn’t affect Jobs in progress.