Tailored Generation

Generate Image - Tailored model

Description

This route allows you to generate images using a tailored model. tailored models are trained using your own datasets to create unique illustrative visual styles or single-subject illustrations. You can train a tailored model through the API or using the Bria platform.

Overview of Tailored Model API

The Tailored Model API provides a set of endpoints to manage the entire lifecycle of a Tailored model:

  1. Dataset Management: Create and manage datasets which will be used to train your tailored models. You can:

    • Create and Retrieve Datasets: Use the /datasets endpoint to create a new dataset or retrieve existing datasets that belong to the client organization.
    • Upload and Retrieve Images: Use the /datasets/{dataset_id}/images endpoint to upload a new image to a dataset or retrieve existing images that belong to the dataset.
    • Manage Individual Images: Use the /datasets/{dataset_id}/images/{image_id} endpoint to get or delete a specific image from a dataset.
  2. Model Management: Create and manage models based on your datasets. You can:

    • Create and Retrieve Models: Use the /models endpoint to create a new model or retrieve all models that belong to the client organization.
    • Get and Delete Specific Models: Use the /models/{id} endpoint to retrieve a specific model by its ID or delete a specific model.
  3. Training Management: Start and stop training jobs for your models. You can:

    • Start Training: Use the /models/{id}/start_training endpoint to initiate the training process. Note that the dataset must include the minimum required number of images and have a status of 'completed' before training can start.
    • Stop Training: Use the /models/{id}/stop_training endpoint to stop a training job for a model.
  4. Image Generation: Generate images using a trained model. You can:

    • Generate Images: Use the /text-to-image/tailored/{model_id} endpoint to generate images.
    • Generate Vector Graphics: Use the /text-to-vector/tailored/{model_id} endpoint to generate vector graphics.

Training a Tailored Model

To train a tailored model via the API:

  1. Create a Dataset: Use the /datasets endpoint to create a dataset.
  2. Upload Images: Upload your images to this dataset using the /datasets/{dataset_id}/images endpoint.
  3. Create a Model: Use the /models endpoint to create a model associated with your dataset.
  4. Complete the Dataset: Ensure the dataset meets the minimum image requirements and change its status to 'completed'.
  5. Start Training: Initiate the training process using the /models/{id}/start_training endpoint. Training of a tailored model takes between 1-3 hours.
  6. Monitor Training: Optionally, you can check the training status to monitor progress.
  7. Generate Images: Once the model is trained, use this route to generate images, or use the /text-to-vector/tailored/{model_id} route to generate vector graphics.

Alternatively, you can use the Bria platform to manage and train your tailored models through a user-friendly interface. Access the Bria platform here.

Guidance Methods

This API supports various guidance methods to provide greater control over text-to-image generation. These methods condition the model on additional inputs derived from user-provided images, allowing for more precise and controlled image generation.

Importantly, users can provide any image they want as input. Our pipeline automatically transforms the input image according to the selected guidance method. For example, if you choose the depth guidance method, our pipeline will extract a depth map from your provided image and use it during the generation inference.

Currently, we support the following guidance methods:

  1. controlnet_canny: Extracts edge information from the input image to guide generation based on structural outlines.

  2. controlnet_depth: Derives depth information from the input image to influence spatial arrangement in generated images.

  3. controlnet_recoloring: Uses grayscale version of the input image to guide recoloring while preserving geometry.

  4. controlnet_color_grid: Extracts a 16x16 color grid from the input image to guide the overall color scheme of generated images.

Using Guidance Methods

You can specify up to four guidance methods in a single request. Each method requires an accompanying image and a scale parameter to determine its impact on the generation inference. The table below provides detailed information about each guidance method, with an example os use:

Guidance Method Prompt Scale Input Image Guidance Image Output Image
ControlNet Canny An exotic colorful shell on the beach 1.0 Input Image Guidance Image Output Image
ControlNet Depth A dog, exploring an alien planet 0.8 Input Image Guidance Image Output Image
ControlNet Recoloring A vibrant photo of a woman 1.00 Input Image Guidance Image Output Image
ControlNet Color Grid A dynamic fantasy illustration of an erupting volcano 0.7 Input Image Guidance Image Output Image

