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

# Remove a background

> Submit a background-removal job — one source image — and get a transparent PNG back.

Remove the background from one source `image`, producing a transparent PNG. The call
returns **`202 Accepted`** with a job `id`; poll
[`GET /images/background-removals/{id}`](/api-reference/image-ops/get-background-removal)
for the result. The `image` takes **exactly one** of `image_id`, `url`, or
`base64` + `mime_type`. There is **no model parameter** — v1 uses the default
background-removal model. Requires the `images.transform` scope.

## Example: one source per mode

<CodeGroup>
  ```bash image_id theme={null}
  curl -X POST https://api.samsa.ai/public/v1/images/background-removals \
    -H "Authorization: Bearer $SAMSA_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{ "image": { "image_id": "123e4567-e89b-12d3-a456-426614174000" } }'
  ```

  ```bash url theme={null}
  curl -X POST https://api.samsa.ai/public/v1/images/background-removals \
    -H "Authorization: Bearer $SAMSA_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "image": { "url": "https://cdn.example.com/photo.png" },
      "webhook_url": "https://example.com/webhooks/samsa"
    }'
  ```

  ```bash base64 theme={null}
  curl -X POST https://api.samsa.ai/public/v1/images/background-removals \
    -H "Authorization: Bearer $SAMSA_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{ "image": { "base64": "iVBORw0KGgoAAAANSUhEUg...", "mime_type": "image/png" } }'
  ```
</CodeGroup>

The normal (charged) path returns a `pending` job:

```json 202 Accepted theme={null}
{
  "id": "f7a8b9c0-1d2e-4f3a-4b5c-6d7e8f9a0b1c",
  "status": "pending",
  "estimated_credits": 1
}
```

<Note>
  **Cost = 1 credit on a miss; 0 on a cache hit.** When the source is an `image_id`
  you own and a background-removed result already exists for it, the submit returns
  `202` with `status: "completed"` and `estimated_credits: 0` **immediately** — no
  new job is queued and your organization's concurrency cap is not consumed. Every
  other case (an `https` `url`/`base64` source, or an owned `image_id` with no ready
  result) is the normal charged path above.
</Note>

```json 202 Accepted (cache hit) theme={null}
{
  "id": "f7a8b9c0-1d2e-4f3a-4b5c-6d7e8f9a0b1c",
  "status": "completed",
  "estimated_credits": 0
}
```

## Errors

