Hidden Hill Video Generation API
This document describes the REST API for generating videos from PubMed papers using the video generation pipeline.
Before using the API, you need to set the following environment variables:
- GEMINI_API_KEY - Your Google Gemini API key (for text-to-speech and scene generation)
- RUNWAYML_API_SECRET - Your RunwayML API key (for video generation)
These can be set in your .env file for local development, or as environment variables in your deployment environment.
POST /api/generate/
Starts the video generation pipeline for a given PubMed ID or PMCID.
Request Body (JSON):
{
"paper_id": "PMC10979640",
"access_code": "your-access-code-here"
}Or as form data:
paper_id=PMC10979640&access_code=your-access-code-here
Note: The access_code is required to prevent unauthorized usage. Contact the administrator to obtain the access code.
Response (200 OK):
{
"success": true,
"paper_id": "PMC10979640",
"status_url": "/api/status/PMC10979640/",
"result_url": "/api/result/PMC10979640/",
"message": "Pipeline started successfully"
}Error Responses:
400 Bad Request: Missing or invalidpaper_id403 Forbidden: Invalid or missingaccess_code409 Conflict: Pipeline already running for this paper_id500 Internal Server Error: Missing API keys or other server errors
Example using curl:
curl -X POST http://localhost:8000/api/generate/ \
-H "Content-Type: application/json" \
-d '{"paper_id": "PMC10979640"}'GET /api/status/<paper_id>/
Returns the current status and progress of the video generation pipeline.
Response (200 OK):
{
"paper_id": "PMC10979640",
"status": "running",
"current_step": "generate-videos",
"completed_steps": ["fetch-paper", "generate-script", "generate-audio"],
"progress_percent": 60,
"final_video_url": null,
"log_tail": "Last 8KB of pipeline log output..."
}Status Values:
pending: Pipeline hasn't started yetrunning: Pipeline is currently executingcompleted: Pipeline finished successfullyfailed: Pipeline encountered an error
Pipeline Steps:
fetch-paper- Download paper from PubMed Centralgenerate-script- Generate video script with scenes using Geminigenerate-audio- Generate text-to-speech audio for narrationgenerate-videos- Generate video clips using RunwayML Veo 3.1 (4 steps total - captions step has been removed)
Example using curl:
curl http://localhost:8000/api/status/PMC10979640/GET /api/result/<paper_id>/
Returns the final video URL when generation is complete.
Response (200 OK) - Video Ready:
{
"paper_id": "PMC10979640",
"success": true,
"video_url": "/media/PMC10979640/final_video.mp4",
"status": "completed",
"progress_percent": 100
}Response (202 Accepted) - Video Not Ready:
{
"paper_id": "PMC10979640",
"success": false,
"error": "Video not ready yet",
"status": "running",
"progress_percent": 60,
"status_url": "/api/status/PMC10979640/"
}Example using curl:
curl http://localhost:8000/api/result/PMC10979640/Here's a complete example of using the API to generate a video:
import requests
import time
BASE_URL = "http://localhost:8000"
# 1. Start generation
response = requests.post(
f"{BASE_URL}/api/generate/",
json={
"paper_id": "PMC10979640",
"access_code": "your-access-code-here" # Required!
}
)
data = response.json()
print(f"Started: {data['message']}")
# 2. Poll for status
paper_id = data["paper_id"]
status_url = data["status_url"]
while True:
response = requests.get(f"{BASE_URL}{status_url}")
status = response.json()
print(f"Status: {status['status']} - {status['progress_percent']}%")
print(f"Current step: {status['current_step']}")
if status["status"] == "completed":
print(f"Video ready: {status['final_video_url']}")
break
elif status["status"] == "failed":
print("Pipeline failed!")
print(status.get("log_tail", ""))
break
time.sleep(5) # Poll every 5 seconds
# 3. Get final result
response = requests.get(f"{BASE_URL}/api/result/{paper_id}/")
result = response.json()
if result["success"]:
print(f"Final video: {BASE_URL}{result['video_url']}")The web application also provides a user-friendly interface:
- Upload Page:
/upload/- Submit a PubMed ID or upload a file - Status Page:
/status/<pmid>/- View pipeline status with progress - Result Page:
/result/<pmid>/- View the final generated video
- The pipeline typically takes 5-15 minutes depending on the number of scenes and video generation time
- Videos are stored in
MEDIA_ROOT/<paper_id>/final_video.mp4 - The pipeline is idempotent - it will skip already completed steps if restarted
- All intermediate files (paper.json, script.json, audio files, video clips) are saved in the output directory for debugging
If the pipeline fails, check:
- The
log_tailfield in the status response for error messages - The full log file at
MEDIA_ROOT/<paper_id>/pipeline.log - Ensure API keys are correctly set in environment variables
- Verify the PubMed ID is valid and the paper is available in PubMed Central (open access)