Note: When using multiple guidance methods, all input images must have the same aspect ratio, which will determine the aspect ratio of the generated results.

To use a guidance method, include the following parameters in your request:

  • guidance_method_X: Specify the guidance method (where X is 1, 2). If the paramter guidance_method_2 is used, so does guidance_method_1 has to be used, and so on. If you would like to use only one method, use the paratmer guidance_method_1

  • guidance_method_X_scale: Set the impact of the guidance (0.0 to 1.0)

  • guidance_method_X_image_file: Provide the base64-encoded input image

By leveraging these guidance methods, you can achieve more precise control over the generated images, tailoring them to your specific needs and creative vision.

Request
path Parameters
model_id
required
string

The model id of the tailored model you would like to use in the request. Both legacy (long, provided in the Bria console) and new (short, available via the 'Get Models' API) model ID formats are supported.

header Parameters
api_token
required
string
Request Body schema: application/json
required
prompt
string

The prompt you would like to use to generate images. Bria currently supports prompts in English only, excluding special characters.

num_results
integer [ 1 .. 4 ]
Default: 4

How many images you would like to generate. This parameter is optional. When fast=false, only num_results 1, 2 are supported.

aspect_ratio
string
Default: "1:1"

The aspect ratio of the image.

Enum: "1:1" "2:3" "3:2" "3:4" "4:3" "4:5" "5:4" "9:16" "16:9"
sync
boolean
Default: false

Determines the response mode. When true, responses are synchronous. With false, responses are asynchronous, immediately providing URLs for images that are generated in the background. Use polling for the URLs to retrieve images once ready.

fast
boolean
Default: true

Determines the generation mode. When true, the generation will utilize the fast mode which provides the best balance between speed and quality. When false, the regular mode will be utilized.

seed
integer

You can choose whether you want your generated result to be random or predictable. You can recreate the same result in the future by using the seed value of a result from the response with the prompt, model type and model version. You can exclude this parameter if you are not interested in recreating your results. This parameter is optional.

steps_num
integer [ 4 .. 20 ]
Default: 8

The number of iterations the model goes through to refine the generated image. This parameter is optional. When fast=false, the default value is 30, the minimum is 20 and the maximum is 50.

model_influence
number <float> [ 0 .. 1 ]
Default: 1

The influence of the structure reference on the generated image. This parameter is optional. Higher value means more adherence to the reference structure.

guidance_method_1
string

Which guidance type you would like to include in the generation. Up to 4 guidance methods can be combined during a single inference. This parameter is optional.

Enum: "controlnet_canny" "controlnet_depth" "controlnet_recoloring" "controlnet_color_grid"
guidance_method_1_scale
number <float> [ 0 .. 1 ]
Default: 1

The impact of the guidance.

guidance_method_1_image_file
string

The image that should be used as guidance, in base64 format, with the method defined in guidance_method_1. Accepted formats are jpeg, jpg, png, webp. Maximum file size 12MB. If more then one guidance method is used, all guidance images must be of the same aspect ratio, and this will be the aspect ratio of the generated results. If guidance_method_1 is selected, an image must be provided.

guidance_method_2
string

Which guidance type you would like to include in the generation. Up to 4 guidance methods can be combined during a single inference. This parameter is optional.

Enum: "controlnet_canny" "controlnet_depth" "controlnet_recoloring" "controlnet_color_grid"
guidance_method_2_scale
number <float> [ 0 .. 1 ]
Default: 1

The impact of the guidance.

guidance_method_2_image_file
string

The image that should be used as guidance, in base64 format, with the method defined in guidance_method_2. Accepted formats are jpeg, jpg, png, webp. Maximum file size 12MB. If more then one guidance method is used, all guidance images must be of the same aspect ratio, and this will be the aspect ratio of the generated results. If guidance_method_1 is selected, an image must be provided.

