प्रकाशित

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-Type को multipart/form-data पर सेट करें।

  2. API कुंजी पृष्ठ पर API कुंजी उत्पन्न करने के बाद, Authorization अनुरोध हेडर में कुंजी मान सेट करें।

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

याद रखें कि $API_KEY को अपनी वास्तविक API कुंजी से बदलें।

प्रतिक्रिया पैरामीटर

0 का रिटर्न कोड API कॉल के सफल होने का संकेत है। कोई अन्य कोड विफलता का प्रतिनिधित्व करता है, जिसमें विफलता का विशिष्ट कारण संदेश क्षेत्र में प्रदान किया जाता है।

  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] पर ईमेल करें।

लेखक
  • avatar
    नाम
    आधिकारिक
    वेबसाइट
    Removebg