પ્રકાશિત

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 કલાક માટે માન્ય છે. આને સંગ્રહિત કરવાનું અથવા તમારા ઉપયોગ કેસના આધારે વપરાશકર્તાને યોગ્ય સમયે સૂચિત કરવાની ખાતરી કરો.

કોડ ઉદાહરણો

ફેચ

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

જાવા

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);
            }
        }
    }
}

પાયથન

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] પર ઈમેલ કરો.

લેખકો