Responses
200

Successful operation.

400

Bad request.

405

Method not allowed.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

post/text-to-image/tailored/{model_id}
Request samples

Generate Vector Graphics - Tailored (Beta)

Description

This route allows you to generate vector graphics using a tailored model. Tailored models are trained using your own datasets to create unique illustrative visual styles or single-subject illustrations. To see a detailed description of the tailored models' functionalities, please refer to the /text-to-image/tailored/{model_id} route documentation. *Text-to-vector is compatible with tailored models in the illustrative domain.

Guidance Methods

This API supports various guidance methods to provide greater control over text-to-image generation. These methods condition the model on additional inputs derived from user-provided images, allowing for more precise and controlled image generation.

Importantly, users can provide any image they want as input. Our pipeline automatically transforms the input image according to the selected guidance method. For example, if you choose the depth guidance method, our pipeline will extract a depth map from your provided image and use it during the generation inference.

Currently, we support the following guidance methods:

  1. controlnet_canny: Extracts edge information from the input image to guide generation based on structural outlines.
  2. controlnet_depth: Derives depth information from the input image to influence spatial arrangement in generated images.
  3. controlnet_recoloring: Uses grayscale version of the input image to guide recoloring while preserving geometry.
  4. controlnet_color_grid: Extracts a 16x16 color grid from the input image to guide the overall color scheme of generated images.

Using Guidance Methods You can specify up to four guidance methods in a single request. Each method requires an accompanying image and a scale parameter to determine its impact on the generation inference. Note: When using multiple guidance methods, all input images must have the same aspect ratio, which will determine the aspect ratio of the generated results. To use a guidance method, include the following parameters in your request:

  • guidance_method_X: Specify the guidance method (where X is 1, 2). If the paramter guidance_method_2 is used, so does guidance_method_1 has to be used, and so on. If you would like to use only one method, use the paratmer guidance_method_1
  • guidance_method_X_scale: Set the impact of the guidance (0.0 to 1.0)
  • guidance_method_X_image_file: Provide the base64-encoded input image

By leveraging these guidance methods, you can achieve more precise control over the generated images, tailoring them to your specific needs and creative vision.

Request
path Parameters
model_id
required
string

The model id of the tailored model you would like to use in the request. Both legacy (long, provided in the Bria console) and new (short, available via the 'Get Models' API) model ID formats are supported.

header Parameters
api_token
required
string
Request Body schema: application/json
required
prompt
string

The prompt you would like to use to generate images. Bria currently supports prompts in English only, excluding special characters.

num_results
integer [ 1 .. 4 ]
Default: 4

How many images you would like to generate. This parameter is optional. When fast=false, only num_results 1, 2 are supported.

aspect_ratio
string
Default: "1:1"

The aspect ratio of the image.

Enum: "1:1" "2:3" "3:2" "3:4" "4:3" "4:5" "5:4" "9:16" "16:9"
sync
boolean
Default: true

Determines the response mode. When true, responses are synchronous. With false, responses are asynchronous, immediately providing URLs for images that are generated in the background. Use polling for the URLs to retrieve images once ready. This parameter is optional. When fast=false, it is reomcmned to use sync=false.

fast
boolean
Default: true

Determines the generation mode. When true, the generation will utilize the fast mode which provides the best balance between speed and quality. When false, the regular mode will be utilized.

seed
integer

You can choose whether you want your generated result to be random or predictable. You can recreate the same result in the future by using the seed value of a result from the response with the prompt, model type and model version. You can exclude this parameter if you are not interested in recreating your results. This parameter is optional.

steps_num
integer [ 4 .. 20 ]
Default: 8

The number of iterations the model goes through to refine the generated image. This parameter is optional. When fast=false, the default value is 30, the minimum is 20 and the maximum is 50.

model_influence
number <float> [ 0 .. 1 ]
Default: 1

The influence of the tailored model on the generation. Only relevant if tailored_model_id is provided. This parameter is optional. Higher value gives more weight to the tailored model.

