Pixian.AI は、本格的な画像背景除去 API を提供しています。 API は、全自動で、クラス最高の忠実度をもって、画像から背景を除去します。
ビットマップ画像を POST して、背景が削除された結果を受け取ります。
$ curl https://api.pixian.ai/api/v2/remove-background \ -u xyz123:[secret] \ -F image=@example.jpeg \ -o pixian_result.png
// Requires: org.apache.httpcomponents.client5:httpclient5-fluent
Request request = Request.post("https://api.pixian.ai/api/v2/remove-background")
.addHeader("Authorization", "Basic cHh4YmJ6Yjk2bjJ3OGFtOltzZWNyZXRd")
.body(
MultipartEntityBuilder.create()
.addBinaryBody("image", new File("example.jpeg")) // TODO: Replace with your image
// TODO: Add more upload parameters here
.build()
);
ClassicHttpResponse response = (ClassicHttpResponse) request.execute().returnResponse();
if (response.getCode() == 200) {
// Write result to disk, TODO: or wherever you'd like
try (FileOutputStream out = new FileOutputStream("pixian_result.png")) {
response.getEntity().writeTo(out);
}
} else {
System.out.println("Request Failed: Status: " + response.getCode() + ", Reason: " + response.getReasonPhrase());
}
using (var client = new HttpClient())
using (var form = new MultipartFormDataContent())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "INSERT_API_KEY_HERE");
form.Add(new ByteArrayContent(File.ReadAllBytes("example.jpeg")), "image", "example.jpeg"); // TODO: Replace with your image
// TODO: Add more upload parameters here
var response = client.PostAsync("https://api.pixian.ai/api/v2/remove-background", form).Result;
if (response.IsSuccessStatusCode)
{
// Write result to disk, TODO: or wherever you'd like
FileStream outStream = new FileStream("pixian_result.png", FileMode.Create, FileAccess.Write, FileShare.None);
response.Content.CopyToAsync(outStream).ContinueWith((copyTask) => { outStream.Close(); });
}
else
{
Console.WriteLine("Request Failed: Status: " + response.StatusCode + ", Reason: " + response.ReasonPhrase);
}
}
// Requires "request" to be installed (see https://www.npmjs.com/package/request)
var request = require('request');
var fs = require('fs');
request.post({
url: 'https://api.pixian.ai/api/v2/remove-background',
formData: {
image: fs.createReadStream('example.jpeg'), // TODO: Replace with your image
// TODO: Add more upload options here
},
auth: {user: 'xyz123', pass: '[secret]'},
followAllRedirects: true,
encoding: null
}, function(error, response, body) {
if (error) {
console.error('Request failed:', error);
} else if (!response || response.statusCode != 200) {
console.error('Error:', response && response.statusCode, body.toString('utf8'));
} else {
// Save result
fs.writeFileSync("pixian_result.png", body);
}
});
$ch = curl_init('https://api.pixian.ai/api/v2/remove-background');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Authorization: Basic cHh4YmJ6Yjk2bjJ3OGFtOltzZWNyZXRd'));
curl_setopt($ch, CURLOPT_POSTFIELDS,
array(
'image' => curl_file_create('example.jpeg'),
// TODO: Add more upload options here
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200) {
// Save result
file_put_contents("pixian_result.png", $data);
} else {
echo "Error: " . $data;
}
curl_close($ch);
# Requires "requests" to be installed (see https://pypi.org/project/requests/)
import requests
response = requests.post(
'https://api.pixian.ai/api/v2/remove-background',
files={'image': open('example.jpeg', 'rb')},
data={
# TODO: Add more upload options here
},
auth=('xyz123', '[secret]')
)
if response.status_code == requests.codes.ok:
# Save result
with open('pixian_result.png', 'wb') as out:
out.write(response.content)
else:
print("Error:", response.status_code, response.text)
# Requires: gem install httpclient
require 'httpclient'
client = HTTPClient.new default_header: {
"Authorization" => "Basic cHh4YmJ6Yjk2bjJ3OGFtOltzZWNyZXRd"
}
response = client.post("https://api.pixian.ai/api/v2/remove-background", {
"image" => File.open("example.jpeg", "rb"), # TODO: Replace with your image
# TODO: Add more upload parameters here
})
if response.status == 200 then
# Write result to disk, TODO: or wherever you'd like
File.open("pixian_result.png", 'w') { |file| file.write(response.body) }
else
puts "Error: Code: " + response.status.to_s + ", Reason: " + response.reason
end
$ curl https://api.pixian.ai/api/v2/remove-background \ -u xyz123:[secret] \ -F 'image.url=https://example.com/example.jpeg' \ -o pixian_result.png
// Requires: org.apache.httpcomponents.client5:httpclient5-fluent
Request request = Request.post("https://api.pixian.ai/api/v2/remove-background")
.addHeader("Authorization", "Basic cHh4YmJ6Yjk2bjJ3OGFtOltzZWNyZXRd")
.body(
MultipartEntityBuilder.create()
.addTextBody("image.url", "https://example.com/example.jpeg") // TODO: Replace with your image URL
// TODO: Add more upload parameters here
.build()
);
ClassicHttpResponse response = (ClassicHttpResponse) request.execute().returnResponse();
if (response.getCode() == 200) {
// Write result to disk, TODO: or wherever you'd like
try (FileOutputStream out = new FileOutputStream("pixian_result.png")) {
response.getEntity().writeTo(out);
}
} else {
System.out.println("Request Failed: Status: " + response.getCode() + ", Reason: " + response.getReasonPhrase());
}
using (var client = new HttpClient())
using (var form = new MultipartFormDataContent())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "INSERT_API_KEY_HERE");
form.Add(new StringContent("https://example.com/example.jpeg"), "image.url"); // TODO: Replace with your image URL
// TODO: Add more upload parameters here
var response = client.PostAsync("https://api.pixian.ai/api/v2/remove-background", form).Result;
if (response.IsSuccessStatusCode)
{
// Write result to disk, TODO: or wherever you'd like
FileStream outStream = new FileStream("pixian_result.png", FileMode.Create, FileAccess.Write, FileShare.None);
response.Content.CopyToAsync(outStream).ContinueWith((copyTask) => { outStream.Close(); });
}
else
{
Console.WriteLine("Request Failed: Status: " + response.StatusCode + ", Reason: " + response.ReasonPhrase);
}
}
// Requires "request" to be installed (see https://www.npmjs.com/package/request)
var request = require('request');
var fs = require('fs');
request.post({
url: 'https://api.pixian.ai/api/v2/remove-background',
formData: {
'image.url': 'https://example.com/example.jpeg', // TODO: Replace with your image
// TODO: Add more upload options here
},
auth: {user: 'xyz123', pass: '[secret]'},
followAllRedirects: true,
encoding: null
}, function(error, response, body) {
if (error) {
console.error('Request failed:', error);
} else if (!response || response.statusCode != 200) {
console.error('Error:', response && response.statusCode, body.toString('utf8'));
} else {
// Save result
fs.writeFileSync("pixian_result.png", body);
}
});
$ch = curl_init('https://api.pixian.ai/api/v2/remove-background');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Authorization: Basic cHh4YmJ6Yjk2bjJ3OGFtOltzZWNyZXRd'));
curl_setopt($ch, CURLOPT_POSTFIELDS,
array(
'image.url' => 'https://example.com/example.jpeg',
// TODO: Add more upload options here
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200) {
// Save result
file_put_contents("pixian_result.png", $data);
} else {
echo "Error: " . $data;
}
curl_close($ch);
# Requires "requests" to be installed (see https://pypi.org/project/requests/)
import requests
response = requests.post(
'https://api.pixian.ai/api/v2/remove-background',
data={
'image.url': 'https://example.com/example.jpeg',
# TODO: Add more upload options here
},
auth=('xyz123', '[secret]')
)
if response.status_code == requests.codes.ok:
# Save result
with open('pixian_result.png', 'wb') as out:
out.write(response.content)
else:
print("Error:", response.status_code, response.text)
# Requires: gem install httpclient
require 'httpclient'
client = HTTPClient.new default_header: {
"Authorization" => "Basic cHh4YmJ6Yjk2bjJ3OGFtOltzZWNyZXRd"
}
response = client.post("https://api.pixian.ai/api/v2/remove-background", {
"image.url" => "https://example.com/example.jpeg", # TODO: Replace with your image URL
# TODO: Add more upload parameters here
})
if response.status == 200 then
# Write result to disk, TODO: or wherever you'd like
File.open("pixian_result.png", 'w') { |file| file.write(response.body) }
else
puts "Error: Code: " + response.status.to_s + ", Reason: " + response.reason
end
他のプロバイダーからの移行ですか? Check out our migration guide
API の統合をテストするのは無料です。購入する必要はありません。
開発には、test=trueを使ってください。 最初のページのインタラクティブウェブアプリを使って、結果の品質を評価することができます。
運用版の結果には、クレジットパックの購入が必要になります。 価格ページをご覧ください。
API は、標準の HTTP 基本アクセス認証を使用します。 API に対するすべてのリクエストは、HTTPS で行い、API Id をユーザーとして、API シークレットをパスワードとする API 資格情報を含める必要があります。
リクエストを正しく行うには、http クライアントライブラリは、サーバー名表示(SNI) に対応している必要があります。 おかしなハンドシェークエラーが発生する場合、大抵これが原因となっています。
API の利用にはレート制限がありますが、割当量には余裕があり、固定された上限値があるわけではありません。
通常のエンドユーザー操作では使用方法に緩急があるのが常なので、ユーザー側で帯域制限を意識することはなく、サービスは円滑に処理されます。
ただし、バッチジョブでは最大 5 スレッドから始め、お望みの並列処理数に達するまで 5 分ごとに 1 新規スレッドを追加することをお奨めします。 100 同時スレッドを超える処理を必要とする場合は、作業開始前にご連絡ください。
あまりにも多くのリクエストを提出すると、429 Too Many Requestsのレスポンスが返されます。 これが発生したら、リニアバックオフを適用してください。すなわち、最初のレスポンスが返った後、次のリクエストの提出まで 5 秒間待ちます。 引き続き 2 回目の 429 レスポンス発生の場合、次のリクエストの提出まで 2*5=10 秒間待ちます。 3 回目は、 3*5=15 秒待ちます(以下同様)。
バックオフカウンターは、リクエストが正しく完了した後リセットできます。バックオフはスレッドごとに適用してください(すなわち、スレッドは相互に独立に操作する)。
API リクエストは通常数秒以内に完了しますが、一時的に過負荷状況が発生すると、より長い処理時間が必要になる可能性があります。
クライアントライブラリが、API リクエストを早期終了しないよう、これはアイドルタイムアウトを 180 秒以上とするように設定すべきです。
当社は、API リクエストの成功または失敗を示すのに、従来の HTTP ステータスを使用し、返されるエラー JSON オブジェクトに重要なエラー情報を含めています。
当社は、問題のあるリクエストには、必ずエラー JSON オブジェクトを返すように努めています。 しかしながら、理論的には常に、内部サーバーの障害により、JSON 以外のエラーレスポンスが返される可能性があります。
|
属性 |
|
|---|---|
| status | 応答の HTTP ステータスをここに再掲されるのでデバッグに役立ててください。 |
| code | Pixian.AI 内部エラーコード。 |
| message | 人間が読みやすいエラーメッセージ、デバッグに役立ててください。 |
リクエストに対する HTTP ステータスが 200 の場合、JSON オブジェクトが返されず、リクエストは概して言えば正しく処理されたと想定することができます。
HTTP クライアントライブラリによっては、HTTP ステータスの例外を 400~599 の範囲で上げてきます。 それら例外を捕捉して、適切に処理する必要があります。
| HTTP Status | 意味 |
|---|---|
200-299
|
成功 |
400-499
|
リクエストで提供された情報に問題があります(パラメータの欠如など)。 エラーメッセージを確認して、修正方法を考えてください。 |
500-599
|
Pixian.AI 内部エラーが発生しました。 少し待ってやり直してください。問題が続くようでしたら、メールでお問い合わせください。 |
エラー応答の例
{
"error" : {
"status" : 400,
"code" : 1006,
"message" : "Failed to read the supplied image. "
}
}
Pixian.AI は、差分 PNG 出力形式を提供する最初の背景削除サービスであることを嬉しく思っております。 差分 PNG は迅速に符号化でき、通常の PNG よりはるかに小さくすることができます。 したがって、モバイルアプリなどの遅延や帯域に厳しいアプリケーションに最適な形式となります。
POST
https://api.pixian.ai/api/v2/remove-background
画像から背景を削除するには、標準 HTTP POST ファイルのアップロードを行います。 コンテンツタイプ は、multipart/form-data でなければならないことに注意してください。
GET
https://api.pixian.ai/api/v2/account
クレジット残数などのアカウントに関する基本的な情報を取得してください。
|
パラメータ |
|
|---|---|
| なし | |
|
応答属性 |
|||||
|---|---|---|---|---|---|
| creditPack |
最近購入されたクレジットパックまたは「なし」。 |
||||
| state |
|
||||
| useBefore |
クレジットパックが休眠する時期を示します。 API の利用を継続するには、この日以前に別のクレジットパックを購入する必要があります。 ISO 8601 形式。 |
||||
| credits |
アカウントの API クレジット残数。 小数の可能性もあります。倍精度浮動小数点数で取り扱うようにしてください。 |
||||
ユーザー名 = API Id、パスワード = API シークレット
cURL
$ curl "https://api.pixian.ai/api/v2/account" \ -u pxxbbzb96n2w8am:[secret]
応答の例
{
"creditPack" : "none",
"state" : "dormant",
"useBefore" : "1970-01-01T00:00:00Z",
"credits" : 0
}
| 日付 | 変更 |
|---|---|
| 2025/02/12 | アカウントステータスエンドポイントを追加しました。 |
| 2024/03/04 | タイムアウトに関するセクションを追加。 |
| 2024/01/16 | エラー JSON オブジェクトを文書化しました。 |
| 2024/01/11 |
現在実際に返されているのは、X-Credits-Charged ヘッダーですが、テスト版のリクエストのために X-Credits-CalculatedVヘッダーが追加されました。
|
| 2023/06/13 | API をバージョン 2 に更新。また、読みやすさのため、パラメータを camelCase から snake-case に更新。 前バージョンの API は廃止予定ですが、まだ利用可能です。 |
| 2023/05/03 | API パラメータを大幅に拡張。 |
| 2023/04/28 | API エンドポイントを更新。 |
| 2023/03/21 | 初回のリリース。 |