Last Updated: January 4, 2025
There are two possible flows when generating from a single image:
/generate_no_preview with your base64 image and parameters/status until completion/download/model to obtain the final GLB/generate_preview with your base64 image and parameters/status until preview is ready/download/preview/{type} to view the previews/resume_from_preview/status until completion/download/model to obtain the final GLBSimilarly, there are two flows for multi-image generation:
/generate_multi_no_preview with your base64 images and parameters/status until completion/download/model to obtain the final GLB/generate_multi_preview with your base64 images and parameters/status until preview is ready/download/preview/{type} to view the previews/resume_from_preview/status until completion/download/model to obtain the final GLBimport requests
import base64
import time
# API endpoint
BASE_URL = "http://127.0.0.1:7960"
def generate_no_preview(image_base64: str):
"""Generate 3D model from a single base64-encoded image without previews.
Args:
image_base64: Base64 string of the image (without 'data:image/...' prefix)
"""
try:
# Set generation parameters
params = {
'image_base64': image_base64,
'seed': 42,
'ss_guidance_strength': 7.5,
'ss_sampling_steps': 30,
'slat_guidance_strength': 7.5,
'slat_sampling_steps': 30,
'mesh_simplify_ratio': 0.95,
'texture_size': 1024,
'output_format': 'glb'
}
# Start generation
print("Starting generation...")
response = requests.post(f"{BASE_URL}/generate_no_preview", data=params)
response.raise_for_status()
# Poll status until complete
while True:
status = requests.get(f"{BASE_URL}/status").json()
print(f"Progress: {status['progress']}%")
if status['status'] == 'COMPLETE':
break
elif status['status'] == 'FAILED':
raise Exception(f"Generation failed: {status['message']}")
time.sleep(1)
# Download the model
print("Downloading model...")
response = requests.get(f"{BASE_URL}/download/model")
response.raise_for_status()
return response.content
except Exception as e:
print(f"Error: {str(e)}")
return None
def generate_multi_preview(image_base64_list: list[str]):
"""Generate 3D model from multiple base64-encoded images with previews.
Args:
image_base64_list: List of base64 strings (without 'data:image/...' prefix)
"""
try:
# Set generation parameters
params = {
'image_list_base64': image_base64_list,
'seed': 42,
'ss_guidance_strength': 7.5,
'ss_sampling_steps': 30,
'slat_guidance_strength': 7.5,
'slat_sampling_steps': 30,
'preview_resolution': 512,
'preview_frames': 30,
'preview_fps': 30,
'mesh_simplify_ratio': 0.95,
'texture_size': 1024,
'output_format': 'glb'
}
# Start generation with preview
print("Starting generation...")
response = requests.post(f"{BASE_URL}/generate_multi_preview", data=params)
response.raise_for_status()
# Poll until preview is ready
while True:
status = requests.get(f"{BASE_URL}/status").json()
print(f"Progress: {status['progress']}%")
if status['status'] == 'PREVIEW_READY':
break
elif status['status'] == 'FAILED':
raise Exception(f"Generation failed: {status['message']}")
time.sleep(1)
# Download preview video
print("Downloading preview...")
preview = requests.get(f"{BASE_URL}/download/preview/gaussian")
preview.raise_for_status()
# Resume generation to get final model
print("Resuming generation for final model...")
resume_params = {
'mesh_simplify_ratio': 0.95,
'texture_size': 1024
}
response = requests.post(f"{BASE_URL}/resume_from_preview", params=resume_params)
response.raise_for_status()
# Wait for final model
while True:
status = requests.get(f"{BASE_URL}/status").json()
print(f"Progress: {status['progress']}%")
if status['status'] == 'COMPLETE':
break
elif status['status'] == 'FAILED':
raise Exception(f"Final generation failed: {status['message']}")
time.sleep(1)
# Download final model
print("Downloading final model...")
model = requests.get(f"{BASE_URL}/download/model")
model.raise_for_status()
return {
'preview': preview.content,
'model': model.content
}
except Exception as e:
print(f"Error: {str(e)}")
return None
Check server status and availability.
{
"status": "running",
"message": "Trellis API is operational",
"busy": boolean
}
Get the status of the current or last generation.
{
"status": string,
"progress": number,
"message": string,
"busy": boolean
}
Generate a 3D model without previews. Download GLB when complete.
Base64-encoded image data (without 'data:image/...' prefix)
Generate a 3D structure with previews. Download videos when ready.
Base64-encoded image data (without 'data:image/...' prefix)
Generate a 3D model using multiple images without previews.
List of base64-encoded images (without 'data:image/...' prefix)
Generate previews using multiple images.
List of base64-encoded images (without 'data:image/...' prefix)
Continue generation from a preview-ready state to create the final GLB model.
Ratio for mesh simplification
Size of the output texture
Cancel the current generation process.
Download preview video. Type can be: "gaussian" or "mesh".
Download the final 3D model (GLB format, with texture).
Random seed for generation
Structure sampling guidance strength
Structure sampling steps
SLAT guidance strength
SLAT sampling steps
Resolution for preview renders in pixels
Number of frames in preview videos
Frames per second for preview videos
Ratio for mesh simplification. Lower values create simpler meshes
Size of the output texture in pixels
Output format, either "glb" or "gltf"