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.

~1.70s
~$0.002
 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

POSThttps://api.segmind.com/v1/sam-v2-image

Parameters

imagerequired
string (uri)

Input image

Default: "https://segmind-sd-models.s3.amazonaws.com/display_images/sam-v2-ip.jpg"
promptrequired
string

Text prompt for object selection

Default: "boy"
base64optional
boolean

Output as base64 encoded string

Default: false
coordinatesoptional
string

Coordinates 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], ...].

Default: null
overlay_maskoptional
boolean

Whether to overlay a mask on the image

Default: true
remove_coordinatesoptional
string

Coordinates to be removed (optional), format is similar to Coordinates

Default: null

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