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

# Batch Create Sessions

> Create multiple sessions with uploaded documents and optional auto-extraction.

## Authentication & Scope

Requires the `sessions-write` ability.

## Overview

This endpoint creates one session per uploaded file, with each session containing the corresponding document. This is the most efficient way to process multiple documents.

<Tip>
  Enable `auto_extract` to automatically start extraction after document parsing completes. This eliminates the need to call the execute endpoint separately.
</Tip>

## Request

```http theme={null}
POST /extractions/templates/550e8400-e29b-41d4-a716-446655440000/sessions/batch HTTP/1.1
Host: api.raydocs.com
Authorization: Bearer <token>
Content-Type: application/json

{
  "files": [
    "tmp/abc123-invoice1.pdf",
    "tmp/def456-invoice2.pdf",
    "tmp/ghi789-invoice3.pdf"
  ],
  "settings": {
    "auto_extract": true
  }
}
```

### Path Parameters

| Parameter    | Type | Required | Description                           |
| ------------ | ---- | -------- | ------------------------------------- |
| `templateId` | uuid | Yes      | The template ID to use for extraction |

### Body Parameters

| Parameter               | Type    | Required | Description                                                                            |
| ----------------------- | ------- | -------- | -------------------------------------------------------------------------------------- |
| `files`                 | array   | Yes      | Array of file keys from signed URL uploads (max 50)                                    |
| `settings`              | object  | No       | Session settings                                                                       |
| `settings.auto_extract` | boolean | No       | When `true`, extraction starts automatically after document parsing (default: `false`) |

<Note>
  File keys are obtained from the [signed URL upload](/guides/uploading-documents) process. Each file creates a separate session.
</Note>

## Response

`201 Created` – Array of created sessions.

```json theme={null}
[
  {
    "id": "770e8400-e29b-41d4-a716-446655440001",
    "name": "Pending...",
    "created_at": "2024-01-15T10:30:00Z"
  },
  {
    "id": "770e8400-e29b-41d4-a716-446655440002",
    "name": "Pending...",
    "created_at": "2024-01-15T10:30:01Z"
  },
  {
    "id": "770e8400-e29b-41d4-a716-446655440003",
    "name": "Pending...",
    "created_at": "2024-01-15T10:30:02Z"
  }
]
```

<Note>
  Session names initially show "Pending..." and are automatically updated to the document filename once processing begins.
</Note>

## Auto-Extract Workflow

When `auto_extract: true`:

1. Sessions are created with uploaded documents
2. Documents are automatically parsed into searchable chunks
3. Once parsing completes, extraction starts automatically
4. Results appear in the session's results endpoint

```mermaid theme={null}
graph LR
    A[Batch Create] --> B[Document Parsing]
    B --> C[Auto-Extract Triggered]
    C --> D[Results Available]
```

<Warning>
  With auto-extract enabled, you don't need to call the [Batch Execute](/api-reference/sessions/batch-execute) endpoint. Doing so would create duplicate extraction jobs.
</Warning>

## Example: Complete Workflow

<Steps>
  <Step title="Upload files and get keys">
    Use [signed URLs](/guides/uploading-documents) to upload your documents first.
  </Step>

  <Step title="Batch create with auto-extract">
    ```bash theme={null}
    curl -X POST "https://api.raydocs.com/extractions/templates/{templateId}/sessions/batch" \
      -H "Authorization: Bearer <token>" \
      -H "Content-Type: application/json" \
      -d '{
        "files": ["tmp/file1.pdf", "tmp/file2.pdf"],
        "settings": { "auto_extract": true }
      }'
    ```
  </Step>

  <Step title="Poll for results">
    Check each session's results endpoint until status is `completed`.

    ```bash theme={null}
    curl "https://api.raydocs.com/extractions/sessions/{sessionId}/results" \
      -H "Authorization: Bearer <token>"
    ```
  </Step>
</Steps>

## Error Responses

| Status | Description                                                 |
| ------ | ----------------------------------------------------------- |
| 403    | Token lacks `sessions-write` ability                        |
| 404    | Template not found                                          |
| 422    | Validation error (invalid file keys, exceeds 50 file limit) |


## OpenAPI

````yaml post /extractions/templates/{templateId}/sessions/batch
openapi: 3.0.1
info:
  title: Raydocs API
  description: REST API for document extraction with AI-powered data parsing
  version: 1.0.0
servers:
  - url: https://api.raydocs.com
security:
  - bearerAuth: []
tags:
  - name: Workspaces
    description: Create and manage workspaces.
  - name: Workspace Users
    description: Manage users within a workspace.
  - name: Extraction Templates
    description: Define extraction schemas and settings.
  - name: Extraction Sessions
    description: Manage extraction jobs and documents.
  - name: Batch Operations
    description: Bulk operations on sessions.
  - name: Documents
    description: Upload and manage source documents.
  - name: Workflows
    description: Discover workflow runs and read their public outputs.
  - name: Results
    description: Access extraction results.
paths:
  /extractions/templates/{templateId}/sessions/batch:
    post:
      tags:
        - Batch Operations
      summary: Batch Create Sessions
      description: >-
        Create sessions from uploaded files with optional auto-extraction. Each
        file creates one session. Requires `sessions-write`.
      operationId: batchCreateSessions
      parameters:
        - name: templateId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - files
              properties:
                files:
                  type: array
                  maxItems: 50
                  description: Array of file keys from signed URL uploads
                  items:
                    type: string
                  example:
                    - tmp/abc123-invoice.pdf
                    - tmp/def456-invoice.pdf
                settings:
                  type: object
                  properties:
                    auto_extract:
                      type: boolean
                      default: false
                      description: >-
                        When true, extraction starts automatically after
                        document parsing
      responses:
        '201':
          description: Sessions created
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: string
                      format: uuid
                    name:
                      type: string
                      example: Pending...
                    created_at:
                      type: string
                      format: date-time
        '403':
          description: Forbidden
        '422':
          description: Validation error (invalid file keys or exceeds 50 file limit)
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        Personal Access Token created from the Raydocs dashboard.

        Include in the Authorization header: `Bearer <your_token>`

        See [API Keys](/api-reference/api-keys) for token creation and
        management.

````