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

# Edit

> Edit a public image with a prompt and region geometry.

Edit is a follow-up operation on one image from a completed parent task. Pass
the parent `jobId`, zero-based `imageNo`, canvas, image position, and replacement
prompt described by the generated request schema. A mask is optional.

The response is an asynchronous task. Validate geometry in your application
before submitting and persist the returned `job_id`.


## OpenAPI

````yaml POST /v1/edit
openapi: 3.1.0
info:
  title: Legnext AI API
  description: |-
    The Legnext API generates and edits images and videos with Midjourney.

    ## Authentication

    Send your API key in the `x-api-key` header on every request (the
    `Authorization: Bearer <key>` form is also accepted). Create and
    manage keys in the Legnext dashboard.

    The one exception is `GET /v1/job/{job_id}`, which is
    unauthenticated. Its UUID is a capability token: keep it private and do not
    expose it in client-side logs or analytics.

    ## Asynchronous tasks

    Every generation endpoint creates an asynchronous task and returns the full
    `TaskResponse` object immediately (status `pending`, or `staged`
    when the account is at its concurrency limit). The task reaches a terminal
    status — `completed` or `failed` — within seconds to minutes. Poll
    `GET /v1/job/{job_id}` or pass a `callback` URL at creation to be
    notified (the completed TaskResponse is POSTed to it).

    ## Errors

    Task endpoints (everything under `/v1`) report errors in the same
    `TaskResponse` shape as success: `status` is `failed` and the
    `error` object carries `code` (the HTTP status) and `message`.
    Account, usage, and webhook endpoints report errors as
    `{code, message}` where `code` mirrors the HTTP status.

    ## Limits and maintenance

    `402` means insufficient quota, `429` means the account's concurrency
    or staged-queue limit is reached (retry once running tasks finish), and
    `503` means the service (or one provider-backed feature) is under
    maintenance.
  version: 1.0.0
  contact:
    email: support@legnext.ai
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: https://api.legnext.ai/api
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Image Generation
    description: Create and derive Midjourney images.
  - name: Video Generation
    description: Create and extend Midjourney videos.
  - name: Image Enhancement
    description: AI image enhancement and upscaling (Topaz).
  - name: Task Management
    description: Track and query asynchronous tasks.
  - name: Account
    description: Account profile, balance, and quota.
