Reels Generator API
If (for some ungodly reason) you want to generate videos programatically, you can use the API directly.
Setup:Add the following to your
.env file:REELS_API_URL=https://nutoriousquan--reels-generator-api-fastapi-app.modal.run
API_KEY=<your api key here>Your API Key:
import requests
import os
class ReelsGeneratorClient:
def __init__(self, api_key: str, base_url: str):
self.api_key = api_key
self.base_url = base_url.rstrip('/')
self.session = requests.Session()
self.session.headers.update({
'X-API-Key': api_key,
'Content-Type': 'application/json'
})
def generate_video(self, subreddit: str, tts_provider: str = "free", background: str = "minecraft", tts_speed: float = 1.5, max_duration: int = 240, time_filter: str = "day,week,month"):
return self.session.post(
f"{self.base_url}/generate",
json={
"subreddit": subreddit,
"tts_provider": tts_provider,
"background": background,
"tts_speed": tts_speed,
"max_duration": max_duration,
"time_filter": time_filter
}
).json()
def get_status(self, job_id: str):
return self.session.get(f"{self.base_url}/status/{job_id}").json()
def download_video(self, job_id: str, output_path: str):
response = self.session.get(f"{self.base_url}/download/{job_id}")
with open(output_path, 'wb') as f:
f.write(response.content)
return output_path
def get_usage(self):
return self.session.get(f"{self.base_url}/usage").json()
def get_history(self, limit: int = 10):
return self.session.get(f"{self.base_url}/history", params={"limit": limit}).json()
# Example usage with polling
import time
client = ReelsGeneratorClient(api_key=os.getenv("API_KEY"), base_url=os.getenv("REELS_API_URL"))
print("Step 1: Initiating video generation...")
job = client.generate_video(
subreddit="EntitledPeople",
tts_provider="free",
background="minecraft",
tts_speed=1.5,
max_duration=240,
time_filter="day,week,month"
)
print(f"Step 2: Job created with ID: {job['job_id']}")
print("Step 3: Polling for job status every 5 seconds...")
while True:
status = client.get_status(job['job_id'])
print(f" Current status: {status.get('status', 'unknown')}")
if status.get('status') == 'completed':
print("Step 4: Video generation completed!")
print("Step 5: Downloading video...")
client.download_video(job['job_id'], "video.mp4")
print("Step 6: Video saved as video.mp4")
break
elif status.get('status') == 'failed':
print(f"Step 4: Video generation failed: {status.get('error_message', 'Unknown error')}")
break
time.sleep(5)
print("Step 7: Fetching usage stats...")
usage = client.get_usage()
print(f" Usage: {usage}")
print("Step 8: Fetching recent history...")
history = client.get_history(limit=5)
print(f" Recent jobs: {len(history)} found")
Other Endpoint Examples
import os
# Health check
response = client.session.get(f"{os.getenv('REELS_API_URL')}/health")
print(response.json())
# List backgrounds
response = client.session.get(f"{os.getenv('REELS_API_URL')}/backgrounds")
print(response.json())
# Check job status
job_id = "your_job_id_here"
status = client.session.get(f"{os.getenv('REELS_API_URL')}/status/{job_id}").json()
print("Job status:", status)
# Download video (if completed)
if status.get("status") == "completed":
video_response = client.session.get(f"{os.getenv('REELS_API_URL')}/download/{job_id}")
with open("video.mp4", "wb") as f:
f.write(video_response.content)
print("Video downloaded as video.mp4")
else:
print("Video not ready. Status:", status.get("status"))
# Get usage stats
usage = client.session.get(f"{os.getenv('REELS_API_URL')}/usage").json()
print("Usage stats:", usage)
# Get recent generation history
history = client.session.get(f"{os.getenv('REELS_API_URL')}/history", params={"limit": 5}).json()
print("Recent jobs:", history)