| Status | Code                                                                                                                                                                                                                            | When                                                                                                                                                                                                                                                                                                                                         |
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `402`  | [`insufficient_credits`](/guides/errors#insufficient_credits) / [`insufficient_team_credits`](/guides/errors#insufficient_team_credits) / [`insufficient_unallocated_credits`](/guides/errors#insufficient_unallocated_credits) | The balance this credential can spend is below the job cost. Organizations with at least one active team get the team-aware codes instead of `insufficient_credits` (budget-exempt system organizations excepted). An operational failure inside the deduction can still surface as the generic `insufficient_credits`, whatever the regime. |
| `402`  | [`subscription_inactive`](/guides/errors#subscription_inactive)                                                                                                                                                                 | The organization has no usable subscription.                                                                                                                                                                                                                                                                                                 |
| `403`  | [`missing_scope`](/guides/errors#missing_scope)                                                                                                                                                                                 | Key lacks the `images.transform` scope.                                                                                                                                                                                                                                                                                                      |
| `404`  | [`not_found`](/guides/errors#not_found)                                                                                                                                                                                         | The source `image_id` is unknown, or not owned by the API key's creator — an image another member of your organization created is a `404` too.                                                                                                                                                                                               |
| `422`  | [`validation_error`](/guides/errors#validation_error)                                                                                                                                                                           | Zero or multiple source modes supplied.                                                                                                                                                                                                                                                                                                      |
| `429`  | [`rate_limited`](/guides/errors#rate_limited) / [`too_many_active_jobs`](/guides/errors#too_many_active_jobs)                                                                                                                   | Per-key rate window or per-org concurrency cap exceeded.                                                                                                                                                                                                                                                                                     |


## OpenAPI

````yaml api-reference/openapi.json POST /images/background-removals
openapi: 3.1.0
info:
  title: Samsa API
  description: >-
    The Samsa public REST API. Authenticate with an organization API key as a
    bearer token (`Authorization: Bearer samsa_sk_...`). Errors follow a single
    envelope shape; every response carries an `X-Request-ID`.
  version: 1.0.0
servers:
  - url: https://api.samsa.ai/public/v1
security:
  - BearerAuth: []
paths:
  /images/background-removals:
    post:
      tags:
        - Images
      summary: Remove an image's background (transparent PNG)
      description: >-
        Submits a background-removal job — one source `image` — and returns
        `202` immediately with the job `id` and a credit estimate; poll `GET
        /images/background-removals/{id}` for the result (a transparent PNG).
        The source is exactly one of `image_id` (an image in your organization's
        context), an https `url`, or `base64`+`mime_type`. There is NO model
        parameter — v1 uses the default background-removal model. **Cost = 1
        credit on a miss; 0 on a cache HIT.** When the source is an `image_id`
        you own and a background-removed result already exists for it, the
        submit returns `202` with `status: "completed"` and `estimated_credits:
        0` immediately — no new job is queued and the per-org concurrency cap is
        not consumed (an at-cap org still gets its cached result); if a
        `webhook_url` was given the `completed` event fires right away. Every
        other case (an https `url`/`base64` source, or an owned `image_id` with
        no ready result) is the normal charged path: `202` with `status:
        "pending"` and `estimated_credits: 1`. Common errors: a foreign or
        unknown `image_id` returns `404`; missing credits or no usable org
        subscription returns `402`; the per-key rate limit or per-org
        concurrency cap returns `429`. Requires the `images.transform` scope.
      operationId: create_image_background_removal_images_background_removals_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PublicBackgroundRemovalRequest'
        required: true
      responses:
        '202':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicTransformAccepted'
        '401':
          description: Missing, invalid, expired, or revoked API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '402':
          description: Insufficient credits, or no usable org subscription.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '403':
          description: The API key lacks the required scope for this operation.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '404':
          description: Generation, or a referenced model/palette, not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '409':
          description: A referenced model is not ready for generation.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '422':
          description: Request validation failed (prompt, engine, resolution, ...).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '429':
          description: Per-key rate limit or per-org concurrency cap exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '500':
          description: Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
components:
  schemas:
    PublicBackgroundRemovalRequest:
      properties:
        image:
          $ref: '#/components/schemas/PublicImageEditSource'
          description: >-
            The source image: exactly one of `image_id`, an https `url`, or
            `base64`+`mime_type`.
        webhook_url:
          anyOf:
            - type: string
            - type: 'null'
          title: Webhook Url
          description: >-
            Optional https webhook notified once on terminal status (signed per
            the webhook signature scheme; see the webhooks docs). On a cache hit
            the `completed` event fires immediately.
          examples:
            - https://example.com/webhooks/samsa
      type: object
      required:
        - image
      title: PublicBackgroundRemovalRequest
      description: >-
        `POST /images/background-removals` body (SAM-820 / S8.8 — ADR §7, §8,
        §10).


        Remove the background from ONE source `image`, producing a transparent
        PNG.

        The source is exactly one of `image_id` (an image in your organization's

        context), an https `url`, or `base64`+`mime_type`. There is NO model

        parameter — v1 uses the default background-removal model.


        **Cost = 1 credit on a miss; 0 on a cache HIT.** When the source is an

        `image_id` you own and a background-removed result already exists for
        it, the

        submit returns `202` with `status: "completed"` and `estimated_credits:
        0`

        immediately (no new job is queued and the org's concurrency cap is not

        consumed). Every other case (an https `url`/`base64` source, or an owned

        `image_id` with no ready result) is the normal charged path: `202` with

        `status: "pending"` and `estimated_credits: 1`.
      examples:
        - image:
            image_id: 123e4567-e89b-12d3-a456-426614174000
        - image:
            url: https://cdn.example.com/photo.png
          webhook_url: https://example.com/webhooks/samsa
        - image:
            base64: iVBORw0KGgoAAAANSUhEUg...
            mime_type: image/png
    PublicTransformAccepted:
      properties:
        id:
          type: string
          format: uuid
          title: Id
          description: The job id — poll the op's `GET .../{id}` endpoint.
        status:
          $ref: '#/components/schemas/PublicImageStatus'
          description: >-
            Initial status: `pending` (job queued — enter the polling flow), or
            `completed` with `estimated_credits: 0` when `background-removals` /
            `vectorizations` serve an owned-image cache hit (the result is
            immediately available).
          examples:
            - pending
        estimated_credits:
          type: integer
          title: Estimated Credits
          description: >-
            Credits this job is expected to cost — `0` on a cache-hit
            `completed` response.
          examples:
            - 5
      type: object
      required:
        - id
        - status
        - estimated_credits
      title: PublicTransformAccepted
      description: >-
        Shared `202` body for the transform-op submits (SAM-813 / S8 wave).


        Every `POST /images/<op>` returns the async job handle

        `{id, status, estimated_credits}`. The initial `status` is `pending`
        (the

        job is queued), with ONE exception: `background-removals` and

        `vectorizations` answer an owned-`image_id` cache hit (a ready result

        already exists for that image) with `status: "completed"` and

        `estimated_credits: 0` — no new job is queued, the `completed` webhook

        event is emitted immediately for a supplied `webhook_url`, and the
        result

        is already available from the op's `GET .../{id}` endpoint. The other

        transform ops (`img2img`, `variations`, `resizes`, `upscales`) always

        start `pending`.
    ErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetail'
      type: object
      required:
        - error
      title: ErrorEnvelope
      description: The complete public error body — an ``error`` object wrapper (ADR §5).
    PublicImageEditSource:
      properties:
        image_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Image Id
          description: Id of an image in your organization's context to edit.
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
          description: https URL of the source image (downloaded under SSRF guards).
          examples:
            - https://cdn.example.com/photo.png
        base64:
          anyOf:
            - type: string
            - type: 'null'
          title: Base64
          description: Base64-encoded source image bytes (send with `mime_type`).
        mime_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Mime Type
          description: >-
            MIME type for a base64 source — one of: image/jpeg, image/png,
            image/webp.
          examples:
            - image/png
      type: object
      title: PublicImageEditSource
      description: >-
        The source image for an edit — exactly one of three modes (ticket §1).


        * `image_id` — an image already in the key creator's context (owned by
        the key
          creator; ownership is enforced in the route -> `404` on a miss).
        * `url` — an `https` URL the server downloads under the SSRF guard
        (§7.4).

        * `base64` + `mime_type` — inline bytes (`mime_type` in the allow-list).


        Exactly one mode must be supplied; zero or more than one is a `422`.


        `url` / `base64` rasters must decode to at most **33,554,432 pixels**

        (32 MP, width x height) — a larger source returns `422` naming the
        source

        param, before any charge (same ceiling the resize op documents).
    PublicImageStatus:
      type: string
      enum:
        - pending
        - processing
        - completed
        - failed
        - cancelled
      title: PublicImageStatus
      description: >-
        Public image-job status — the lower-cased internal ``TaskStatus``.


        Deliberately the plain lower-cased internal value (NOT the ADR §7.2

        ``PENDING -> queued`` remap): the ticket's 202 uses ``status:
        "pending"`` and

        its fixtures say ``pending/processing/completed/failed``, and this keeps
        the

        public surface consistent with the already-shipped models API

        (``PublicModelStatus``).
    ErrorDetail:
      properties:
        type:
          type: string
          title: Type
          examples:
            - authentication_error
        code:
          type: string
          title: Code
          examples:
            - invalid_api_key
        message:
          type: string
          title: Message
          examples:
            - The provided API key is invalid, expired, or revoked.
        request_id:
          type: string
          title: Request Id
          examples:
            - 8f14e45fceea167a5a36dedd4bea2543
        param:
          anyOf:
            - type: string
            - type: 'null'
          title: Param
          description: Present on validation errors — names the offending field.
          examples:
            - aspect_ratio
      type: object
      required:
        - type
        - code
        - message
        - request_id
      title: ErrorDetail
      description: The ``error`` object of the public envelope (ADR §5).
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Organization API key as a bearer token: `Authorization: Bearer
        samsa_sk_...`.

````