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

# Edit an image

> Edit or transform an existing image from a prompt and one or more input images. Sent as `multipart/form-data`. Supports the same model-specific sizing and quality parameters as image generation; how many reference images a model accepts varies (see the `edit` block in `GET /v1/models`).



## OpenAPI

````yaml /api-reference/openapi.json post /v1/images/edits
openapi: 3.1.0
info:
  title: Deepshi API
  description: >-
    OpenAI-compatible REST API for Deepshi's own models and leading third-party
    models. Authenticate with your Deepshi API key as a bearer token, and
    reference a model by its id (e.g. `deepshi-3.0`, `gpt-4o`) in the `model`
    field.
  version: 1.0.0
servers:
  - url: https://api.deepshi.ai
    description: Deepshi API
security:
  - BearerAuth: []
paths:
  /v1/images/edits:
    post:
      tags:
        - Images
      summary: Edit an image
      description: >-
        Edit or transform an existing image from a prompt and one or more input
        images. Sent as `multipart/form-data`. Supports the same model-specific
        sizing and quality parameters as image generation; how many reference
        images a model accepts varies (see the `edit` block in `GET
        /v1/models`).
      operationId: editImage
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ImageEditRequest'
            encoding:
              image[]:
                style: form
                explode: true
                contentType: image/png, image/jpeg, image/webp
              image:
                style: form
                explode: true
                contentType: image/png, image/jpeg, image/webp
      responses:
        '200':
          description: >-
            The edited image(s). When `stream: true`, the response is a
            Server-Sent Events stream (`text/event-stream`): periodic keepalive
            comments followed by a terminal `image_generation.completed` event
            carrying the final image (see the `ImageStreamEvent` schema).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageResponse'
            text/event-stream:
              schema:
                $ref: '#/components/schemas/ImageStreamEvent'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/InsufficientQuota'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    ImageEditRequest:
      type: object
      description: >-
        Image edit request, sent as `multipart/form-data`. `model`, `prompt`,
        and at least one input image are required. Send the image files under
        either `image[]` or `image` — both are accepted.
      required:
        - model
        - prompt
      anyOf:
        - required:
            - image[]
        - required:
            - image
      properties:
        model:
          type: string
          description: The image model id to use. See `GET /v1/models`.
          example: nano-banana-2
        prompt:
          type: string
          description: Instruction describing the edit to perform.
          example: remove the person on the left
        image[]:
          type: array
          items:
            type: string
            format: binary
          description: >-
            One or more input images to edit, each sent as a separate `image[]`
            part. How many reference images a model accepts varies from 1 up to
            14. See the `edit` block in `GET /v1/models`.
        image:
          type: array
          items:
            type: string
            format: binary
          description: >-
            Same as `image[]`, under the field name the OpenAI SDKs use when you
            pass a single file. Send images under either this or `image[]`.
        'n':
          type: integer
          description: Number of images to generate (1–4).
          minimum: 1
          maximum: 4
          default: 1
        response_format:
          type: string
          description: >-
            How images are returned. `url` returns an inline base64 `data:` URI,
            not a hosted link.
          enum:
            - b64_json
            - url
          default: b64_json
        output_format:
          type: string
          description: Encoding of the returned image. Not all models honor every format.
          enum:
            - png
            - jpeg
            - webp
        stream:
          type: boolean
          description: >-
            Stream the result as Server-Sent Events. Use it for slow,
            high-resolution generations that would otherwise time out.
          default: false
        seed:
          type: integer
          description: Seed for reproducible output. Omit for a random seed.
        width:
          type: integer
          description: >-
            Model-specific. Output width in pixels, for pixel-dimension models
            (e.g. `flux-2-pro`).
        height:
          type: integer
          description: Model-specific. Output height in pixels, for pixel-dimension models.
        aspect_ratio:
          type: string
          description: >-
            Model-specific. Aspect ratio for aspect-ratio and resolution-tier
            models.
          example: '16:9'
        resolution:
          type: string
          description: >-
            Model-specific. Resolution tier for resolution-tier models (e.g.
            `nano-banana-2`, `nano-banana-pro`, `grok-imagine-quality`).
            Determines the billed price for those models.
          example: 2K
        quality:
          type: string
          description: >-
            Model-specific. Quality tier for the GPT Image models
            (`gpt-image-1.5`, `gpt-image-2`). Higher tiers cost more, and the
            price depends on the image size and quality you pick. Omit to use
            the model's default tier.
          enum:
            - low
            - medium
            - high
        image_size:
          type: string
          description: >-
            Model-specific. Named output size for preset-size models (e.g.
            `seedream-4.5`).
          example: auto_2K
    ImageResponse:
      type: object
      properties:
        created:
          type: integer
          format: int64
          description: Unix timestamp when the request was created.
        model:
          type: string
          description: The image model id you requested.
        size:
          type: string
          description: The actual output dimensions, as `WIDTHxHEIGHT`.
        data:
          type: array
          items:
            $ref: '#/components/schemas/ImageData'
          description: The generated image(s).
        usage:
          $ref: '#/components/schemas/Usage'
    ImageStreamEvent:
      type: object
      description: >-
        One Server-Sent Event from a streamed image request (`stream: true`).
        The stream sends keepalive comments, then a terminal
        `image_generation.completed` event carrying the final image and usage.
        Note the flat shape: `b64_json` is top-level here, not nested under
        `data[]` as in the non-streamed `ImageResponse`.
      properties:
        type:
          type: string
          description: Event type.
          example: image_generation.completed
        b64_json:
          type: string
          description: Base64-encoded image, present on the completed event.
        size:
          type: string
          description: Output dimensions of the image.
          example: 1024x1024
        usage:
          $ref: '#/components/schemas/Usage'
    ImageData:
      type: object
      required:
        - index
      properties:
        b64_json:
          type: string
          nullable: true
          description: >-
            Base64-encoded image. Present when `response_format` is `b64_json`
            (the default).
        url:
          type: string
          nullable: true
          description: >-
            Inline `data:` URI for the image. Present when `response_format` is
            `url`.
        revised_prompt:
          type: string
          nullable: true
          description: The prompt actually used, if the model revised it.
        index:
          type: integer
          description: Position of this image in the batch.
    Usage:
      type: object
      description: Token usage and the billed cost for the request.
      properties:
        prompt_tokens:
          type: integer
          description: Total input tokens (includes any cached tokens).
        prompt_tokens_details:
          type: object
          properties:
            cached_tokens:
              type: integer
            cached_read_tokens:
              type: integer
              description: >-
                Tokens served from the prompt cache, billed at the cache-read
                rate.
            image_tokens:
              type: integer
        completion_tokens:
          type: integer
          description: >-
            Output tokens generated (includes reasoning tokens for reasoning
            models).
        completion_tokens_details:
          type: object
          properties:
            reasoning_tokens:
              type: integer
            image_tokens:
              type: integer
        total_tokens:
          type: integer
        cost:
          $ref: '#/components/schemas/Cost'
    Error:
      type: object
      description: Error envelope, matching the OpenAI shape.
      required:
        - error
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: Human-readable description of the error.
            type:
              type: string
              description: >-
                Error category, e.g. `invalid_request_error` or
                `insufficient_quota`.
            code:
              type: string
              nullable: true
              description: >-
                Machine-readable error code, e.g. `invalid_api_key`,
                `model_not_found`, `insufficient_quota` (may be null).
            param:
              type: string
              nullable: true
              description: The request parameter the error relates to, when applicable.
    Cost:
      type: object
      description: >-
        Deepshi extension: the exact USD amount this request deducted from your
        balance. Standard OpenAI SDKs ignore it.
      properties:
        total_cost:
          type: number
          description: USD cost deducted from your balance for this request.
          example: 0.000135
  responses:
    BadRequest:
      description: Malformed request, or a model id that doesn't exist in the catalog.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: The model does not exist or you do not have access to it.
              type: invalid_request_error
              code: model_not_found
              param: null
    Unauthorized:
      description: Missing, malformed, or unknown API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Incorrect API key provided.
              type: invalid_request_error
              code: invalid_api_key
              param: null
    InsufficientQuota:
      description: The account is out of credits.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: You have insufficient credits to complete this request.
              type: insufficient_quota
              code: insufficient_quota
              param: null
    Forbidden:
      description: The key is revoked, or not permitted to use the requested model.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: The model does not exist or you do not have access to it.
              type: invalid_request_error
              code: model_not_found
              param: null
    RateLimited:
      description: Too many requests. Back off and retry.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Rate limit reached. Please retry after a short delay.
              type: rate_limit_error
              code: rate_limit_exceeded
              param: null
    InternalError:
      description: Temporary server error. Retry with backoff.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                The server had an error while processing your request. Please
                retry.
              type: api_error
              code: null
              param: null
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: 'Your Deepshi API key, sent as `Authorization: Bearer <key>`.'

````