Bria で画像を編集する
CometAPI 経由で Bria Image Editing API を使用し、POST /bria/image/edit/ で erase、gen_fill、expand、enhance、upscale、または背景置換を実行します。
curl https://api.cometapi.com/bria/image/edit/replace_background \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"image": "https://your-image-host/source.jpg",
"prompt": "in a cozy living room"
}'import os
import requests
# Replace replace_background with the action you need: erase, gen_fill,
# increase_resolution, remove_background, ...
response = requests.post(
"https://api.cometapi.com/bria/image/edit/replace_background",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"image": "https://your-image-host/source.jpg",
"prompt": "in a cozy living room",
},
)
task = response.json()
print(task["request_id"]) # poll GET /bria/{request_id} until status COMPLETED
// Replace replace_background with the action you need: erase, gen_fill,
// increase_resolution, remove_background, ...
const response = await fetch("https://api.cometapi.com/bria/image/edit/replace_background", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
image: "https://your-image-host/source.jpg",
prompt: "in a cozy living room",
}),
});
const task = await response.json();
console.log(task.request_id); // poll GET /bria/{request_id} until status COMPLETED
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/bria/image/edit/{action}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'image' => 'https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/original_image.png',
'mask' => 'https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/mask_image.png'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/bria/image/edit/{action}"
payload := strings.NewReader("{\n \"image\": \"https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/original_image.png\",\n \"mask\": \"https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/mask_image.png\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.cometapi.com/bria/image/edit/{action}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"image\": \"https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/original_image.png\",\n \"mask\": \"https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/mask_image.png\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/bria/image/edit/{action}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"image\": \"https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/original_image.png\",\n \"mask\": \"https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/mask_image.png\"\n}"
response = http.request(request)
puts response.read_body{
"request_id": "<request_id>"
}概要
Bria の Image Editing API は、画像を加工・強化するための包括的なツール群を提供します。request_id を使用して Query Status エンドポイント経由で結果を照会してください。このインターフェースでは sync パラメータは固定されているため、指定する必要はありません。サポートされている操作
| Operation | Description | Documentation |
|---|---|---|
erase | 画像からオブジェクトを削除 | Bria Erase Docs |
gen_fill | マスク領域に対する生成塗りつぶし | Bria Gen Fill Docs |
expand | 画像キャンバスを拡張 | Bria Expand Docs |
enhance | 画像品質を向上 | Bria Enhance Docs |
increase_resolution | 画像解像度をアップスケール | Bria Upscale Docs |
replace_background | 画像の背景を置換 | Bria Background Docs |
承認
Bearer token authentication. Use your CometAPI key.
ヘッダー
Must be application/json.
パスパラメータ
Editing action to perform. Supported values: erase, gen_fill, expand, enhance, increase_resolution, replace_background.
ボディ
Source image as a public URL or base64-encoded data URI. Accepted formats: JPEG, PNG, WebP. Maximum 12 MB.
Mask image as a public URL or base64. White areas mark the region to edit; black areas are preserved. Required for erase, gen_fill, and expand actions.
Text description of the desired edit. Required for gen_fill and replace_background actions.
Number of result variants to generate. Default: 1.
When true, the response blocks until results are ready. When false (default), returns immediately with placeholder URLs that can be polled.
レスポンス
Success
The response is of type object.
curl https://api.cometapi.com/bria/image/edit/replace_background \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"image": "https://your-image-host/source.jpg",
"prompt": "in a cozy living room"
}'import os
import requests
# Replace replace_background with the action you need: erase, gen_fill,
# increase_resolution, remove_background, ...
response = requests.post(
"https://api.cometapi.com/bria/image/edit/replace_background",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"image": "https://your-image-host/source.jpg",
"prompt": "in a cozy living room",
},
)
task = response.json()
print(task["request_id"]) # poll GET /bria/{request_id} until status COMPLETED
// Replace replace_background with the action you need: erase, gen_fill,
// increase_resolution, remove_background, ...
const response = await fetch("https://api.cometapi.com/bria/image/edit/replace_background", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
image: "https://your-image-host/source.jpg",
prompt: "in a cozy living room",
}),
});
const task = await response.json();
console.log(task.request_id); // poll GET /bria/{request_id} until status COMPLETED
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/bria/image/edit/{action}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'image' => 'https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/original_image.png',
'mask' => 'https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/mask_image.png'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/bria/image/edit/{action}"
payload := strings.NewReader("{\n \"image\": \"https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/original_image.png\",\n \"mask\": \"https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/mask_image.png\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.cometapi.com/bria/image/edit/{action}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"image\": \"https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/original_image.png\",\n \"mask\": \"https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/mask_image.png\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/bria/image/edit/{action}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"image\": \"https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/original_image.png\",\n \"mask\": \"https://raw.githubusercontent.com/cometapi-dev/.github/refs/heads/main/assets/img/mask_image.png\"\n}"
response = http.request(request)
puts response.read_body{
"request_id": "<request_id>"
}