guidance_method_1
string

Which guidance type you would like to include in the generation. Up to 4 guidance methods can be combined during a single inference. This parameter is optional.

Enum: "controlnet_canny" "controlnet_depth" "controlnet_recoloring" "controlnet_color_grid"
guidance_method_1_scale
number <float> [ 0 .. 1 ]
Default: 1

The impact of the guidance.

guidance_method_1_image_file
string

The image that should be used as guidance, in base64 format, with the method defined in guidance_method_1. Accepted formats are jpeg, jpg, png, webp. Maximum file size 12MB. If more then one guidance method is used, all guidance images must be of the same aspect ratio, and this will be the aspect ratio of the generated results. If guidance_method_1 is selected, an image must be provided.

guidance_method_2
string

Which guidance type you would like to include in the generation. Up to 4 guidance methods can be combined during a single inference. This parameter is optional.

Enum: "controlnet_canny" "controlnet_depth" "controlnet_recoloring" "controlnet_color_grid"
guidance_method_2_scale
number <float> [ 0 .. 1 ]
Default: 1

The impact of the guidance.

guidance_method_2_image_file
string

The image that should be used as guidance, in base64 format, with the method defined in guidance_method_2. Accepted formats are jpeg, jpg, png, webp. Maximum file size 12MB. If more then one guidance method is used, all guidance images must be of the same aspect ratio, and this will be the aspect ratio of the generated results. If guidance_method_1 is selected, an image must be provided.

Responses
200

Successful operation.

400

Bad request.

403

Forbidden. Insufficient permissions to access the image URL..

405

Method not allowed.

415

Unsupported Media Type. Invalid file type. Supported file types are jpeg, jpg, png, webp.

422

Unprocessable Entity. The URL does not point to a valid image or is inaccessible.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

post/text-to-vector/tailored/{model_id}
Request samples

Create Dataset

Description This endpoint allows the creation of a new dataset that will belong to the organization associated with the used API token. The dataset will be created with a default status of "draft".

Request
header Parameters
api_token
required
string

API token associated with the organization.

Request Body schema: application/json
use_case
string

Specifies the use case of the dataset.

Enum: "illustrative_style" "illustrative_single_object"
style_description
string

Description of the visual style. This is currently required but might change in the future.

name
string

Name of the dataset.

Responses
201

Dataset successfully created.

400

Bad request.

401

Unauthorized.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

post/tailored-gen/datasets
Request samples
Response samples
application/json
{
  • "id": 123,
  • "use_case": "illustrative_style",
  • "style_description": "A 2d vibrant and colorful flat illustration.",
  • "name": "My Illustrations",
  • "status": "draft",
  • "images_count": 0,
  • "images": [ ],
  • "created_at": "2024-05-26T12:00:00Z",
  • "updated_at": null
}

Get Datasets

Description Retrieve a list of datasets that belong to the organization associated with the used API token. If no datasets are found, an empty array is returned.

Request
header Parameters
api_token
required
string

API token associated with the organization.

Responses
200

Successful operation.

401

Unauthorized.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

get/tailored-gen/datasets
Request samples
Response samples
application/json
[
  • {
    },
  • {
    }
]

Get Dataset by ID

Description Retrieve a specific dataset by its ID. The response includes all the details of the dataset and an array of associated images.

Request
path Parameters
id
required
integer

The ID of the dataset to retrieve.

header Parameters
api_token
required
string

API token associated with the organization.

Responses
200

Successful operation.

401

Unauthorized.

404

Dataset with the specified ID does not exist.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

get/tailored-gen/datasets/{id}
Request samples
Response samples
application/json
{
  • "id": 123,
  • "use_case": "illustrative_style",
  • "style_description": "A 2d vibrant and colorful flat illustration.",
  • "name": "My Illustrations",
  • "status": "draft",
  • "images": [
    ],
  • "created_at": "2024-05-26T12:00:00Z",
  • "updated_at": null
}

