Pixian.AI ขอเสนอ API สติกเกอร์รูปหน้าสุดพิเศษ API สร้างคัตเอาต์รูปหน้าที่ดูน่ารักน่าโหลด จึงเหมาะอย่างยิ่งทั้งกับสัตว์เลี้ยงและคนทั่วไป
โพสต์ภาพบิตแมปและรอรับผลลัพธ์ที่เป็นสติกเกอร์รูปหน้ากลับมา:
$ curl https://api.pixian.ai/api/v2/face-sticker \ -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/face-sticker") .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/face-sticker", 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/face-sticker', 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/face-sticker'); 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/face-sticker', 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/face-sticker", { "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/face-sticker \ -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/face-sticker") .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/face-sticker", 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/face-sticker', 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/face-sticker'); 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/face-sticker', 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/face-sticker", { "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
ทั้งนี้สามารถผสานรวมกับ API และทดสอบได้ฟรี โดยไม่จำเป็นต้องซื้อสินค้าใด ๆ
เพียงแค่ใช้ test=true
เพื่อการพัฒนา คุณสามารถประเมินคุณภาพผลลัพธ์ได้โดยใช้เว็บแอปแบบโต้ตอบที่หน้าหลัก
ผลลัพธ์ที่พร้อมออกสื่อต้องอาศัยการซื้อชุดเครดิต โปรดดูที่หน้าการกำหนดราคา
API ใช้ การรับรองความถูกต้องเบื้องต้นของการเข้าถึง HTTP แบบมาตรฐาน คำร้องขอทั้งหมดถึง API ต้องดำเนินการผ่าน HTTPS และมีข้อมูลประจำตัว API ของคุณ โดยมี API Id เป็นผู้ใช้ และรหัสลับ API เป็นรหัสผ่าน
ไลบรารีไคลเอ็นต์ http ของคุณต้องรองรับ การบ่งชี้ชื่อเซิร์ฟเวอร์ (SNI) จึงจะส่งคำขอได้สำเร็จ หากคุณได้รับข้อผิดพลาดการสื่อสารที่ผิดปกติ ก็น่าจะเป็นเพราะเหตุนี้มากที่สุด
การใช้งาน API มีอัตราที่จำกัด โดยเผื่อค่าไว้กว้างและไม่มีขอบเขตบนที่เคร่งครัด
ในระหว่างการดำเนินการที่ผู้ใช้ปลายทางกระทำตามปกตินั้น มีโอกาสน้อยที่คุณจะประสบกับอัตราที่จำกัด เพราะการใช้งานมีแนวโน้มที่จะขึ้น ๆ ลง ๆ ในลักษณะที่บริการจัดการได้อย่างเรียบร้อย
อย่างไรก็ตาม ในกรณีของชุดงาน เราขอแนะนำให้เริ่มต้นด้วยชุดกิจกรรมสูงสุด 5 ชุด โดยเพิ่มใหม่ 1 ชุดทุก ๆ 5 นาที จนกว่าคุณจะไปถึงระดับการทำงานแบบขนานตามที่ต้องการ กรุณาแจ้งให้เราทราบก่อนที่คุณจะเริ่มงาน หากต้องการชุดกิจกรรมมากกว่า 100 ชุดพร้อมกัน
หากคุณส่งคำขอมากเกินไป คุณจะเริ่มได้รับผลตอบกลับ 429 Too Many Requests
เมื่อเกิดกรณีเช่นนี้ขึ้น คุณควรปรับใช้กลยุทธ์สุ่มรอเวลาแบบเส้นตรง : ในผลตอบกลับดังกล่าวครั้งแรก รอ 5 วินาที ก่อนส่งคำขอถัดไป ในผลตอบกลับ 429 ที่ต่อเนื่องกันครั้งที่สอง รอ 2*5=10 วินาที ก่อนส่งคำขอถัดไป ส่วนครั้งที่สาม จะรอ 3*5=15 วินาที ฯลฯ
คุณสามารถรีเซ็ตตัวนับการสุ่มรอเวลาหลังจากคำขอประสบผลสำเร็จ และคุณควรนำการสุ่มรอเวลาไปใช้กับแต่ละชุดกิจกรรม (กล่าวคือ ชุดกิจกรรมควรทำหน้าที่โดยอิสระไม่ขึ้นต่อกันและกัน)
แม้ว่าโดยปกติแล้วคำขอ API จะเสร็จสมบูรณ์ภายในเวลาไม่กี่วินาที แต่ก็เป็นไปได้ที่อาจต้องประสบกับเวลาดำเนินการที่นานขึ้นในช่วงที่มีการโหลดข้อมูลเพิ่มขึ้นอย่างรวดเร็วชั่วครู่
เพื่อให้แน่ใจว่าไลบรารีไคลเอนต์ของคุณจะไม่ยุติคำขอ API ก่อนกำหนด ควรกำหนดค่าให้มีการหมดเวลาขณะไม่ได้ใช้งานไว้อย่างน้อย 180 วินาที
เราใช้สถานะ HTTP แบบปกติ เพื่อบ่งชี้ความสำเร็จหรือความล้มเหลวของคำขอ API และรวมถึงรายละเอียดข้อผิดพลาดที่สำคัญในออบเจ็กต์ 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. " } }
POST
https://api.pixian.ai/api/v2/face-sticker
หากต้องการรับสติกเกอร์รูปหน้าจากภาพ คุณต้องอัปโหลดไฟล์ 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 }
วันที่ | เปลี่ยน |
---|---|
12 ก.พ. 2025 | เพิ่มจุดหมาย API ของสถานะบัญชี |
11 เม.ย. 2024 | ออกเผยแพร่ครั้งแรก |