> ## Documentation Index
> Fetch the complete documentation index at: https://docs.livepeer.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Segment Anything 2

> Segment objects in an image.

<Info>
  The default Gateway used in this guide is the public
  [Livepeer.cloud](https://www.livepeer.cloud/) Gateway. It is free to use but
  not intended for production-ready applications. For production-ready
  applications, consider using the [Livepeer Studio](https://livepeer.studio/)
  Gateway, which requires an API token. Alternatively, you can set up your own
  Gateway node or partner with one via the `ai-video` channel on
  [Discord](https://discord.gg/livepeer).
</Info>

<Note>
  Please note that the exact parameters, default values, and responses may vary
  between models. For more information on model-specific parameters, please
  refer to the respective model documentation available in the
  [segment-anything-2 pipeline](/ai/pipelines/segment-anything-2). Not all
  parameters might be available for a given model.
</Note>


## OpenAPI

````yaml post /segment-anything-2
openapi: 3.1.0
info:
  title: Livepeer AI Runner
  description: An application to run AI pipelines
  version: 0.0.0
servers:
  - url: https://dream-gateway.livepeer.cloud
    description: Livepeer Cloud Community Gateway
  - url: https://livepeer.studio/api/beta/generate
    description: Livepeer Studio Gateway
security: []
paths:
  /segment-anything-2:
    post:
      tags:
        - generate
      summary: Segment Anything 2
      description: Segment objects in an image.
      operationId: genSegmentAnything2
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/Body_genSegmentAnything2'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MasksResponse'
                x-speakeasy-name-override: data
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPError'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPError'
      security:
        - HTTPBearer: []
components:
  schemas:
    Body_genSegmentAnything2:
      properties:
        image:
          type: string
          format: binary
          title: Image
          description: Image to segment.
        model_id:
          type: string
          title: Model Id
          description: Hugging Face model ID used for image generation.
          default: ''
        point_coords:
          type: string
          title: Point Coords
          description: >-
            Nx2 array of point prompts to the model, where each point is in
            (X,Y) in pixels.
        point_labels:
          type: string
          title: Point Labels
          description: >-
            Labels for the point prompts, where 1 indicates a foreground point
            and 0 indicates a background point.
        box:
          type: string
          title: Box
          description: A length 4 array given as a box prompt to the model, in XYXY format.
        mask_input:
          type: string
          title: Mask Input
          description: >-
            A low-resolution mask input to the model, typically from a previous
            prediction iteration, with the form 1xHxW (H=W=256 for SAM).
        multimask_output:
          type: boolean
          title: Multimask Output
          description: >-
            If true, the model will return three masks for ambiguous input
            prompts, often producing better masks than a single prediction.
          default: true
        return_logits:
          type: boolean
          title: Return Logits
          description: >-
            If true, returns un-thresholded mask logits instead of a binary
            mask.
          default: true
        normalize_coords:
          type: boolean
          title: Normalize Coords
          description: >-
            If true, the point coordinates will be normalized to the range
            [0,1], with point_coords expected to be with respect to image
            dimensions.
          default: true
      type: object
      required:
        - image
      title: Body_genSegmentAnything2
    MasksResponse:
      properties:
        masks:
          type: string
          title: Masks
          description: The generated masks.
        scores:
          type: string
          title: Scores
          description: The model's confidence scores for each generated mask.
        logits:
          type: string
          title: Logits
          description: The raw, unnormalized predictions (logits) for the masks.
      type: object
      required:
        - masks
        - scores
        - logits
      title: MasksResponse
      description: Response model for object segmentation.
    HTTPError:
      properties:
        detail:
          allOf:
            - $ref: '#/components/schemas/APIError'
          description: Detailed error information.
      type: object
      required:
        - detail
      title: HTTPError
      description: HTTP error response model.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    APIError:
      properties:
        msg:
          type: string
          title: Msg
          description: The error message.
      type: object
      required:
        - msg
      title: APIError
      description: API error response model.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````