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

# Cancel Edit

Cancel an in-flight background `Edit` run (one created with `background: true`). Cancellation is idempotent: a run that has already reached a terminal state (`completed`, `failed`, or `cancelled`) is returned unchanged rather than erroring.

<RequestExample>
  ```python Python theme={null}
  from retab import Retab

  client = Retab()

  edit = client.edits.create_edit_cancel("edt_01G34H8J2K")
  print(edit.status)
  ```

  ```typescript TypeScript theme={null}
  import { Retab } from "@retab/node";

  const client = new Retab({ apiKey: process.env.RETAB_API_KEY });

  const edit = await client.edits.create_edit_cancel("edt_01G34H8J2K");
  console.log(edit.status);
  ```

  ```go Go theme={null}
  package main

  import (
  	"context"
  	"fmt"
  	"log"

  	retab "github.com/retab-dev/retab/clients/go"
  )

  func main() {
  	client, err := retab.NewClient("")
  	if err != nil {
  		log.Fatal(err)
  	}

  	edit, err := client.Edits.CreateCancel(context.Background(), "edt_01G34H8J2K")
  	if err != nil {
  		log.Fatal(err)
  	}

  	fmt.Println(edit.Status)
  }
  ```

  ```java Java theme={null}
  import com.retab.RetabClient;

  public final class Example {
    public static void main(String[] args) throws Exception {
      RetabClient client = new RetabClient(System.getenv("RETAB_API_KEY"));

      var edit = client.edits().createCancel("edt_01G34H8J2K");
      System.out.println(edit.getStatus());
    }
  }
  ```

  ```ruby Ruby theme={null}
  require 'retab'

  client = Retab::Client.new(api_key: ENV['RETAB_API_KEY'])

  edit = client.edits.create_edit_cancel(edit_id: 'edt_01G34H8J2K')
  puts edit.status
  ```

  ```rust Rust theme={null}
  use retab::Retab;

  #[tokio::main]
  async fn main() -> Result<(), Box<dyn std::error::Error>> {
      let client = Retab::new(std::env::var("RETAB_API_KEY")?);

      let edit = client.edits().create_edit_cancel("edt_01G34H8J2K").await?;
      println!("{:?}", edit.status);
      Ok(())
  }
  ```

  ```php PHP theme={null}
  <?php
  require 'vendor/autoload.php';

  use Retab\Client;

  $client = new Client(apiKey: getenv('RETAB_API_KEY'));

  $edit = $client->edits()->createEditCancel('edt_01G34H8J2K');
  echo $edit->status?->value . PHP_EOL;
  ```

  ```csharp C# theme={null}
  using Retab;
  using RetabClient = Retab.Retab;

  var apiKey = Environment.GetEnvironmentVariable("RETAB_API_KEY")!;
  var client = new RetabClient(apiKey);

  var edit = await client.Edits.CreateCancelAsync("edt_01G34H8J2K");
  Console.WriteLine(edit.Status);
  ```

  ```curl cURL theme={null}
  curl -X POST \
    'https://api.retab.com/v1/edits/edt_01G34H8J2K/cancel' \
    -H "Authorization: Bearer $RETAB_API_KEY"
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "edt_01G34H8J2K",
    "status": "cancelled",
    "error": null
  }
  ```

  ```json 404 theme={null}
  {
    "detail": "edit 'edt_01G34H8J2K' not found"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml POST /v1/edits/{edit_id}/cancel
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.retab.com
security: []
paths:
  /v1/edits/{edit_id}/cancel:
    post:
      tags:
        - Edits
      summary: Cancel Edit
      operationId: cancel_edit
      parameters:
        - in: path
          name: edit_id
          required: true
          schema:
            type: string
            title: Edit Id
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Edit'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    Edit:
      properties:
        id:
          type: string
          title: Id
          description: Unique identifier of the edit.
        file:
          $ref: '#/components/schemas/FileRef'
          description: Information about the source file (input document or template PDF).
        model:
          type: string
          title: Model
          description: Model used for the edit operation.
        instructions:
          anyOf:
            - type: string
            - type: 'null'
          title: Instructions
          description: Free-form instructions supplied with the edit request.
        config:
          $ref: '#/components/schemas/EditConfig'
          description: Configuration used for the edit operation.
        template_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Template Id
          description: >-
            Template id used when the edit was created from a template; null for
            direct-document edits.
        output:
          $ref: '#/components/schemas/EditResult'
          description: >-
            The edit result: filled form fields and the rendered PDF. An empty
            sentinel until status == 'completed'; gate reads on status.
        status:
          type: string
          enum:
            - pending
            - queued
            - in_progress
            - completed
            - failed
            - cancelled
          title: Status
          description: >-
            Lifecycle status. The synchronous path returns 'completed'.
            Background runs progress pending -> queued -> in_progress ->
            completed | failed | cancelled.
          default: pending
        error:
          anyOf:
            - $ref: '#/components/schemas/PrimitiveError'
            - type: 'null'
          description: >-
            Error details when a background run fails; null otherwise. Always
            present so consumers can read it without an existence check.
        filled_document_ref:
          anyOf:
            - $ref: '#/components/schemas/FileRef'
            - type: 'null'
          description: Durable file reference for the filled document, when materialized.
        usage:
          anyOf:
            - $ref: '#/components/schemas/RetabUsage'
            - type: 'null'
          description: Usage information for the edit operation.
        created_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Created At
      type: object
      required:
        - config
        - file
        - id
        - model
      title: Edit
      description: >-
        An edit result: form-field values written onto a document or template
        PDF.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
          default: []
      type: object
      title: HTTPValidationError
    FileRef:
      properties:
        id:
          type: string
          title: Id
          description: ID of the file
        filename:
          type: string
          title: Filename
          description: Filename of the file
        mime_type:
          type: string
          title: Mime Type
          description: MIME type of the file
      type: object
      required:
        - filename
        - id
        - mime_type
      title: FileRef
      description: Public/shared file reference used across SDK and customer-facing APIs.
    EditConfig:
      properties:
        color:
          anyOf:
            - type: string
            - type: 'null'
          title: Color
          description: Hex code of the color to use for the filled text.
          default: '#000080'
      type: object
      title: EditConfig
    EditResult:
      properties:
        form_data:
          items:
            $ref: '#/components/schemas/FormField'
          type: array
          title: Form Data
          description: Filled form fields (positions, descriptions, and filled values).
        filled_document:
          $ref: '#/components/schemas/MIMEData'
          description: PDF with the filled form values rendered in.
      type: object
      required:
        - filled_document
        - form_data
      title: EditResult
    PrimitiveError:
      properties:
        code:
          type: string
          title: Code
          description: Machine-readable error code.
        message:
          type: string
          title: Message
          description: Human-readable error message.
        details:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Details
          description: Optional structured error context.
      type: object
      required:
        - code
        - message
      title: PrimitiveError
    RetabUsage:
      properties:
        credits:
          type: number
          title: Credits
          description: Credits consumed for processing
      type: object
      required:
        - credits
      title: RetabUsage
      description: Usage information for document processing.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
          default: null
        ctx:
          type: object
          title: Context
          default: {}
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    FormField:
      properties:
        bbox:
          $ref: '#/components/schemas/BBox'
          description: Position and size of this field on the page.
        description:
          type: string
          title: Description
          description: >-
            Human-readable description of the field, including label and
            instructions.
        type:
          $ref: '#/components/schemas/FieldType'
          description: 'Type of field. Currently supported: ''text'' and ''checkbox''.'
        key:
          type: string
          title: Key
          description: Stable key identifying the field in the form data.
        value:
          anyOf:
            - type: string
            - type: 'null'
          title: Value
          description: Filled value of the field as text. Null when no filled value is set.
      type: object
      required:
        - bbox
        - description
        - key
        - type
      title: FormField
    MIMEData:
      properties:
        filename:
          type: string
          title: Filename
          description: The filename of the file
          examples:
            - file.pdf
            - image.png
            - data.txt
        url:
          type: string
          title: Url
          description: The URL of the file in base64 format
          examples:
            - data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA...
      additionalProperties: false
      type: object
      required:
        - filename
        - url
      title: MIMEData
      description: A file represented by its `filename` and a base64 data `url`.
    BBox:
      properties:
        left:
          type: number
          title: Left
          description: >-
            Left coordinate of the bounding box, relative to page width (0.0 =
            left edge, 1.0 = right edge).
        top:
          type: number
          title: Top
          description: >-
            Top coordinate of the bounding box, relative to page height (0.0 =
            top edge, 1.0 = bottom edge).
        width:
          type: number
          title: Width
          description: Width of the bounding box, relative to page width (0.0–1.0).
        height:
          type: number
          title: Height
          description: Height of the bounding box, relative to page height (0.0–1.0).
        page:
          type: integer
          title: Page
          description: 1-based index of the page where this field appears.
      type: object
      required:
        - height
        - left
        - page
        - top
        - width
      title: BBox
    FieldType:
      type: string
      enum:
        - text
        - checkbox
      title: FieldType
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````