How to use RunPod secure cloud
Quick answer
Use the
runpod Python package to interact with RunPod's secure cloud by setting your API key in runpod.api_key. Create an Endpoint instance with your endpoint ID and call run_sync with your input to run inference securely in the cloud.PREREQUISITES
Python 3.8+RunPod API keypip install runpod
Setup
Install the runpod Python package and set your API key from environment variables to authenticate with RunPod's secure cloud.
pip install runpod output
Collecting runpod Downloading runpod-1.0.0-py3-none-any.whl (10 kB) Installing collected packages: runpod Successfully installed runpod-1.0.0
Step by step
Use the runpod SDK to run inference on your secure cloud endpoint. Set your API key, create an Endpoint object with your endpoint ID, and call run_sync with your input prompt.
import os
import runpod
# Set your RunPod API key from environment variable
runpod.api_key = os.environ["RUNPOD_API_KEY"]
# Replace with your actual RunPod endpoint ID
endpoint_id = "YOUR_ENDPOINT_ID"
# Create an Endpoint instance
endpoint = runpod.Endpoint(endpoint_id)
# Input data for the model
input_data = {"prompt": "Hello, RunPod secure cloud!"}
# Run inference synchronously
result = endpoint.run_sync({"input": input_data})
# Print the output
print("Output:", result["output"]) output
Output: Hello, RunPod secure cloud! How can I assist you today?
Common variations
You can use asynchronous calls with run_async for non-blocking inference. Also, you can run serverless handlers inside RunPod pods by defining a handler function and starting the serverless environment.
import asyncio
import os
import runpod
runpod.api_key = os.environ["RUNPOD_API_KEY"]
endpoint_id = "YOUR_ENDPOINT_ID"
endpoint = runpod.Endpoint(endpoint_id)
async def main():
input_data = {"prompt": "Async call example"}
result = await endpoint.run_async({"input": input_data})
print("Async output:", result["output"])
asyncio.run(main()) output
Async output: Async call example received and processed.
Troubleshooting
- If you get an authentication error, verify your
RUNPOD_API_KEYenvironment variable is set correctly. - If the endpoint ID is invalid, double-check your RunPod dashboard for the correct endpoint identifier.
- For network timeouts, ensure your network allows outbound HTTPS requests to RunPod's API.
Key Takeaways
- Set
runpod.api_keyfrom environment variables for secure authentication. - Use
Endpoint.run_syncfor simple synchronous inference calls. - Use
Endpoint.run_asyncfor asynchronous, non-blocking calls. - Verify endpoint IDs and API keys in your RunPod dashboard to avoid errors.