forge/backend/test_runway.py

57 lines
1.8 KiB
Python

import asyncio
import httpx
import os
import sys
# Add current dir to path to import app
sys.path.append(os.getcwd())
from app.config import settings
async def test_runway():
print(f"Testing Runway API with key: {settings.runway_api_key[:5]}...{settings.runway_api_key[-5:] if settings.runway_api_key else 'None'}")
headers = {
"Authorization": f"Bearer {settings.runway_api_key}",
"Content-Type": "application/json",
"X-Runway-Version": "2024-11-06"
}
async with httpx.AsyncClient() as client:
# 1. Test Video Endpoint (text_to_video)
print("\n1. Testing text_to_video endpoint...")
try:
resp = await client.post(
"https://api.dev.runwayml.com/v1/text_to_video",
headers=headers,
json={
"model": "gen4.5",
"promptText": "A cinematic shot of a robot",
"ratio": "1280:720",
"duration": 5
}
)
print(f"Status: {resp.status_code}")
print(f"Response: {resp.text[:200]}")
except Exception as e:
print(f"Error: {e}")
# 2. Test Image Endpoint (text_to_image - if exists)
print("\n2. Testing text_to_image endpoint...")
try:
resp = await client.post(
"https://api.dev.runwayml.com/v1/text_to_image",
headers=headers,
json={
"model": "gen4_image",
"promptText": "A cinematic shot of a robot",
"ratio": "1360:768"
}
)
print(f"Status: {resp.status_code}")
print(f"Response: {resp.text[:200]}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
asyncio.run(test_runway())