Update Dataset

Description Update the details of a specific dataset by its ID. If the status of the dataset is completed, the style_description and use_case cannot be updated. Additionally, if the status is completed, it cannot be returned to draft if a model has already been trained based on it.

Request
path Parameters
id
required
integer

The ID of the dataset to update.

header Parameters
api_token
required
string

API token associated with the organization.

Request Body schema: application/json
use_case
string

Specifies the use case of the dataset. Accepted values are "illustrative_style" and "illustrative_single_object".

style_description
string

Description of the visual style.

name
string

Name of the dataset.

status
string

Status of the dataset.

Value: "COMPLETED"
Responses
200

Successful operation.

400

Bad request.

401

Unauthorized.

404

Dataset with the specified ID does not exist.

409

Conflict.

500

Internal server error.

put/tailored-gen/datasets/{id}
Request samples
Response samples
application/json
{
  • "id": 123,
  • "use_case": "illustrative_style",
  • "style_description": "A 2d vibrant and colorful flat illustration.",
  • "name": "My Illustrations",
  • "status": "draft",
  • "images": [],
  • "created_at": "2024-05-26T12:00:00Z",
  • "updated_at": "2024-05-26T12:00:00Z"
}

Delete Dataset

Description Delete a specific dataset. Changes status to deleted.

Request
path Parameters
id
required
integer

The ID of the dataset to delete.

header Parameters
api_token
required
string

API token associated with the organization.

Responses
204

Dataset successfully deleted.

404

Dataset with the specified ID does not exist.

409

Conflict.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

delete/tailored-gen/datasets/{id}
Request samples
Response samples
application/json
{
  • "error": "Cannot delete a dataset that is used by a model that is in training or has the status 'ready'."
}

Upload Image to Dataset

Description Upload a new image to a specific dataset. One of the following parameters, file or image_url, must be provided.

Upload a new image using the image file

In our documentation request example, we demonstrate how to upload a new image using the image URL.

If you want to use an image from a file, follow the example below:

  import requests

  url = "/tailored-gen/datasets/{dataset_id}/images"

  payload = {}
  files=[
    ('file',('image_name.jpeg',open('/path_to_local_file/image_name.jpeg','rb'),'image/jpeg'))
  ]
  headers = {
    'api_token': 'xxxx'
  }

  response = requests.request("POST", url, headers=headers, data=payload, files=files)

  print(response.text)
Request
path Parameters
dataset_id
required
integer

The ID of the dataset to which the image will be uploaded.

header Parameters
api_token
required
string

API token associated with the organization.

Request Body schema: multipart/form-data
file
string <binary>

Image file to upload. Either file or image_url must be provided.

image_url
string

URL of the image to upload. Either file or image_url must be provided.

image_name
string

Name of the image. If not provided, the file name will be used. If neither is available, a default name will be set. This field is only relevant when an image_url is provided.

Responses
201

Image successfully uploaded.

400

Bad request.

404

Dataset with the specified ID does not exist.

409

Conflict.

412

Precondition Failed.

415

Unsupported Media Type.

422

Unprocessable Entity.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

post/tailored-gen/datasets/{dataset_id}/images
Request samples
Response samples
application/x-www-form-urlencoded
id=123&dataset_id=123&caption=A%20vibrant%202D%20illustration%20of%20a%20sunny%20day%20with%20children%20playing%20in%20a%20park.&file_name=Illustration1.png&image_url=https%3A%2F%2Fexample.com%2Fimage1.png&thumbnail_url=https%3A%2F%2Fexample.com%2Fimage1_thumbnail.png&created_at=2024-05-26T12%3A00%3A00Z

Get Images

Description Retrieve a list of images in a specific dataset.

Request
path Parameters
dataset_id
required
integer

The ID of the dataset for which to retrieve images.

header Parameters
api_token
required
string

API token associated with the organization.

Responses
200

Successful operation.

404

Dataset with the specified ID does not exist.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

get/tailored-gen/datasets/{dataset_id}/images
Request samples
Response samples
application/json
[]

