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

# Create Split

> Create a split.

Divides a `document` into the named `subdocuments`, assigning each its set of pages,
using the chosen `model` and optional `instructions`. Set `n_consensus` above `1` to
run multiple votes and consolidate them. Returns the stored `Split` with its `output`
page assignments, and responds with `201`.

Split a multi-page document into labeled subdocuments and return the canonical split resource. This endpoint is split-only: key-based grouping belongs to [`/v1/partitions`](/api-reference/partitions/create).

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

  client = Retab()

  document = MIMEData(
      filename="invoice_batch.pdf",
      url="https://my-bucket.s3.us-east-1.amazonaws.com/documents/invoice_batch.pdf",
  )

  split = client.splits.create(
      document=document,
      model="retab-small",
      subdocuments=[
          {
              "name": "invoice",
              "description": "Invoice documents with billing information",
              "allow_multiple_instances": True,
          },
          {"name": "receipt", "description": "Receipt documents for payments"},
          {"name": "contract", "description": "Legal contract documents"},
      ],
      instructions="Processing Q4 2024 vendor document batch",
      n_consensus=3,
      bust_cache=False,
  )

  for sub in split.output:
      print(f"{sub.name}: pages {sub.pages}")
  ```

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

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

  const document = {
    filename: "invoice_batch.pdf",
    url: "https://my-bucket.s3.us-east-1.amazonaws.com/documents/invoice_batch.pdf",
  };

  const split = await client.splits.create(document, [
      {
        name: "invoice",
        description: "Invoice documents with billing information",
        allowMultipleInstances: true,
      },
      { name: "receipt", description: "Receipt documents for payments" },
      { name: "contract", description: "Legal contract documents" },
    ], "retab-small", "Processing Q4 2024 vendor document batch", 3, false);

  split.output.forEach((sub) => {
    console.log(`${sub.name}: pages ${sub.pages}`);
  });
  ```

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

  import (
  	"context"
  	"fmt"
  	"log"

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

  func ptr[T any](v T) *T { return &v }

  func main() {
  	ctx := context.Background()

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

  	document := retab.MIMEData{
  		Filename: "invoice_batch.pdf",
  		URL:      "https://my-bucket.s3.us-east-1.amazonaws.com/documents/invoice_batch.pdf",
  	}

  	split, err := client.Splits.Create(ctx, &retab.SplitsCreateParams{
  		Document: document,
  		Model:    ptr("retab-small"),
  		Subdocuments: []*retab.Subdocument{
  			{Name: "invoice", Description: ptr("Invoice documents with billing information"), AllowMultipleInstances: ptr(true)},
  			{Name: "receipt", Description: ptr("Receipt documents for payments")},
  			{Name: "contract", Description: ptr("Legal contract documents")},
  		},
  		Instructions: ptr("Processing Q4 2024 vendor document batch"),
  		NConsensus:   ptr(3),
  		BustCache:    ptr(false),
  	})
  	if err != nil {
  		log.Fatal(err)
  	}

  	for _, sub := range split.Output {
  		fmt.Printf("%s: pages %v\n", sub.Name, sub.Pages)
  	}
  }
  ```

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

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

  document = {
    filename: 'invoice_batch.pdf',
    url: 'https://my-bucket.s3.us-east-1.amazonaws.com/documents/invoice_batch.pdf',
  }

  split = client.splits.create(
    document: document,
    model: 'retab-small',
    subdocuments: [
      {
        'name' => 'invoice',
        'description' => 'Invoice documents with billing information',
        'allow_multiple_instances' => true,
      },
      { 'name' => 'receipt', 'description' => 'Receipt documents for payments' },
      { 'name' => 'contract', 'description' => 'Legal contract documents' },
    ],
    instructions: 'Processing Q4 2024 vendor document batch',
    n_consensus: 3,
    bust_cache: false,
  )

  split.output.each do |sub|
    puts "#{sub.name}: pages #{sub.pages}"
  end
  ```

  ```rust Rust theme={null}
  use retab::models::Subdocument;
  use retab::resources::splits::CreateParams;
  use retab::{MimeData, Retab};

  #[tokio::main]
  async fn main() -> Result<(), Box<dyn std::error::Error>> {
      let client = Retab::new(std::env::var("RETAB_API_KEY")?);
      let document = MimeData::new(
          "invoice_batch.pdf",
          "https://my-bucket.s3.us-east-1.amazonaws.com/documents/invoice_batch.pdf",
      );

      let subdocuments = vec![
          Subdocument {
              name: "invoice".into(),
              description: Some("Invoice documents with billing information".into()),
              allow_multiple_instances: Some(true),
          },
          Subdocument {
              name: "receipt".into(),
              description: Some("Receipt documents for payments".into()),
              allow_multiple_instances: None,
          },
          Subdocument {
              name: "contract".into(),
              description: Some("Legal contract documents".into()),
              allow_multiple_instances: None,
          },
      ];

      let mut params = CreateParams::new(document, subdocuments);
      params.body.model = Some("retab-small".into());
      params.body.instructions = Some("Processing Q4 2024 vendor document batch".into());
      params.body.n_consensus = Some(3);
      params.body.bust_cache = Some(false);

      let split = client.splits().create(params).await?;

      for sub in split.output.as_ref().unwrap() {
          println!("{}: pages {:?}", sub.name, sub.pages);
      }
      Ok(())
  }
  ```

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

  use Retab\Client;

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

  $result = $client->splits()->create(
      document: [
          'filename' => 'invoice_batch.pdf',
          'url' => 'https://my-bucket.s3.us-east-1.amazonaws.com/documents/invoice_batch.pdf',
      ],
      subdocuments: [['name' => 'invoice', 'description' => 'Invoice documents']],
  );
  print_r($result);
  ```

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

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

  var document = MimeData.FromUrl(
      new Uri("https://my-bucket.s3.us-east-1.amazonaws.com/documents/invoice_batch.pdf"));

  var result = await client.Splits.CreateAsync(new SplitsCreateOptions
  {
      Document = document,
      Model = "retab-small",
      Subdocuments = new List<Subdocument>
      {
          new Subdocument
          {
              Name = "invoice",
              Description = "Invoice documents with billing information",
              AllowMultipleInstances = true,
          },
          new Subdocument { Name = "receipt", Description = "Receipt documents for payments" },
          new Subdocument { Name = "contract", Description = "Legal contract documents" },
      },
      Instructions = "Processing Q4 2024 vendor document batch",
      NConsensus = 3,
      BustCache = false,
  });

  Console.WriteLine(result);
  ```

  ```java Java theme={null}
  import com.retab.RetabClient;
  import com.retab.models.MimeData;
  import com.retab.models.Subdocument;
  import java.net.URI;
  import java.util.List;

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

      MimeData document = MimeData.fromUrl(
          URI.create("https://my-bucket.s3.us-east-1.amazonaws.com/documents/invoice_batch.pdf"));

      List<Subdocument> subdocuments = List.of(
          new Subdocument("invoice", "Invoice documents with billing information", true),
          new Subdocument("receipt", "Receipt documents for payments", null),
          new Subdocument("contract", "Legal contract documents", null));

      var result = client.splits().create(
          document,
          subdocuments,
          "retab-small",
          "Processing Q4 2024 vendor document batch",
          3L,
          false,
          null);
      System.out.println(result);
    }
  }
  ```

  ```curl cURL theme={null}
  curl -X POST \
    'https://api.retab.com/v1/splits' \
    -H "Authorization: Bearer $RETAB_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
    "document": {
      "filename": "invoice_batch.pdf",
      "url": "https://my-bucket.s3.us-east-1.amazonaws.com/documents/invoice_batch.pdf"
    },
    "model": "retab-small",
    "subdocuments": [
      {
        "name": "invoice",
        "description": "Invoice documents with billing information",
        "allow_multiple_instances": true
      },
      {
        "name": "receipt",
        "description": "Receipt documents for payments"
      },
      {
        "name": "contract",
        "description": "Legal contract documents"
      }
    ],
    "instructions": "Processing Q4 2024 vendor document batch",
    "n_consensus": 3,
    "bust_cache": false
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "split_01G34H8J2K",
    "file": {
      "id": "file_6dd6eb00688ad8d1",
      "filename": "invoice_batch.pdf",
      "mime_type": "application/pdf"
    },
    "model": "retab-small",
    "subdocuments": [
      {
        "name": "invoice",
        "description": "Invoice documents with billing information",
        "allow_multiple_instances": true
      },
      {
        "name": "receipt",
        "description": "Receipt documents for payments",
        "allow_multiple_instances": false
      }
    ],
    "n_consensus": 3,
    "instructions": "Processing Q4 2024 vendor document batch",
    "output": [
      { "name": "invoice", "pages": [1, 2, 3] },
      { "name": "invoice", "pages": [4, 5] },
      { "name": "receipt", "pages": [6] }
    ],
    "consensus": {
      "likelihoods": [
        { "name": 0.98, "pages": [0.99, 0.97, 0.96] },
        { "name": 0.95, "pages": [0.95, 0.93] },
        { "name": 0.99, "pages": [0.99] }
      ],
      "choices": [
        [
          { "name": "invoice", "pages": [1, 2, 3] },
          { "name": "invoice", "pages": [4, 5] },
          { "name": "receipt", "pages": [6] }
        ],
        [
          { "name": "invoice", "pages": [1, 2] },
          { "name": "invoice", "pages": [3, 4, 5] },
          { "name": "receipt", "pages": [6] }
        ],
        [
          { "name": "invoice", "pages": [1, 2, 3] },
          { "name": "invoice", "pages": [4, 5] },
          { "name": "receipt", "pages": [6] }
        ]
      ]
    },
    "usage": {
      "credits": 3.0
    },
    "created_at": "2024-03-15T10:30:00Z"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml POST /v1/splits
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.retab.com
security: []
paths:
  /v1/splits:
    post:
      tags:
        - Splits
      summary: Create Split
      description: >-
        Create a split.


        Divides a `document` into the named `subdocuments`, assigning each its
        set of pages,

        using the chosen `model` and optional `instructions`. Set `n_consensus`
        above `1` to

        run multiple votes and consolidate them. Returns the stored `Split` with
        its `output`

        page assignments, and responds with `201`.
      operationId: create_split
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSplitRequest'
        required: true
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Split'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    CreateSplitRequest:
      properties:
        document:
          $ref: '#/components/schemas/MIMEData'
          description: The document to split
        subdocuments:
          items:
            $ref: '#/components/schemas/Subdocument'
          type: array
          title: Subdocuments
          description: The subdocuments to split the document into
        model:
          type: string
          title: Model
          description: The model to use to split the document
          default: retab-small
        instructions:
          anyOf:
            - type: string
            - type: 'null'
          title: Instructions
          description: >-
            Free-form instructions appended to the system prompt to steer the
            split.
        n_consensus:
          type: integer
          title: N Consensus
          description: >-
            Number of consensus split runs to perform. Uses deterministic
            single-pass when set to 1.
          default: 1
        bust_cache:
          type: boolean
          title: Bust Cache
          description: If true, skip the LLM cache and force a fresh completion
          default: false
        background:
          type: boolean
          title: Background
          description: >-
            If true, run asynchronously: returns immediately with status
            'queued' and an empty output. Poll GET /v1/<primitive>/{id} until
            status is terminal. Mutually exclusive with stream.
          default: false
      type: object
      required:
        - document
        - subdocuments
      title: CreateSplitRequest
      description: Request body to create a split.
    Split:
      properties:
        id:
          type: string
          title: Id
          description: Unique identifier of the split result
        file:
          $ref: '#/components/schemas/FileRef'
          description: Information about the split file
        model:
          type: string
          title: Model
          description: Model used for the split operation
        subdocuments:
          items:
            $ref: '#/components/schemas/Subdocument'
          type: array
          title: Subdocuments
          description: Subdocuments used for the split operation
        n_consensus:
          type: integer
          title: N Consensus
          description: Number of consensus votes used
          default: 1
        instructions:
          anyOf:
            - type: string
            - type: 'null'
          title: Instructions
          description: Free-form instructions supplied with the split request.
        output:
          items:
            $ref: '#/components/schemas/SplitResult'
          type: array
          title: Output
          description: >-
            The list of document splits 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/SplitConsensus'
            - type: 'null'
          description: Consensus metadata for multi-vote split runs
        usage:
          anyOf:
            - $ref: '#/components/schemas/RetabUsage'
            - type: 'null'
          description: Usage information for the split operation
        created_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Created At
      type: object
      required:
        - file
        - id
        - model
        - subdocuments
      title: Split
      description: 'A split result: a document divided into its constituent `subdocuments`.'
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
          default: []
      type: object
      title: HTTPValidationError
    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`.
    Subdocument:
      properties:
        name:
          type: string
          title: Name
          description: The name of the subdocument
        description:
          type: string
          title: Description
          description: The description of the subdocument
          default: ''
        allow_multiple_instances:
          type: boolean
          title: Allow Multiple Instances
          description: >-
            When true, this subdocument type can appear more than once in the
            document — the split will identify each distinct instance (runs an
            extra vision-based refinement pass).
          default: false
      type: object
      required:
        - name
      title: Subdocument
    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.
    SplitResult:
      properties:
        name:
          type: string
          title: Name
          description: The name of the subdocument
        pages:
          items:
            type: integer
          type: array
          title: Pages
          description: The pages of the subdocument (1-indexed)
        regions:
          items:
            $ref: '#/components/schemas/SheetRegion'
          type: array
          title: Regions
          default: []
      type: object
      required:
        - name
        - pages
      title: SplitResult
    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
    SplitConsensus:
      properties:
        likelihoods:
          items:
            $ref: '#/components/schemas/SplitSubdocumentLikelihood'
          type: array
          title: Likelihoods
          description: Consensus likelihood tree mirroring the split output
          default: []
        choices:
          items:
            items:
              $ref: '#/components/schemas/SplitResult'
            type: array
          type: array
          title: Choices
          description: Alternative split vote outputs used to build the consolidated result
          default: []
      type: object
      title: SplitConsensus
    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
    SheetRegion:
      properties:
        col_end:
          anyOf:
            - type: integer
            - type: 'null'
          title: Col End
        col_start:
          anyOf:
            - type: integer
            - type: 'null'
          title: Col Start
        header_rows:
          items:
            type: integer
          type: array
          title: Header Rows
          default: []
        row_end:
          type: integer
          title: Row End
        row_start:
          type: integer
          title: Row Start
        sheet_index:
          type: integer
          title: Sheet Index
        sheet_name:
          type: string
          title: Sheet Name
      type: object
      required:
        - row_end
        - row_start
        - sheet_index
        - sheet_name
      title: SheetRegion
    SplitSubdocumentLikelihood:
      properties:
        name:
          anyOf:
            - type: number
            - type: 'null'
          title: Name
          description: Confidence that this split label is correct
        pages:
          items:
            type: number
          type: array
          title: Pages
          description: Confidence for each page in the corresponding split.pages array
          default: []
      type: object
      title: SplitSubdocumentLikelihood
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````