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

Cancel an in-flight background `Partition` 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()

  partition = client.partitions.create_partition_cancel("prtn_01G34H8J2K")
  print(partition.status)
  ```

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

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

  const partition = await client.partitions.create_partition_cancel("prtn_01G34H8J2K");
  console.log(partition.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)
  	}

  	partition, err := client.Partitions.CreateCancel(context.Background(), "prtn_01G34H8J2K")
  	if err != nil {
  		log.Fatal(err)
  	}

  	fmt.Println(partition.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 partition = client.partitions().createCancel("prtn_01G34H8J2K");
      System.out.println(partition.getStatus());
    }
  }
  ```

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

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

  partition = client.partitions.create_partition_cancel(partition_id: 'prtn_01G34H8J2K')
  puts partition.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 partition = client.partitions().create_partition_cancel("prtn_01G34H8J2K").await?;
      println!("{:?}", partition.status);
      Ok(())
  }
  ```

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

  use Retab\Client;

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

  $partition = $client->partitions()->createPartitionCancel('prtn_01G34H8J2K');
  echo $partition->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 partition = await client.Partitions.CreateCancelAsync("prtn_01G34H8J2K");
  Console.WriteLine(partition.Status);
  ```

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

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

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


## OpenAPI

````yaml POST /v1/partitions/{partition_id}/cancel
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.retab.com
security: []
paths:
  /v1/partitions/{partition_id}/cancel:
    post:
      tags:
        - Partitions
      summary: Cancel Partition
      operationId: cancel_partition
      parameters:
        - in: path
          name: partition_id
          required: true
          schema:
            type: string
            title: Partition Id
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Partition'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    Partition:
      properties:
        id:
          type: string
          title: Id
          description: Unique identifier of the partition
        file:
          $ref: '#/components/schemas/FileRef'
          description: Information about the partitioned file
        model:
          type: string
          title: Model
          description: Model used for the partition operation
        key:
          type: string
          title: Key
          description: Partition key used for the run
        instructions:
          anyOf:
            - type: string
            - type: 'null'
          title: Instructions
          description: Free-form instructions supplied with the partition request
        n_consensus:
          type: integer
          title: N Consensus
          description: Number of consensus votes used
          default: 1
        allow_overlap:
          type: boolean
          title: Allow Overlap
          description: >-
            Whether pages were allowed to appear in more than one partition
            chunk
          default: true
        output:
          items:
            $ref: '#/components/schemas/PartitionChunk'
          type: array
          title: Output
          description: >-
            The list of partition chunks with their assigned pages. Empty []
            until status == 'completed'.
          default: []
        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.
        consensus:
          anyOf:
            - $ref: '#/components/schemas/PartitionConsensus'
            - type: 'null'
          description: Consensus metadata for multi-vote partition runs
        usage:
          anyOf:
            - $ref: '#/components/schemas/RetabUsage'
            - type: 'null'
          description: Usage information for the partition operation
        created_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Created At
      type: object
      required:
        - file
        - id
        - key
        - model
      title: Partition
      description: >-
        A partition result: a document segmented into chunks along the requested
        `key`.
    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.
    PartitionChunk:
      properties:
        key:
          type: string
          title: Key
          description: The partition key value for this chunk
        pages:
          items:
            type: integer
          type: array
          title: Pages
          description: The pages assigned to this partition chunk (1-indexed)
          default: []
      type: object
      required:
        - key
      title: PartitionChunk
    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
    PartitionConsensus:
      properties:
        choices:
          items:
            items:
              $ref: '#/components/schemas/PartitionChunk'
            type: array
          type: array
          title: Choices
          description: >-
            Alternative partition vote outputs used to build the consolidated
            result.
          default: []
        likelihoods:
          items:
            $ref: '#/components/schemas/PartitionChunkLikelihood'
          type: array
          title: Likelihoods
          description: Consensus likelihoods aligned with the partition output.
          default: []
      type: object
      title: PartitionConsensus
    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
    PartitionChunkLikelihood:
      properties:
        key:
          anyOf:
            - type: number
            - type: 'null'
          title: Key
          description: Confidence that this partition key value is correct
        pages:
          items:
            type: number
          type: array
          title: Pages
          description: >-
            Confidence for each page in the corresponding partition chunk.pages
            array
          default: []
      type: object
      title: PartitionChunkLikelihood
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````