> ## 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.

# Redimensionner une image

> Soumets un job de redimensionnement — une image source vers un nouveau ratio (outpainting côté serveur).

Redimensionne une `image` source vers un nouveau `aspect_ratio`. Le redimensionnement
est un **outpainting côté serveur** : le backend rend la composition et le masque à
partir de ta source au ratio cible et remplit la nouvelle toile exposée avec une
extension assortie au style. L'appel renvoie **`202 Accepted`** avec un `id` de job ;
interroge [`GET /images/resizes/{id}`](/fr/api-reference/image-ops/get-resize) pour le
résultat. L'`image` prend **exactement un** de `image_id`, `url` ou
`base64` + `mime_type`. Requiert le scope `images.transform`.

## Exemple : une source par mode

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

  ```bash url theme={null}
  curl -X POST https://api.samsa.ai/public/v1/images/resizes \
    -H "Authorization: Bearer $SAMSA_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "image": { "url": "https://cdn.example.com/portrait.png" },
      "aspect_ratio": "1:1",
      "resolution": "2K",
      "placement": { "gravity": "top", "scale": 0.8 }
    }'
  ```

  ```bash base64 theme={null}
  curl -X POST https://api.samsa.ai/public/v1/images/resizes \
    -H "Authorization: Bearer $SAMSA_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "image": { "base64": "iVBORw0KGgoAAAANSUhEUg...", "mime_type": "image/png" },
      "aspect_ratio": "21:9",
      "num_outputs": 2,
      "prompt": "extend the mountain range on both sides",
      "webhook_url": "https://example.com/webhooks/samsa"
    }'
  ```
</CodeGroup>

La réponse `202` est le handle de job asynchrone :

```json 202 Accepted theme={null}
{
  "id": "e6f7a8b9-0c1d-4e2f-3a4b-5c6d7e8f9a0b",
  "status": "pending",
  "estimated_credits": 5
}
```

<Note>
  `aspect_ratio` est **requis** et l'un de `21:9`, `16:9`, `3:2`, `4:3`, `5:4`, `1:1`,
  `4:5`, `3:4`, `2:3`, `9:16`. `resolution` (`1K` défaut, `2K`, `4K`) est une
  métadonnée fournisseur qui met à l'échelle les credits — la toile est toujours
  rendue avec un bord maximal de 1024px. `num_outputs` (1 à 4) vaut **1** par défaut
  et chaque sortie (output) est facturée. `prompt` est une instruction facultative
  pour la zone nouvellement générée (validée si non vide). `placement` positionne la
  source sur la toile cible : `gravity` est l'un de `center` (défaut), `top`,
  `bottom`, `left`, `right`, `top_left`, `top_right`, `bottom_left`, `bottom_right` ;
  `scale` est dans `(0, 1]` (défaut `1.0` = contain-fit maximal).
</Note>

<Note>
  **No-op masque vide.** Quand l'`aspect_ratio` + `placement` demandés ne laissent
  (presque) aucune nouvelle zone à générer — p. ex. la source correspond déjà au
  ratio cible à `scale = 1` — et qu'aucun `prompt` n'est fourni, le job saute le
  modèle, renvoie la composition aplatie et **rembourse les sorties inutilisées**. Il
  `completes` tout de même.
</Note>

## Credits

Chaque sortie (output) coûte `5` credits en `1K`, en fonction de la résolution
(`1K` ×1, `2K` ×2, `4K` ×4) et multiplié par `num_outputs`. Voir
[Tarifs](/fr/guides/pricing).

## Erreurs

