How to get started with RunPod
Quick answer
Use the
runpod Python package by setting your API key in runpod.api_key. Create an Endpoint instance with your RunPod endpoint ID, then call run_sync with your input prompt to get AI model output.PREREQUISITES
Python 3.8+RunPod API key (set as environment variable RUNPOD_API_KEY)pip install runpod
Setup
Install the runpod Python package and set your API key as an environment variable RUNPOD_API_KEY. This key authenticates your requests to RunPod's serverless AI endpoints.
pip install runpod
# In your shell, set the API key:
# export RUNPOD_API_KEY=os.environ["RUNPOD_API_KEY"] 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 package to create an Endpoint object with your endpoint ID. Call run_sync with your input prompt to get the AI model's response.
import os
import runpod
# Set API key from environment
runpod.api_key = os.environ["RUNPOD_API_KEY"]
# Replace with your actual RunPod endpoint ID
endpoint_id = "YOUR_ENDPOINT_ID"
endpoint = runpod.Endpoint(endpoint_id)
# Input prompt for the model
input_data = {"prompt": "Hello, RunPod!"}
# Run inference synchronously
result = endpoint.run_sync({"input": input_data})
print("Model output:", result["output"]) output
Model output: Hello, RunPod! How can I assist you today?
Common variations
You can use run_async for asynchronous calls if your application supports async. Change the input structure depending on your model's requirements. RunPod supports various AI models, so adjust endpoint_id accordingly.
import asyncio
import os
import runpod
runpod.api_key = os.environ["RUNPOD_API_KEY"]
endpoint = runpod.Endpoint("YOUR_ENDPOINT_ID")
async def main():
input_data = {"prompt": "Async call example"}
result = await endpoint.run_async({"input": input_data})
print("Async model output:", result["output"])
asyncio.run(main()) output
Async model 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, check your RunPod dashboard for the correct endpoint identifier.
- For network timeouts, ensure your internet connection is stable and retry.
Key Takeaways
- Set your RunPod API key in the environment variable
RUNPOD_API_KEYbefore using the SDK. - Use
runpod.Endpointwith your endpoint ID to interact with your deployed AI model. - Call
run_syncorrun_asyncto send inputs and receive outputs from RunPod. - Check your endpoint ID and API key carefully to avoid authentication or endpoint errors.