LoRA Integration Guide
API version: v1.2.4
Learn how to use custom LoRA models to generate videos with unique styles.
What is LoRA?
LoRA (Low-Rank Adaptation) models allow you to customize video generation with specific styles, characters, or visual effects. Each LoRA consists of two files:
- High noise file: Used during early denoising steps
- Low noise file: Used during later denoising steps
Step 1: Import Your LoRA
You can import LoRA models either by uploading files or providing URLs.
Option A: Import from URLs
Python
import requests
API_KEY = "your-api-key-here"
API_URL = "https://phosor.ai"
# Import LoRA from URLs
response = requests.post(
f"{API_URL}/api/v1/storage/lora/import",
headers={
"X-API-Key": API_KEY,
"Content-Type": "application/json"
},
json={
"high_noise_url": "https://example.com/high_noise.safetensors",
"low_noise_url": "https://example.com/low_noise.safetensors",
"name": "My Custom Style",
"default_scale": 1.0
}
)
result = response.json()
lora_id = result["lora_id"]
print(f"LoRA import started! ID: {lora_id}")Option B: Upload Files
Python
import requests
API_KEY = "your-api-key-here"
API_URL = "https://phosor.ai"
# Upload LoRA files
with open("high_noise.safetensors", "rb") as high_f, \
open("low_noise.safetensors", "rb") as low_f:
response = requests.post(
f"{API_URL}/api/v1/storage/lora/upload",
headers={"X-API-Key": API_KEY},
files={
"high_noise_file": high_f,
"low_noise_file": low_f
},
data={
"name": "My Custom Style",
"default_scale": 1.0
}
)
result = response.json()
lora_id = result["lora_id"]
print(f"LoRA upload started! ID: {lora_id}")Step 2: Wait for LoRA to be Ready
After importing, the LoRA needs processing time. Poll the status endpoint until it's ready.
Python
import time
def wait_for_lora(lora_id, api_key, timeout=300):
"""Wait for LoRA to be ready"""
start_time = time.time()
while time.time() - start_time < timeout:
response = requests.get(
f"{API_URL}/api/v1/loras/{lora_id}/status",
headers={"X-API-Key": api_key}
)
status = response.json()["status"]
print(f"Status: {status}")
if status == "ready":
print("LoRA is ready!")
return True
elif status == "failed":
print("LoRA processing failed")
return False
time.sleep(5)
print("Timeout waiting for LoRA")
return False
# Wait for the LoRA to be ready
wait_for_lora(lora_id, API_KEY)Step 3: Generate Video with LoRA
Once the LoRA is ready, use it in your video generation request.
Python
# Submit video generation with LoRA
response = requests.post(
f"{API_URL}/api/v1/inference/submit",
headers={
"X-API-Key": API_KEY,
"Content-Type": "application/json"
},
json={
"prompt": "A character walking through a garden",
"lora_id": lora_id,
"lora_scale": 0.8,
"num_frames": 81,
"frames_per_second": 16
}
)
request_id = response.json()["request_id"]
print(f"Video generation started! Request ID: {request_id}")Complete Example
Here's the full workflow in one script:
Python
import requests
import time
API_KEY = "your-api-key-here"
API_URL = "https://phosor.ai"
def import_lora_from_urls(high_url, low_url, name):
"""Import LoRA from URLs"""
response = requests.post(
f"{API_URL}/api/v1/storage/lora/import",
headers={
"X-API-Key": API_KEY,
"Content-Type": "application/json"
},
json={
"high_noise_url": high_url,
"low_noise_url": low_url,
"name": name,
"default_scale": 1.0
}
)
return response.json()["lora_id"]
def wait_for_lora(lora_id, timeout=300):
"""Wait for LoRA to be ready"""
start_time = time.time()
while time.time() - start_time < timeout:
response = requests.get(
f"{API_URL}/api/v1/loras/{lora_id}/status",
headers={"X-API-Key": API_KEY}
)
status = response.json()["status"]
if status == "ready":
return True
elif status == "failed":
return False
print(f"Status: {status}, waiting...")
time.sleep(5)
return False
def generate_video_with_lora(prompt, lora_id, lora_scale=0.8):
"""Generate video using LoRA"""
response = requests.post(
f"{API_URL}/api/v1/inference/submit",
headers={
"X-API-Key": API_KEY,
"Content-Type": "application/json"
},
json={
"prompt": prompt,
"lora_id": lora_id,
"lora_scale": lora_scale,
"num_frames": 81,
"frames_per_second": 16
}
)
return response.json()["request_id"]
# Full workflow
print("Step 1: Importing LoRA...")
lora_id = import_lora_from_urls(
"https://example.com/high_noise.safetensors",
"https://example.com/low_noise.safetensors",
"My Custom Style"
)
print(f"LoRA ID: {lora_id}")
print("\nStep 2: Waiting for LoRA to be ready...")
if wait_for_lora(lora_id):
print("\nStep 3: Generating video...")
request_id = generate_video_with_lora(
"A character in custom style walking in a park",
lora_id,
lora_scale=0.8
)
print(f"Video generation started! Request ID: {request_id}")
else:
print("Failed to prepare LoRA")LoRA Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
lora_id | string | - | UUID of the LoRA model (required) |
lora_scale | float | 1.0 | Strength of LoRA effect (0.0-1.0) |
lora_scale tips:
1.0: Full LoRA effect0.5-0.8: Balanced blend with base model0.1-0.4: Subtle influence
List Your LoRAs
View all your uploaded LoRA models:
Python
response = requests.get(
f"{API_URL}/api/v1/loras",
headers={"X-API-Key": API_KEY}
)
loras = response.json()["loras"]
for lora in loras:
print(f"- {lora['name']} ({lora['lora_id']}): {lora['status']}")Next Steps
- Upload LoRA Files - Detailed upload API
- LoRA Status - Check LoRA processing status
- List LoRAs - View all your LoRA models