| Statut | Code                                                                                                                                                                                                                                     | Quand                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `402`  | [`insufficient_credits`](/fr/guides/errors#insufficient_credits) / [`insufficient_team_credits`](/fr/guides/errors#insufficient_team_credits) / [`insufficient_unallocated_credits`](/fr/guides/errors#insufficient_unallocated_credits) | Le solde que ce credential peut dépenser est en dessous du coût du job. Les organisations avec au moins une équipe active reçoivent les codes liés aux équipes à la place de `insufficient_credits` (sauf les organisations système exemptées du budgeting par équipe). Une défaillance opérationnelle dans la déduction elle-même peut néanmoins renvoyer le générique `insufficient_credits`, quel que soit le régime. |
| `402`  | [`subscription_inactive`](/fr/guides/errors#subscription_inactive)                                                                                                                                                                       | L'organisation n'a aucun abonnement utilisable.                                                                                                                                                                                                                                                                                                                                                                          |
| `403`  | [`missing_scope`](/fr/guides/errors#missing_scope)                                                                                                                                                                                       | La clé n'a pas le scope `images.transform`.                                                                                                                                                                                                                                                                                                                                                                              |
| `404`  | [`not_found`](/fr/guides/errors#not_found)                                                                                                                                                                                               | L'`image_id` source est inconnu ou n'appartient pas au créateur de la clé — une image créée par un autre membre de ton organisation renvoie aussi un `404`.                                                                                                                                                                                                                                                              |
| `422`  | [`validation_error`](/fr/guides/errors#validation_error)                                                                                                                                                                                 | Zéro/plusieurs modes source, `aspect_ratio` manquant/invalide, `placement` invalide, un `prompt` contraire à la politique, ou une image raster source au-dessus de **33 554 432 pixels** (32 MP, largeur × hauteur), rejetée avec `param: image` avant tout rendu.                                                                                                                                                       |
| `429`  | [`rate_limited`](/fr/guides/errors#rate_limited) / [`too_many_active_jobs`](/fr/guides/errors#too_many_active_jobs)                                                                                                                      | Fenêtre de débit par clé ou plafond de concurrence par organisation dépassé.                                                                                                                                                                                                                                                                                                                                             |


## OpenAPI

````yaml api-reference/openapi.json POST /images/resizes
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/resizes:
    post:
      tags:
        - Images
      summary: Resize an image to a new aspect ratio (server-side outpaint)
      description: >-
        Submits a resize job — one source `image` plus a target `aspect_ratio` —
        and returns `202` immediately with the job `id` and a credit estimate;
        poll `GET /images/resizes/{id}` for the result. The server renders the
        composition and fills the newly exposed canvas with a style-matched
        extension (this is the app's outpaint feature). The source is exactly
        one of `image_id` (an image in your organization's context), an https
        `url`, or `base64`+`mime_type`. `aspect_ratio` is REQUIRED (one of
        `21:9`, `16:9`, `3:2`, `4:3`, `5:4`, `1:1`, `4:5`, `3:4`, `2:3`,
        `9:16`). Optional `resolution` (`1K` default, `2K`, `4K` — the canvas is
        always a 1024px max edge; the tier is provider metadata scaling credits
        1K:1x, 2K:2x, 4K:4x), `num_outputs` (1-4, default **1**), free-text
        `prompt` for the new area, and `placement` (`gravity` + `scale`)
        positioning the source on the canvas. Each output is billed at `5 x
        resolution_multiplier` credits. **Empty-mask no-op:** when the target
        ratio + placement leave (almost) no new area to generate (e.g. the
        source already matches the target ratio at `scale=1`) and no `prompt` is
        given, the job skips the model, returns the flattened composition, and
        refunds the unused outputs — it still `completes`. Common errors: an
        unsupported `aspect_ratio`/`resolution` or a rejected `prompt` returns
        `422`; 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_resize_images_resizes_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PublicResizeRequest'
        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:
    PublicResizeRequest:
      properties:
        image:
          $ref: '#/components/schemas/PublicImageEditSource'
          description: >-
            The source image: exactly one of `image_id`, an https `url`, or
            `base64`+`mime_type`. The source raster must be at most **33,554,432
            pixels** (32 MP, width x height) — a larger source returns `422`
            with `param: image` before any rendering. The composition canvas is
            at most 1024px per edge, so higher-resolution sources gain no output
            detail.
        aspect_ratio:
          type: string
          title: Aspect Ratio
          description: >-
            Target aspect ratio (REQUIRED) — one of: `21:9`, `16:9`, `3:2`,
            `4:3`, `5:4`, `1:1`, `4:5`, `3:4`, `2:3`, `9:16`.
          examples:
            - '16:9'
        resolution:
          type: string
          title: Resolution
          description: >-
            Provider resolution tier — `1K` (default), `2K`, or `4K`. The canvas
            is always rendered at a 1024px max edge (per S8.5); the tier is
            provider metadata that scales credits 1K:1x, 2K:2x, 4K:4x per
            output.
          default: 1K
          examples:
            - 1K
        num_outputs:
          type: integer
          maximum: 4
          minimum: 1
          title: Num Outputs
          description: >-
            Number of images to generate (1-4). Defaults to **1**; each output
            is billed.
          default: 1
          examples:
            - 1
        prompt:
          type: string
          title: Prompt
          description: >-
            Optional instruction for the newly generated area. When non-empty it
            runs the app's prompt validation (rejects empty / malformed /
            policy-violating prompts with a `422`).
          default: ''
          examples:
            - extend the beach and the ocean horizon naturally
        placement:
          anyOf:
            - $ref: '#/components/schemas/PublicResizePlacement'
            - type: 'null'
          description: >-
            Optional placement of the source on the target canvas (`gravity` +
            `scale`). Defaults to centered, maximum contain-fit.
        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).
          examples:
            - https://example.com/webhooks/samsa
      type: object
      required:
        - image
        - aspect_ratio
      title: PublicResizeRequest
      description: >-
        `POST /images/resizes` body (SAM-818 / S8.6 — ADR §8, §10).


        Resize = server-side outpaint: the backend renders the composition +
        mask from

        your source at the target `aspect_ratio` and fills the newly exposed
        canvas

        with a style-matched extension. The source is exactly one of `image_id`
        (an

        image in your organization's context), an https `url`, or
        `base64`+`mime_type`.

        `aspect_ratio` is REQUIRED (validated against the resize engine's
        supported

        list). `num_outputs` defaults to **1**; each output is billed at

        `5 x resolution_multiplier` credits (1K:1x, 2K:2x, 4K:4x).


        Empty-mask no-op: when the requested `aspect_ratio` + `placement` leave
        (almost)

        no new area to generate (e.g. the source already matches the target
        ratio at

        `scale=1`) and no `prompt` is given, the job SKIPS the model, returns
        the

        flattened composition, and REFUNDS the unused outputs — it still
        `completes`.
      examples:
        - aspect_ratio: '16:9'
          image:
            image_id: 123e4567-e89b-12d3-a456-426614174000
        - aspect_ratio: '1:1'
          image:
            url: https://cdn.example.com/portrait.png
          placement:
            gravity: top
            scale: 0.8
          resolution: 2K
        - aspect_ratio: '21:9'
          image:
            base64: iVBORw0KGgoAAAANSUhEUg...
            mime_type: image/png
          num_outputs: 2
          prompt: extend the mountain range on both sides
          webhook_url: https://example.com/webhooks/samsa
    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).
    PublicResizePlacement:
      properties:
        gravity:
          type: string
          title: Gravity
          description: >-
            Placement of the source on the target canvas — one of: center, top,
            bottom, left, right, top_left, top_right, bottom_left, bottom_right.
          default: center
          examples:
            - center
        scale:
          type: number
          maximum: 1
          exclusiveMinimum: 0
          title: Scale
          description: Contain-fit scale in (0, 1]; 1.0 = fill the canvas edge-to-edge.
          default: 1
          examples:
            - 1
      type: object
      title: PublicResizePlacement
      description: >-
        Where the source sits on the resized canvas (S8.5 geometry).


        ``gravity`` is one of the nine positions; ``scale`` in ``(0, 1]``
        shrinks the

        contain-fit placement (1.0 = maximum contain-fit).
        ``build_resize_composition``

        re-validates both (the geometry authority) — these validators give a
        clean,

        param-scoped ``422`` at request parse.
    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_...`.

````