Sam V2 Image Serverless API
SAM v2, the next-gen segmentation model from Meta AI, revolutionizes computer vision. Building on SAM's success, it excels at accurately segmenting objects in images, offering robust and efficient solutions for various visual contexts.
1import requests
2import json
3
4url = "https://api.segmind.com/v1/sam-v2-image"
5headers = {
6 "x-api-key": "YOUR_API_KEY",
7 "Content-Type": "application/json"
8}
9
10data = {
11 "base64": false,
12 "image": "https://segmind-sd-models.s3.amazonaws.com/display_images/sam-v2-ip.jpg",
13 "overlay_mask": true,
14 "prompt": "boy"
15}
16
17response = requests.post(url, headers=headers, json=data)
18
19if response.status_code == 200:
20 result = response.json()
21 print(json.dumps(result, indent=2))
22else:
23 print(f"Error: {response.status_code}")
24 print(response.text) 1import requests
2import json
3
4url = "https://api.segmind.com/v1/sam-v2-image"
5headers = {
6 "x-api-key": "YOUR_API_KEY",
7 "Content-Type": "application/json"
8}
9
10data = {
11 "base64": false,
12 "image": "https://segmind-sd-models.s3.amazonaws.com/display_images/sam-v2-ip.jpg",
13 "overlay_mask": true,
14 "prompt": "boy"
15}
16
17response = requests.post(url, headers=headers, json=data)
18
19if response.status_code == 200:
20 result = response.json()
21 print(json.dumps(result, indent=2))
22else:
23 print(f"Error: {response.status_code}")
24 print(response.text)API Endpoint
https://api.segmind.com/v1/sam-v2-imageParameters
imagerequiredstring (uri)Input image
"https://segmind-sd-models.s3.amazonaws.com/display_images/sam-v2-ip.jpg"promptrequiredstringText prompt for object selection
"boy"base64optionalbooleanOutput as base64 encoded string
falsecoordinatesoptionalstringCoordinates for image selection (optional): Provide either a prompt or coordinates. If a prompt is provided, coordinates will be ignored. For a single coordinate, use the format [834,74]. For multiple coordinates, use [[839,74], [844,20], ...].
nulloverlay_maskoptionalbooleanWhether to overlay a mask on the image
trueremove_coordinatesoptionalstringCoordinates to be removed (optional), format is similar to Coordinates
nullResponse Type
Returns: Image
Common Error Codes
The API returns standard HTTP status codes. Detailed error messages are provided in the response body.
Bad Request
Invalid parameters or request format
Unauthorized
Missing or invalid API key
Forbidden
Insufficient permissions
Not Found
Model or endpoint not found
Insufficient Credits
Not enough credits to process request
Rate Limited
Too many requests
Server Error
Internal server error
Bad Gateway
Service temporarily unavailable
Timeout
Request timed out