paths:
  /v1/edit:
    post:
      tags:
        - Image Generation
      summary: Edit Image
      description: >-
        Reposition and repaint an image on a custom canvas with optional masks.


        Requires a base image generated on our premium lane (e.g. with --turbo);
        editing a standard-lane base image is rejected.
      operationId: editImage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EditRequest'
      responses:
        '200':
          description: Edit task accepted.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TaskResponse'
        '400':
          description: >-
            Bad Request — invalid request body or parameter values (see
            `error.message`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TaskResponse'
        '401':
          description: Unauthorized — missing, invalid, or revoked API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TaskResponse'
        '402':
          description: >-
            Payment Required — insufficient quota to freeze for this task
            (`insufficient quota`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TaskResponse'
        '403':
          description: Forbidden — account disabled or daily error limit reached.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TaskResponse'
        '429':
          description: >-
            Too Many Requests — concurrency or staged-queue limit exceeded;
            retry after running tasks finish.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TaskResponse'
        '500':
          description: Internal Server Error — unexpected server-side failure.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TaskResponse'
components:
  schemas:
    EditRequest:
      type: object
      properties:
        callback:
          type: string
          format: uri
          description: >-
            Optional webhook URL. When set, the completed TaskResponse is POSTed
            to this URL; when empty, poll GET /v1/job/{job_id}.
        canvas:
          $ref: '#/components/schemas/OfficialCanvas'
          description: Target canvas dimensions.
        imageNo:
          type: integer
          description: >-
            Index of the image in the parent task's grid (0-3, left-to-right,
            top-to-bottom).
          minimum: 0
          maximum: 3
        imgPos:
          $ref: '#/components/schemas/OfficialImagePosition'
          description: Position and size of the source image on the canvas.
        jobId:
          type: string
          format: uuid
          description: ID of the original task (the `job_id` returned when it was created).
        mask:
          $ref: '#/components/schemas/OfficialMask'
          description: >-
            Optional mask (url max 1024 chars, or areas with width/height
            500-4096).
        remixPrompt:
          type: string
          description: >-
            Prompt guiding the edit (1-8192 characters). Midjourney --flags are
            accepted.
          minLength: 1
          maxLength: 8192
      required:
        - jobId
        - imageNo
        - canvas
        - imgPos
        - remixPrompt
    TaskResponse:
      type: object
      properties:
        config:
          $ref: '#/components/schemas/TaskConfig'
        detail:
          type: 'null'
          description: Reserved for future use; currently null in public API responses.
        error:
          $ref: '#/components/schemas/TaskError'
        input:
          type: object
          description: >-
            Echo of the task's input parameters (shape depends on `task_type`;
            mirrors the create-request body of the operation that created the
            task). Null in error responses.
        job_id:
          type: string
          format: uuid
          description: >-
            Task UUID. Pass it to GET /v1/job/{job_id} to poll, or reference it
            as `jobId` in follow-up operations.
        logs:
          type: array
          description: Operational log lines of the task (progress events, retries).
          items:
            type: string
        meta:
          description: Timestamps and billing usage of the task (null in error responses).
          oneOf:
            - $ref: '#/components/schemas/TaskMeta'
            - type: 'null'
        model:
          type: string
          description: Model family that executed the task.
          enum:
            - midjourney
        output:
          description: >-
            Task result, present once status is `completed` (null before that).
            Image/video tasks return URLs; describe/shorten tasks return text
            prompts.
          oneOf:
            - $ref: '#/components/schemas/ImageOutput'
            - $ref: '#/components/schemas/VideoOutput'
            - $ref: '#/components/schemas/TextOutput'
            - type: 'null'
        status:
          type: string
          description: >-
            Lifecycle state. Terminal states: `completed`, `failed`. `staged`
            means the task is queued behind the account's concurrency limit;
            `retry` means it is being resubmitted after a transient provider
            error.
          enum:
            - pending
            - staged
            - processing
            - retry
            - completed
            - failed
        task_type:
          type: string
          description: Type of the task — the operation that created it.
          enum:
            - diffusion
            - upscale
            - reroll
            - variation
            - inpaint
            - outpaint
            - pan
            - edit
            - remix
            - enhance
            - upload_paint
            - retexture
            - remove_background
            - shorten
            - describe
            - blend
            - video_diffusion
            - extend_video
            - video_upscale
            - enhance_upscale
      required:
        - job_id
        - model
        - task_type
        - status
        - config
        - input
        - output
        - meta
        - detail
        - logs
        - error
    OfficialCanvas:
      type: object
      properties:
        height:
          type: integer
        width:
          type: integer
      required:
        - width
        - height
    OfficialImagePosition:
      type: object
      properties:
        height:
          type: integer
        width:
          type: integer
        x:
          type: integer
        'y':
          type: integer
      required:
        - width
        - height
        - x
        - 'y'
    OfficialMask:
      type: object
      properties:
        areas:
          type: array
          items:
            $ref: '#/components/schemas/OfficialArea'
        url:
          type: string
      required:
        - url
        - areas
    TaskConfig:
      type: object
      properties:
        service_mode:
          type: string
          description: >-
            Service mode the task runs under. Only `public` is currently
            supported.
          enum:
            - public
        webhook_config:
          $ref: '#/components/schemas/TaskWebhookConfig'
      required:
        - service_mode
        - webhook_config
    TaskError:
      type: object
      properties:
        code:
          type: integer
        detail: {}
        message:
          type: string
        raw_message:
          type: string
      required:
        - code
        - raw_message
        - message
        - detail
    TaskMeta:
      type: object
      properties:
        created_at:
          type: string
          format: date-time
        ended_at:
          type: string
          format: date-time
        started_at:
          type: string
          format: date-time
        usage:
          $ref: '#/components/schemas/TaskUsage'
      required:
        - created_at
        - started_at
        - ended_at
        - usage
    ImageOutput:
      type: object
      properties:
        available_actions:
          type: object
        image_url:
          type: string
        image_urls:
          type: array
          items:
            type: string
        seed:
          type: string
      required:
        - image_url
        - image_urls
        - seed
    VideoOutput:
      type: object
      properties:
        available_actions:
          type: object
        seed:
          type: string
        video_urls:
          type: array
          items:
            type: string
      required:
        - video_urls
        - seed
    TextOutput:
      type: object
      properties:
        description:
          type: string
        finalPrompt:
          type: string
        promptEn:
          type: string
        prompts:
          type: array
          items:
            type: string
      required:
        - promptEn
        - description
        - finalPrompt
        - prompts
    OfficialArea:
      type: object
      properties:
        height:
          type: integer
        points:
          type: array
          items:
            type: integer
        width:
          type: integer
      required:
        - width
        - height
        - points
    TaskWebhookConfig:
      type: object
      properties:
        endpoint:
          type: string
        secret:
          type: string
      required:
        - endpoint
        - secret
    TaskUsage:
      type: object
      properties:
        consume:
          type: integer
        frozen:
          type: integer
        type:
          type: string
          description: Billing unit used for the task.
          enum:
            - credit
            - point
      required:
        - type
        - frozen
        - consume
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        API key from the Legnext dashboard. `Authorization: Bearer <key>` is
        accepted as an alternative.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.