POST
javascript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 const axios = require('axios'); const fs = require('fs'); const path = require('path'); async function toB64(imgPath) { const data = fs.readFileSync(path.resolve(imgPath)); return Buffer.from(data).toString('base64'); } const api_key = "YOUR API-KEY"; const url = "https://api.segmind.com/v1/sam-v21-hiera-large"; const data = { "image": "toB64('https://huggingface.co/datasets/hf-internal-testing/sam2-fixtures/resolve/main/truck.jpg')", "make_overlay": true, "save_polygons": true, "save_rle": true, "save_pngs": true, "points_per_side": 32, "points_per_batch": 64, "pred_iou_thresh": 0.86, "stability_score_thresh": 0, "min_mask_region_area": 0, "nms_iou_thresh": 0.7, "max_masks": 0, "polygon_epsilon": 0, "tile_size": 0, "tile_stride": 0 }; (async function() { try { const response = await axios.post(url, data, { headers: { 'x-api-key': api_key } }); console.log(response.data); } catch (error) { console.error('Error:', error.response.data); } })();
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

Attributes


imageimage *

Input image URL or base64 encoded image


make_overlaybool ( default: true )

Generate overlay image with masks


save_polygonsbool ( default: true )

Include polygon coordinates in output


save_rlebool ( default: true )

Include COCO RLE format in output


save_pngsbool ( default: true )

Generate individual PNG masks in ZIP


points_per_sideint ( default: 32 )

Number of points per side for mask generation

min : 8,

max : 64


points_per_batchint ( default: 64 )

Number of points per batch for processing

min : 16,

max : 128


pred_iou_threshfloat ( default: 0.86 )

Prediction IoU threshold for mask filtering

min : 0.5,

max : 1


stability_score_threshfloat ( default: 1 )

Stability score threshold for mask filtering

min : 0,

max : 1


min_mask_region_areaint ( default: 1 )

Minimum mask area in pixels

min : 0,

max : 10000


nms_iou_threshfloat ( default: 0.7 )

Non-Maximum Suppression IoU threshold

min : 0,

max : 1


max_masksint ( default: 1 )

Maximum number of masks to return (0 = no limit)

min : 0,

max : 100


polygon_epsilonfloat ( default: 1 )

Epsilon for polygon simplification

min : 0,

max : 10


tile_sizeint ( default: 1 )

Tile size for large images (0 = disabled)

min : 0,

max : 2048


tile_strideint ( default: 1 )

Tile stride for large images (0 = use tile_size)

min : 0,

max : 2048

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.

SAM v2.1 Hiera Large

SAM v2.1 (Segment Anything Model 2.1) represents the next evolution in promptable visual segmentation by Meta AI, delivering more accurate and efficient mask generation for a wide range of image types and contexts.

Model Information

  • Architecture: SAM v2.1 extends the original SAM framework with optimized Hiera-based encoders for higher accuracy and speed.
  • Flexible Outputs: Supports overlay images, polygon coordinates, COCO RLE encodings, and individual PNG masks.

How to Use the Model

  1. Upload an image (JPG, PNG, or WebP) — either as a URL or base64 string.
  2. Configure output options:
    • make_overlay – Generate a visual overlay of masks on the input image.
    • save_polygons – Return polygon coordinates for each segmented region.
    • save_rle – Export COCO RLE encodings for mask data.
    • save_pngs – Save individual masks as PNGs in a ZIP file.
  3. Adjust advanced parameters for quality and precision:
    • points_per_side, points_per_batch, pred_iou_thresh, stability_score_thresh, min_mask_region_area, nms_iou_thresh, max_masks, polygon_epsilon, tile_size, tile_stride.
  4. Click “Generate” to obtain segmentation results.

Use Cases

  • Assisted Image Labeling: Speeds up dataset annotation with automatic mask proposals.
  • AR/VR Applications: Enables precise object isolation for immersive environments.
  • Autonomous Vehicles: Supports accurate perception and obstacle detection.
  • Environmental Monitoring: Segments satellite and aerial imagery for analysis.
  • Industrial & Sonar Imaging: Identifies regions of interest in complex visual data.