BRIA API
BRIA¶
BRIA provides advanced image generation and editing capabilities with comprehensive support for professional image workflows, product photography, and creative transformations.
This section provides comprehensive examples for all BRIA API endpoints available in Vision Studio.
Prerequisites¶
import requests
import json
import base64
# Your API endpoint and key
API_URL = "http://localhost:8527/api/v1/bria"
API_KEY = "your-api-key"
headers = {
"X-API-Key": API_KEY,
"Content-Type": "application/json"
}
Prompt Enhancement¶
Enhance your prompts using LLama 3 for better results.
# Note: This endpoint uses form data, not JSON
response = requests.post(
f"{API_URL}/prompt/enhance-prompt",
headers={"X-API-Key": API_KEY}, # No Content-Type for form data
data={"prompt": "cat sitting on a chair"}
)
Image Generation¶
1. Generate Image (Base Model)¶
Generate high-quality images using BRIA's base model with extensive customization options.
data = {
"bria_model_version": "3.2",
"prompt": "A majestic mountain landscape with snow-capped peaks at sunset",
"num_results": 2,
"aspect_ratio": "16:9",
"sync": True,
"steps_num": 30,
"text_guidance_scale": 7.5,
"prompt_enhancement": True,
"seed": 12345,
"negative_prompt": "blurry, low quality, distorted",
"medium": "photography"
}
response = requests.post(
f"{API_URL}/image/generation/generate-image",
headers=headers,
json=data
)
With Guidance Methods¶
# Using ControlNet guidance
with open("reference_image.jpg", "rb") as f:
image_base64 = base64.b64encode(f.read()).decode()
data = {
"bria_model_version": "2.3", # Required for guidance methods
"prompt": "Modern architecture building",
"num_results": 1, # Use 1 when using guidance methods
"aspect_ratio": "4:3",
"sync": True,
"steps_num": 30,
"text_guidance_scale": 6.0,
"prompt_enhancement": False,
"guidance_method_1": "controlnet_canny",
"guidance_method_1_scale": 0.8,
"guidance_method_1_image_file": image_base64,
"guidance_method_2": "controlnet_depth",
"guidance_method_2_scale": 0.6,
"guidance_method_2_image_url": "https://example.com/depth_map.jpg",
"seed": 2222,
"negative_prompt": "blurry, distorted",
"medium": "photography"
}
response = requests.post(
f"{API_URL}/image/generation/generate-image",
headers=headers,
json=data
)
With Image Prompts¶
data = {
"bria_model_version": "2.3",
"prompt": "Artistic rendering in this style",
"num_results": 1,
"aspect_ratio": "1:1",
"sync": True,
"steps_num": 25,
"text_guidance_scale": 5.0,
"prompt_enhancement": False,
"image_prompt_mode": "style_only",
"image_prompt_urls": ["https://example.com/style_reference.jpg"],
"image_prompt_scale": 0.7,
"seed": 3333,
"medium": "art"
}
response = requests.post(
f"{API_URL}/image/generation/generate-image",
headers=headers,
json=data
)
2. Generate Image (Fast Model)¶
Quick image generation with reduced processing time.
data = {
"bria_model_version": "2.3",
"prompt": "A cute puppy playing in a garden",
"num_results": 1,
"aspect_ratio": "1:1",
"sync": True,
"steps_num": 8,
"prompt_enhancement": False,
"seed": 9876,
"medium": "photography"
}
response = requests.post(
f"{API_URL}/image/generation/generate-image-fast",
headers=headers,
json=data
)
3. Generate Image (HD Model)¶
High-resolution image generation for detailed outputs.
data = {
"bria_model_version": "2.2",
"prompt": "Ultra-detailed close-up of a butterfly on a flower",
"num_results": 1,
"aspect_ratio": "3:2",
"sync": True,
"steps_num": 40,
"text_guidance_scale": 8.0,
"prompt_enhancement": True,
"negative_prompt": "blurry, pixelated, low resolution",
"medium": "photography"
}
response = requests.post(
f"{API_URL}/image/generation/generate-image-hd",
headers=headers,
json=data
)
4. Generate Vector Graphics (Base)¶
Create high-quality vector graphics with full customization.
data = {
"bria_model_version": "3.2",
"prompt": "Minimalist logo design with geometric shapes",
"num_results": 1,
"aspect_ratio": "1:1",
"sync": True,
"steps_num": 35,
"text_guidance_scale": 6.0,
"seed": 5555,
"negative_prompt": "complex, cluttered, photorealistic"
}
response = requests.post(
f"{API_URL}/image/generation/generate-vector-base",
headers=headers,
json=data
)
5. Generate Vector Graphics (Fast)¶
Rapid vector graphic generation.
data = {
"bria_model_version": "2.3",
"prompt": "Simple icon design for mobile app",
"num_results": 2,
"aspect_ratio": "1:1",
"sync": False,
"steps_num": 6,
"seed": 1111
}
response = requests.post(
f"{API_URL}/image/generation/generate-vector-fast",
headers=headers,
json=data
)
6. Generate Variations¶
Create variations of existing images while maintaining structure.
data = {
"prompt": "Transform this into a watercolor painting",
"num_results": 3,
"sync": True,
"fast": True,
"steps_num": 15,
"ref_image_influence": 0.8,
"image_url": "https://example.com/source_image.jpg",
"seed": 7777,
"include_generation_prefix": True
}
response = requests.post(
f"{API_URL}/image/generation/generate-variation",
headers=headers,
json=data
)
Image Editing¶
1. Expand Image¶
Expand images to larger canvases with AI-generated content.
Using Canvas Size with Position¶
data = {
"image_url": "https://example.com/portrait.jpg",
"canvas_size": [1024, 1024], # Will be converted to tuple by Pydantic
"position": "center",
"prompt": "Beautiful sunset background",
"negative_prompt": "buildings, urban elements",
"seed": 4444
}
response = requests.post(
f"{API_URL}/image/editing/expand-image",
headers=headers,
json=data
)
Using Aspect Ratio with Custom Padding¶
# Assuming image_base64 is defined from earlier example
data = {
"image_file": image_base64,
"aspect_ratio": "16:9",
"padding_left": 0.1,
"padding_right": 0.1,
"padding_top": 0.2,
"padding_bottom": 0.05,
"prompt": "Mountain landscape background",
"negative_prompt": "city, buildings",
"seed": 3333
}
response = requests.post(
f"{API_URL}/image/editing/expand-image",
headers=headers,
json=data
)
2. Remove Background¶
Remove backgrounds from images automatically.
data = {
"image_url": "https://example.com/product_photo.jpg"
}
response = requests.post(
f"{API_URL}/image/editing/remove-background",
headers=headers,
json=data
)
3. Product Cutout¶
Create precise product cutouts with advanced options.
data = {
"image_url": "https://example.com/product_with_background.jpg",
"force_rmbg": True
}
response = requests.post(
f"{API_URL}/image/editing/product-cutout",
headers=headers,
json=data
)
4. Crop Foreground¶
Crop the main subject with customizable padding.
data = {
"image_url": "https://example.com/full_scene.jpg",
"padding": 50,
"force_rmbg": False
}
response = requests.post(
f"{API_URL}/image/editing/crop-foreground",
headers=headers,
json=data
)
5. Get Segmentation Masks¶
Generate segmentation masks for different objects in an image.
data = {
"image_url": "https://example.com/multi_object_scene.jpg"
}
response = requests.post(
f"{API_URL}/image/editing/get-masks",
headers=headers,
json=data
)
6. Inpainting¶
Fill masked regions with AI-generated content.
Manual Mask¶
data = {
"mask_type": "manual",
"prompt": "red sports car",
"num_results": 2,
"sync": True,
"image_url": "https://example.com/street_scene.jpg",
"mask_url": "https://example.com/mask.png",
"negative_prompt": "bicycle, motorcycle",
"seed": 4444
}
response = requests.post(
f"{API_URL}/image/editing/inpaint",
headers=headers,
json=data
)
Border Only (Extend Image Borders)¶
data = {
"mask_type": "border_only",
"prompt": "continue the forest scenery",
"border_percentage": 0.15,
"num_results": 1,
"sync": True
}
7. Blur Background¶
Apply depth-of-field blur effect to backgrounds.
data = {
"image_url": "https://example.com/portrait.jpg",
"blur_scale": 3,
"force_rmbg": False
}
response = requests.post(
f"{API_URL}/image/editing/blur-background",
headers=headers,
json=data
)
Background Generation¶
1. Generate Solid Background¶
Create professional product shots with solid backgrounds.
data = {
"image_url": "https://example.com/product_cutout.png",
"background_color": "#FFFFFF", # or "transparent"
"force_rmbg": True
}
response = requests.post(
f"{API_URL}/image/editing/generate-solid-background",
headers=headers,
json=data
)
2. Generate Background¶
Replace backgrounds using reference images or text prompts.
With Reference Image¶
data = {
"image_url": "https://example.com/subject.jpg",
"ref_image_url": "https://example.com/background_reference.jpg",
"enhance_ref_image": True,
"num_results": 2,
"sync": True,
"fast": False,
"force_rmbg": True
}
response = requests.post(
f"{API_URL}/image/editing/generate-background",
headers=headers,
json=data
)
With Text Prompt¶
data = {
"image_url": "https://example.com/subject.jpg",
"bg_prompt": "Tropical beach with palm trees and sunset",
"refine_prompt": True,
"original_quality": True,
"negative_prompt": "urban, city, buildings",
"seed": 8888
}
3. Generate Product Shadow¶
Add realistic shadows to product images.
Regular Shadow¶
data = {
"image_url": "https://example.com/product_cutout.png",
"shadow_type": "regular",
"shadow_color": "#000000",
"shadow_intensity": 70,
"shadow_offset": [5, 20], # [x, y] offset in pixels
"shadow_blur": 15,
"background_color": "#F5F5F5",
"force_rmbg": False
}
response = requests.post(
f"{API_URL}/image/editing/generate-product-shadow",
headers=headers,
json=data
)
Floating Shadow with Custom Dimensions¶
data = {
"image_url": "https://example.com/product_cutout.png",
"shadow_type": "float",
"shadow_color": "#333333",
"shadow_intensity": 50,
"shadow_offset": [0, 25],
"shadow_blur": 20,
"shadow_width": 200, # Width of elliptical shadow
"shadow_height": 70, # Height of elliptical shadow
"background_color": "transparent",
"force_rmbg": True
}
response = requests.post(
f"{API_URL}/image/editing/generate-product-shadow",
headers=headers,
json=data
)
4. Generate Product Background by Text¶
Place products in lifestyle scenes using text descriptions.
data = {
"scene_description": "Modern kitchen with marble countertops and natural lighting",
"image_url": "https://example.com/product.png",
"sync": True,
"fast": True,
"optimize_description": True,
"num_results": 3,
"placement_type": "automatic",
"aspect_ratio": "4:3",
"force_rmbg": True,
"exclude_elements": "people, hands"
}
response = requests.post(
f"{API_URL}/image/editing/generate-product-background-by-text",
headers=headers,
json=data
)
With Manual Placement¶
data = {
"scene_description": "Elegant living room setting",
"image_url": "https://example.com/furniture.png",
"placement_type": "manual_placement",
"manual_placement_selection": "center_horizontal",
"aspect_ratio": "16:9",
"num_results": 2,
"sync": True,
"force_rmbg": True
}
response = requests.post(
f"{API_URL}/image/editing/generate-product-background-by-text",
headers=headers,
json=data
)
With Custom Coordinates¶
data = {
"scene_description": "Modern office workspace",
"image_url": "https://example.com/product.png",
"placement_type": "custom_coordinates",
"foreground_image_size": [400, 300],
"foreground_image_location": [200, 150],
"aspect_ratio": "16:9",
"num_results": 1,
"sync": True,
"fast": False,
"force_rmbg": True
}
response = requests.post(
f"{API_URL}/image/editing/generate-product-background-by-text",
headers=headers,
json=data
)
With Manual Padding¶
data = {
"scene_description": "Minimalist studio setting",
"image_url": "https://example.com/product.png",
"placement_type": "manual_padding",
"padding_values": [50, 50, 100, 30], # [left, right, top, bottom]
"aspect_ratio": "4:3",
"optimize_description": True,
"exclude_elements": "people, text",
"num_results": 1
}
response = requests.post(
f"{API_URL}/image/editing/generate-product-background-by-text",
headers=headers,
json=data
)
5. Generate Product Background by Image¶
Use reference images to create product backgrounds.
data = {
"image_url": "https://example.com/product.png",
"ref_image_urls": ["https://example.com/lifestyle_ref.jpg"],
"sync": True,
"enhance_ref_image": True,
"ref_image_influence": 1.2,
"num_results": 2,
"placement_type": "automatic",
"aspect_ratio": "1:1",
"force_rmbg": True
}
response = requests.post(
f"{API_URL}/image/editing/generate-product-background-by-image",
headers=headers,
json=data
)
Image Enhancement¶
Upscale Image¶
Increase image resolution by 2x or 4x.
data = {
"image_url": "https://example.com/low_res_image.jpg",
"desired_increase": 4,
"preserve_alpha": True,
"content_moderation": False
}
response = requests.post(
f"{API_URL}/image/editing/upscale-image",
headers=headers,
json=data
)
Video Processing¶
Remove Video Background¶
Remove backgrounds from video files.
response = requests.post(
f"{API_URL}/video/editing/video-remove-background",
headers=headers,
data={"video_url": "https://example.com/input_video.mp4"}
)
Tailored Generation¶
Generate images with custom fine-tuned models for specific styles or use cases. Tailored generation enables you to leverage custom-trained models for highly specific outputs, supporting unique branding, product styles, or creative requirements. Bria LoRA API Endpoints
1. Generate Image with Custom Model¶
Use a tailored model for specialized image generation.
data = {
"model_id": "custom-model-123",
"prompt": "A luxury wristwatch on a marble table",
"num_results": 2,
"aspect_ratio": "4:3",
"sync": True,
"steps_num": 30,
"text_guidance_scale": 7.5,
"seed": 2024,
"negative_prompt": "blurry, low quality",
"medium": "product"
}
response = requests.post(
f"{API_URL}/image/generation/generate-image",
headers=headers,
json=data
)
2. Generate Vector Graphics with Custom Model¶
Create vector graphics using a fine-tuned model.
data = {
"model_id": "custom-vector-model-456",
"prompt": "Modern minimalist logo for a tech startup",
"num_results": 1,
"aspect_ratio": "1:1",
"sync": True,
"steps_num": 20,
"seed": 3030
}
response = requests.post(
f"{API_URL}/image/generation/generate-vector-base",
headers=headers,
json=data
)
Advanced Example: Concurrent Requests¶
Here's an example of making multiple concurrent requests using asyncio and aiohttp for the generate-image endpoint:
import asyncio
import aiohttp
import json
async def generate_image_async(session, prompt, seed=None):
"""Generate a single image asynchronously."""
url = f"{API_URL}/image/generation/generate-image"
data = {
"bria_model_version": "3.2",
"prompt": prompt,
"num_results": 1,
"aspect_ratio": "1:1",
"sync": True,
"steps_num": 25,
"text_guidance_scale": 7.0,
"seed": seed
}
headers_async = {
"X-API-Key": API_KEY,
"Content-Type": "application/json"
}
async with session.post(url, headers=headers_async, json=data) as response:
result = await response.json()
return {
"prompt": prompt,
"seed": seed,
"status": response.status,
"result": result
}
async def generate_multiple_images():
"""Generate multiple images concurrently."""
prompts_and_seeds = [
("A serene mountain landscape at dawn", 1001),
("A futuristic cityscape with flying cars", 1002),
("A cozy coffee shop interior with warm lighting", 1003),
("An underwater coral reef with tropical fish", 1004),
("A mystical forest with glowing mushrooms", 1005)
]
async with aiohttp.ClientSession() as session:
# Create tasks for concurrent execution
tasks = [
generate_image_async(session, prompt, seed)
for prompt, seed in prompts_and_seeds
]
# Wait for all tasks to complete
results = await asyncio.gather(*tasks)
# Process results
for result in results:
if result["status"] == 200:
print(f"✅ Generated: {result['prompt'][:50]}...")
if result["result"]["success"]:
urls = result["result"]["data"]["urls"]
print(f" Image URLs: {urls}")
else:
print(f" Error: {result['result']['message']}")
else:
print(f"❌ Failed: {result['prompt'][:50]}... (HTTP {result['status']})")
# Run the concurrent generation
if __name__ == "__main__":
asyncio.run(generate_multiple_images())
This example demonstrates: - Making 5 concurrent image generation requests - Using different prompts and seeds for variety - Proper error handling for HTTP status codes - Processing and displaying results from all concurrent requests
The concurrent approach can significantly reduce total processing time when generating multiple images, especially when using sync=True for immediate results.