Get Image by ID

Description Retrieve a specific image by its ID.

Request
path Parameters
dataset_id
required
integer

The ID of the dataset to which the image belongs.

image_id
required
integer

The ID of the image to retrieve.

header Parameters
api_token
required
string

API token associated with the organization.

Responses
200

Successful operation.

404

Not Found.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

get/tailored-gen/datasets/{dataset_id}/images/{image_id}
Request samples
Response samples
application/json
{}

Delete Image

Description Delete a specific image.

Request
path Parameters
dataset_id
required
integer

The ID of the dataset to which the image belongs.

image_id
required
integer

The ID of the image to delete.

header Parameters
api_token
required
string

API token associated with the organization.

Responses
204

Image successfully deleted.

404

Not Found.

409

Conflict.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

delete/tailored-gen/datasets/{dataset_id}/images/{image_id}
Request samples
Response samples
application/json
{
  • "error": "Image with the specified ID does not exist."
}

Create Model

Description Create a new model.

Request
header Parameters
api_token
required
string

API token associated with the organization.

Request Body schema: application/json
name
string

Name of the model.

description
string

Description of the model.

dataset_id
integer

ID of the dataset to be used for training the model.

Responses
201

Model successfully created.

404

Dataset with the specified ID does not exist.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

post/tailored-gen/models
Request samples
Response samples
application/json
{
  • "id": 123,
  • "name": "My Model",
  • "description": "This model is designed for generating illustrative style images.",
  • "status": "Created",
  • "dataset_id": 123,
  • "created_at": "2024-05-26T12:00:00Z"
}

Get Models

Description Retrieve a list of models. If there are no models, an empty array is being returned.

Request
header Parameters
api_token
required
string

API token associated with the organization.

Responses
200

Successful operation.

401

Unauthorized.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

get/tailored-gen/models
Request samples
Response samples
application/json
[
  • {
    },
  • {
    }
]

Get model by ID

Description Retrieve a specific model by its ID.

Request
path Parameters
id
required
integer

The ID of the model to retrieve.

header Parameters
api_token
required
string

API token associated with the organization.

Responses
200

Successful operation.

404

Model with the specified ID does not exist.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

get/tailored-gen/models/{id}
Request samples
Response samples
application/json
{
  • "id": 123,
  • "name": "My Model",
  • "description": "This model is designed for generating illustrative style images.",
  • "status": "Created",
  • "dataset_id": 123,
  • "created_at": "2024-05-26T12:00:00Z"
}

Delete model

Description Delete a specific model.

Request
path Parameters
id
required
integer

The ID of the model to delete.

header Parameters
api_token
required
string

API token associated with the organization.

Responses
204

Model successfully deleted.

404

Model with the specified ID does not exist.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

delete/tailored-gen/models/{id}
Request samples
Response samples
application/json
{
  • "status": "Deleted"
}

Start Training

Description Start a new training job for a specific model. Training of a tailored model takes between 1-3 hours.

Request
path Parameters
id
required
integer

The ID of the model for which to start the training job.

header Parameters
api_token
required
string

API token associated with the organization.

Responses
200

Training job successfully started.

404

Model with the specified ID does not exist.

409

Conflict.

412

Precondition Failed.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

post/tailored-gen/models/{id}/start_training
Request samples
Response samples
application/json
{
  • "id": 123,
  • "status": "Training In Progress"
}

Stop Training

Description Stop a specific training job for a model.

Request
path Parameters
id
required
integer

The ID of the model for which to stop the training job.

header Parameters
api_token
required
string

API token associated with the organization.

Responses
200

Training job successfully stopped.

404

Model with the specified ID does not exist.

409

Conflict.

429

Request limit exceeded. Your account has reached its maximum allowed requests. Please upgrade your plan or try again later.

500

Internal server error.

post/tailored-gen/models/{id}/stop_training
Request samples
Response samples
application/json
{
  • "error": "Model with the specified ID does not exist."
}