POST/v1/sd1.5-inpainting
1const axios = require('axios');
2
3const fs = require('fs');
4const path = require('path');
5
6async function toB64(imgPath) {
7    const data = fs.readFileSync(path.resolve(imgPath));
8    return Buffer.from(data).toString('base64');
9}
10
11const api_key = "YOUR API-KEY";
12const url = "https://api.segmind.com/v1/sd1.5-inpainting";
13
14const data = {
15  "prompt": "mecha robot sitting on a bench",
16  "negative_prompt": "Disfigured, cartoon, blurry, nude",
17  "samples": 1,
18  "image": "toB64('https://segmind.com/inpainting-input-image.jpeg')",
19  "mask": "toB64('https://segmind.com/inpainting-input-mask.jpeg')",
20  "scheduler": "DDIM",
21  "num_inference_steps": 25,
22  "guidance_scale": 7.5,
23  "strength": 1,
24  "seed": 17123564234,
25  "img_width": 512,
26  "img_height": 512
27};
28
29(async function() {
30    try {
31        const response = await axios.post(url, data, { headers: { 'x-api-key': api_key } });
32        console.log(response.data);
33    } catch (error) {
34        console.error('Error:', error.response.data);
35    }
36})();
RESPONSE
image/jpeg
HTTP Response Codes
200 - OKImage Generated
401 - UnauthorizedUser authentication failed
404 - Not FoundThe requested URL does not exist
405 - Method Not AllowedThe requested HTTP method is not allowed
406 - Not AcceptableNot enough credits
500 - Server ErrorServer had some issue with processing
Expand

Attributes


promptstr *

Prompt to render


negative_promptstr ( default: None )

Prompts to exclude, eg. 'bad anatomy, bad hands, missing fingers'


samplesint ( default: 1 ) Affects Pricing

Number of samples to generate.

min : 1,

min : 4


imageimage *

Input Image.


maskimage *

Mask Image


schedulerenum:str ( default: DDIM )

Type of scheduler.

Allowed values:


num_inference_stepsint ( default: 20 ) Affects Pricing

Number of denoising steps.

min : 20,

min : 100


guidance_scalefloat ( default: 7.5 )

Scale for classifier-free guidance

min : 0.1,

min : 25


strengthfloat ( default: 1 )

How much to transform the reference image

min : 0.1,

min : 1


seedint ( default: -1 )

Seed for image generation.


img_widthenum:int ( default: 512 ) Affects Pricing

Image resolution.

Allowed values:


img_heightenum:int ( default: 512 ) Affects Pricing

Image resolution.

Allowed values:

To keep track of your credit usage, you can inspect the response headers of each API call. The x-remaining-credits property will indicate the number of remaining credits in your account. Ensure you monitor this value to avoid any disruptions in your API usage.