How to run video models on Replicate
Quick answer
Use the
replicate Python package to run video models by calling replicate.run() with the model name and video input parameters. Provide the video file path or URL in the input dictionary, then process the output which may include video URLs or metadata depending on the model.PREREQUISITES
Python 3.8+pip install replicateReplicate API token set as environment variable REPLICATE_API_TOKEN
Setup
Install the replicate Python package and set your Replicate API token as an environment variable for authentication.
pip install replicate
export REPLICATE_API_TOKEN="your_token_here" # Linux/macOS
setx REPLICATE_API_TOKEN "your_token_here" # Windows PowerShell output
Collecting replicate Downloading replicate-0.10.0-py3-none-any.whl (20 kB) Installing collected packages: replicate Successfully installed replicate-0.10.0 # No output for environment variable set command
Step by step
This example shows how to run a video model on Replicate by uploading a local video file and receiving the processed output URL.
import os
import replicate
# Initialize client with API token from environment
client = replicate.Client(api_token=os.environ["REPLICATE_API_TOKEN"])
# Example video model on Replicate (replace with actual model name)
model_name = "stability-ai/stable-video-diffusion"
# Path to local video file
video_path = "input_video.mp4"
# Run the model with video input
output = client.run(
model_name,
input={"video": open(video_path, "rb")}
)
print("Output:", output) output
Output: https://replicate.delivery/pbxt/abcd1234efgh5678/output_video.mp4
Common variations
- Use video URLs instead of local files by passing
{"video": "https://example.com/video.mp4"}as input. - Run asynchronously with
asyncioandreplicate.async_run()for non-blocking calls. - Switch models by changing the
model_nameto other video models available on Replicate.
import asyncio
import os
import replicate
async def run_video_model():
client = replicate.Client(api_token=os.environ["REPLICATE_API_TOKEN"])
model_name = "stability-ai/stable-video-diffusion"
output = await client.async_run(
model_name,
input={"video": "https://example.com/sample.mp4"}
)
print("Async output:", output)
asyncio.run(run_video_model()) output
Async output: https://replicate.delivery/pbxt/xyz9876output.mp4
Troubleshooting
- If you get authentication errors, verify your
REPLICATE_API_TOKENenvironment variable is set correctly. - For large video files, ensure your network connection is stable and consider using URLs instead of uploads.
- If the model fails, check the model documentation on Replicate for required input formats and supported video codecs.
Key Takeaways
- Use the official
replicatePython package with your API token for authentication. - Pass video inputs as file objects or URLs in the
inputparameter toclient.run(). - Async calls with
client.async_run()enable non-blocking video model execution. - Check model-specific input requirements on Replicate to avoid format or codec errors.