RunwayML - Image Generation
Overviewโ
| Property | Details |
|---|---|
| Description | RunwayML provides advanced AI-powered image generation with high-quality results |
| Provider Route on LiteLLM | runwayml/ |
| Supported Operations | /images/generations |
| Link to Provider Doc | RunwayML API โ |
LiteLLM supports RunwayML's Gen-4 image generation API, allowing you to generate high-quality images from text prompts.
Quick Startโ
Basic Image Generation
from litellm import image_generation
import os
os.environ["RUNWAYML_API_KEY"] = "your-api-key"
response = image_generation(
model="runwayml/gen4_image",
prompt="A serene mountain landscape at sunset",
size="1920x1080"
)
print(response.data[0].url)
Authenticationโ
Set your RunwayML API key:
Set API Key
import os
os.environ["RUNWAYML_API_KEY"] = "your-api-key"
Supported Parametersโ
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model to use (e.g., runwayml/gen4_image) |
prompt | string | Yes | Text description for the image |
size | string | No | Image dimensions (default: 1920x1080) |
Supported Sizesโ
1024x10241792x10241024x17921920x1080(default)1080x1920
Async Usageโ
Async Image Generation
from litellm import aimage_generation
import os
import asyncio
os.environ["RUNWAYML_API_KEY"] = "your-api-key"
async def generate_image():
response = await aimage_generation(
model="runwayml/gen4_image",
prompt="A futuristic city skyline at night",
size="1920x1080"
)
print(response.data[0].url)
asyncio.run(generate_image())
LiteLLM Proxy Usageโ
Add RunwayML to your proxy configuration:
config.yaml
model_list:
- model_name: gen4-image
litellm_params:
model: runwayml/gen4_image
api_key: os.environ/RUNWAYML_API_KEY
Start the proxy:
litellm --config /path/to/config.yaml
Generate images through the proxy:
Proxy Request
curl --location 'http://localhost:4000/v1/images/generations' \
--header 'Content-Type: application/json' \
--header 'x-litellm-api-key: sk-1234' \
--data '{
"model": "runwayml/gen4_image",
"prompt": "A serene mountain landscape at sunset",
"size": "1920x1080"
}'
Supported Modelsโ
| Model | Description | Default Size |
|---|---|---|
runwayml/gen4_image | High-quality image generation | 1920x1080 |
Cost Trackingโ
LiteLLM automatically tracks RunwayML image generation costs:
Cost Tracking
from litellm import image_generation, completion_cost
response = image_generation(
model="runwayml/gen4_image",
prompt="A serene mountain landscape at sunset",
size="1920x1080"
)
cost = completion_cost(completion_response=response)
print(f"Image generation cost: ${cost}")
Supported Featuresโ
| Feature | Supported |
|---|---|
| Image Generation | โ |
| Cost Tracking | โ |
| Logging | โ |
| Fallbacks | โ |
| Load Balancing | โ |
How It Worksโ
RunwayML uses an asynchronous task-based API pattern. LiteLLM handles the polling and response transformation automatically.
Complete Flow Diagramโ
What LiteLLM Does For Youโ
When you call litellm.image_generation() or /v1/images/generations:
- Request Transformation: Converts OpenAI image generation format โ RunwayML format
- Submits Task: Sends transformed request to RunwayML API
- Receives Task ID: Captures the task ID from the initial response
- Automatic Polling:
- Polls the task status endpoint every 2 seconds
- Continues until status is
SUCCEEDEDorFAILED - Default timeout: 10 minutes (configurable via
RUNWAYML_POLLING_TIMEOUT)
- Response Transformation: Converts RunwayML format โ OpenAI format
- Returns Result: Sends unified OpenAI format response to client
Polling Configuration:
- Default timeout: 600 seconds (10 minutes)
- Configurable via
RUNWAYML_POLLING_TIMEOUTenvironment variable - Uses sync (
time.sleep()) or async (await asyncio.sleep()) based on call type
info
Typical processing time: 10-30 seconds depending on image size and complexity