Skip to main content
Interacting with Runpod’s Endpoints is a core feature of the SDK, enabling the execution of tasks and the retrieval of results. This section covers the synchronous and asynchronous execution methods, along with checking the status of operations.

Prerequisites

Before using the Runpod Go SDK, ensure that you have:

Set your Endpoint Id

Set your Runpod API key and your Endpoint Id as environment variables.
This allows all calls to pass through your Endpoint Id with a valid API key. The following are actions you use on the Here is the revised documentation based on the Go Sample:

Run the Endpoint

Run the Endpoint using either the asynchronous run 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 the runSync 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 the run 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 the status method and specify the id of the run to get the status of a run.

Cancel

You can cancel a Job request by using the cancel() 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 the RequestTimeout field in the RunInput struct.

Execution policy

You can specify the TTL (Time-to-Live) and ExecutionTimeout values for the job using the Input map of the JobInput struct.
For more information, see Execution policy.

Purge Queue

Create an instance of the PurgeQueueInput struct and set the desired values. Call the PurgeQueue method of the Endpoint with the PurgeQueueInput instance. PurgeQueue() doesn’t affect Jobs in progress.