Automatic Mask Generator

Automatic Mask Generator is a powerful tool that automates the creation of precise masks for inpainting

~1.49s
~$0.001
 1import requests
 2import json
 3
 4url = "https://api.segmind.com/v1/models/automatic-mask-generator"
 5headers = {
 6    "x-api-key": "YOUR_API_KEY",
 7    "Content-Type": "application/json"
 8}
 9
10data = {
11    "prompt": "sample text",
12    "image": "sample text",
13    "threshold": 0.2,
14    "stop_on_empty_mask": false,
15    "invert_mask": false,
16    "return_mask": true,
17    "return_alpha": false,
18    "grow_mask": 10,
19    "seed": -1,
20    "base64": false
21}
22
23response = requests.post(url, headers=headers, json=data)
24
25if response.status_code == 200:
26    result = response.json()
27    print(json.dumps(result, indent=2))
28else:
29    print(f"Error: {response.status_code}")
30    print(response.text)

API Endpoint

POSThttps://api.segmind.com/v1/models/automatic-mask-generator

Parameters

imagerequired
string (base64)

Upload your input image

promptrequired
string

Prompt to render

base64optional
boolean

Base64 encoding of the output image.

Default: false
grow_maskoptional
integer

Selectively expand image regions

Default: 10Range: 0 - 100
invert_maskoptional
boolean

Refers to inverting the mask.

Default: false
return_alphaoptional
boolean

Check this to obtain alpha mask image

Default: false
return_maskoptional
boolean

Check this to obtain the mask as the output.

Default: true
seedoptional
integer

Seed for image generation.

Default: -1Range: -1 - 999999999999999
stop_on_empty_maskoptional
boolean

Refers to stop the execution on an empty mask.

Default: false
thresholdoptional
number

Detection threshold

Default: 0.2Range: 0 - 1

Response Type

Returns: Image

Common Error Codes

The API returns standard HTTP status codes. Detailed error messages are provided in the response body.

400

Bad Request

Invalid parameters or request format

401

Unauthorized

Missing or invalid API key

403

Forbidden

Insufficient permissions

404

Not Found

Model or endpoint not found

406

Insufficient Credits

Not enough credits to process request

429

Rate Limited

Too many requests

500

Server Error

Internal server error

502

Bad Gateway

Service temporarily unavailable

504

Timeout

Request timed out