게시일

Removebg API 문서

Cover

시작하기

curl --location 'https://removebg.one/api/v1/predict' \
--header 'Authorization: Bearer $API_KEY' \
--form 'file=@"test.png"'

요청 도메인

https://removebg.one

요청 엔드포인트

/api/v1/predict

API 키 생성

API 키 페이지에서 API 키를 생성하거나 재설정하세요.

요청 매개변수

  1. 현재, 파일 객체만 formData를 통해 전송할 수 있으므로, 항상 Content-Typemultipart/form-data로 설정해 주세요.

  2. API 키 페이지에서 API 키를 생성한 후, Authorization 요청 헤더에 키 값을 설정하세요.

Content-Type: multipart/form-data
Authorization: Bearer $API_KEY

$API_KEY를 실제 API 키로 바꾸는 것을 잊지 마세요.

응답 매개변수

반환 코드 0은 API 호출이 성공했음을 의미합니다. 다른 코드가 반환되면 실패를 의미하며, 실패 사유는 message 필드에 제공됩니다.

  1. 성공적인 응답
{
    "code": 0,
    "data": {
        "cutoutUrl": "https://r.removebg.one/static/8d062cc4-7d1d-4390-b958-a88e3a714e68.png?signature=...",
        "maskUrl": "https://r.removebg.one/static/acd1904f-e7b6-4e20-92cc-29f19659caf8.png?signature=..."
    }
}
  1. 실패한 응답
{
    "code": 400,
    "message": "Invalid request parameters."
}

참고: 성공적으로 반환된 이미지 URL은 1시간 동안만 유효합니다. 사용 사례에 맞게 사용자에게 적시에 알리거나 저장해 두세요.

코드 예시

Fetch

const formData = new FormData()
formData.append('file', File)
fetch('https://removebg.one/api/v1/predict', {
  method: 'POST',
  body: formData,
  headers: {
    Authorization: 'Bearer $API_KEY',
  },
})

Java

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.util.EntityUtils;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.File;
 
public class RemoveBgApiRequest {
    public static void main(String[] args) throws Exception {
        String apiKey = "YOUR_API_KEY"; // Replace with your API key
        String filePath = "test.png";  // Replace with your file path
        String url = "https://removebg.one/api/v1/predict";
        
        File file = new File(filePath);
        
        // Create HTTP client
        try (CloseableHttpClient client = HttpClients.createDefault()) {
            HttpPost post = new HttpPost(url);
            post.setHeader("Authorization", "Bearer " + apiKey);
            
            // Build multipart form data
            FileBody fileBody = new FileBody(file);
            HttpEntity entity = MultipartEntityBuilder.create()
                    .addPart("file", fileBody)
                    .build();
            post.setEntity(entity);
            
            // Execute request
            String response = EntityUtils.toString(client.execute(post).getEntity());
            
            // Parse the JSON response
            JsonObject jsonResponse = JsonParser.parseString(response).getAsJsonObject();
            int code = jsonResponse.get("code").getAsInt();
            
            if (code == 0) {
                // Success
                System.out.println("Success: Response data = " + jsonResponse.getAsJsonObject("data"));
            } else {
                // Failure
                String message = jsonResponse.has("message") ? jsonResponse.get("message").getAsString() : "Unknown error";
                System.out.println("Failure: " + message);
            }
        }
    }
}

Python

import requests
 
# Replace with your actual API key
api_key = 'your_api_key_here'
url = 'https://removebg.one/api/v1/predict'
 
# Path to the image file
file_path = 'test.png'
 
# Set up the headers with Authorization
headers = {
    'Authorization': f'Bearer {api_key}'
}
 
# Open the image file in binary mode
with open(file_path, 'rb') as image_file:
    # Send the POST request with the file
    response = requests.post(url, headers=headers, files={'file': image_file})
 
# Check the response status
if response.code == 0:
    print('Request successful')
    # You can save or process the response content as needed
    with open('output.png', 'wb') as output_file:
        output_file.write(response.content)
else:
    print(f'Error: {response.code}')
 

최종 참고 사항

궁금한 사항이 있으시면 [email protected]으로 이메일을 보내주세요.

작성자