Generate a Portrait Photo
Bake API allows you to generate high-quality portrait photos from single face images or two face images. In this tutorial, we'll demonstrate how to create a portrait photo from two face images. The process for generating a photo from a single face image is similar.
Step 1: Sign up and Get Your API Key
To get started, sign up for a Bake API account and obtain your API key.
Step 2: Download the Task Input File
Download the task-input.json file from the Bake API website.
Step 3: Run the Command
Run the following command to create a task, replacing YOUR_API_KEY
with your actual API key:
1curl --request POST \
2 --url https://api.getbake.ai/v1/tasks \
3 --header 'Accept: application/json, text/plain' \
4 --header 'Authorization: Bearer YOUR_API_KEY' \
5 --header 'Content-Type: application/json' \
6 --data '@task-input.json'
Step 4: Check the Task Status
To check the status of your task, use the following command:
1curl --request GET \
2 --url https://api.getbake.ai/v1/tasks/YOUR_TASK_ID \
3 --header 'Accept: application/json, text/plain' | jq .
Once the task has been processed, you'll receive a response including the generated image URL as follows:
1{
2 "created": "2024-04-23T06:41:47.399211Z",
3 "customerId": "cus_PyZljdS4lwu9nV",
4 "error": "",
5 "generatedImageUrl": "https://storage.googleapis.com/bake-api-public-prod/9f77743d-b16c-4b0f-8058-3902d9574bc3/jpeg",
6 "id": "9f77743d-b16c-4b0f-8058-3902d9574bc3",
7 "prompt": "a highly detailed, portrait photo of a beautiful woman, wearing black shirt, serious face, detailed face, skin pores shot, dramatic lighting",
8 "status": {
9 "isEnqueued": true,
10 "isFailed": false,
11 "isGenerated": true,
12 "isPaid": true
13 },
14 "webhookUrl": "https://enw6hliv6ugu.x.pipedream.net"
15}
Step 5: View the Generated Image
The generated image will be available at the specified URL. Please note that since the image is generated using a random seed, it's possible to obtain different images by creating the same task multiple times. We recommend trying multiple times to get a good image.
Task Input File
In the task-input.json
file, you'll find the following parameters:
faceImage
: The base64-encoded string of the JPEG image.prompt
: The prompt for the generated image. See the Prompt Guide for more info.webhookUrl
: An optional webhook URL for notifications.secondaryImage
: The base64-encoded string of the secondary face image.secondaryImageWeight
: A number between 0.0 and 1.0 that determines how much of each face is mixed.
Here's an example of what the task-input.json
file might look like:
1{
2 "faceImage": "/9j/4AAQSkZJRgABAQEBLA...",
3 "prompt": "a highly detailed, portrait photo of a beautiful woman, wearing black shirt, serious face, detailed face, skin pores shot, dramatic lighting",
4 "webhookUrl": "https://enw6hliv6ugu.x.pipedream.net",
5 "secondaryImage": "/9j/4AAQSkZJRgABAQEAyA...",
6 "secondaryImageWeight": 0.5
7}
Note
You can obtain a base64-encoded string from an image file using the command base64 -i karina.jpg
.
API Documentation
For more information about the Bake API, please refer to our API documentation.