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

# Batch Mode

> Async document processing — 40% cheaper than standard API

<Tabs sync={false}>
  <Tab title="EN">
    ## Overview

    Batch mode processes files from Google Drive in the background — **40% cheaper** than the standard API. Ideal for large document archives.

    | | Standard API | Batch Mode |
    | - | - | - |
    | Response | Synchronous (streaming) | Async (polling) |
    | Price | 100% | **60% (40% discount)** |
    | Input | Per-request | Bulk submit or Google Drive folder |
    | Output | Response body | JSON result or written back to Drive |

    **Supported file types:** PNG · JPG · TIFF · WebP · PDF · TXT · MD · JSON · CSV · Excel

    ## Quick Start

    ### 1. Submit a job

    ```python theme={null}
    import httpx

    resp = httpx.post(
        "https://app.lapathoniia.top/batch/jobs",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={
            "job_type": "chat",
            "model": "MamayLM-Gemma-3-27B-IT-v2.0",
            "input": "Summarise the following: ...",
        },
    )
    job_id = resp.json()["job_id"]
    ```

    ### 2. Poll for result

    ```python theme={null}
    import time

    while True:
        status = httpx.get(
            f"https://app.lapathoniia.top/batch/jobs/{job_id}",
            headers={"Authorization": "Bearer YOUR_API_KEY"},
        ).json()
        if status["status"] == "done":
            print(status["result"]["content"])
            break
        time.sleep(5)
    ```

    ## Batch JSON List

    Submit a single JSON file with an array of prompts — each item is processed as a separate job. Ideal for bulk translation, mass processing, batch analysis.

    ```json theme={null}
    [
      {"text": "Chapter 1: One morning Gregor Samsa..."},
      {"text": "Chapter 2: His sister brought food daily..."},
      {"text": "Chapter 3: Their father no longer felt shame..."}
    ]
    ```

    Extended format with metadata:

    ```json theme={null}
    [
      {
        "id": "page_1",
        "text": "Page text...",
        "system": "Translate to Polish."
      },
      {
        "id": "page_2",
        "text": "Next page text...",
        "system": "Translate to Polish."
      }
    ]
    ```

    | Field | Required | Description |
    | - | - | - |
    | `text` | ✅ | The prompt text for the LLM |
    | `id` | — | Identifier for finding results |
    | `system` | — | System prompt for this item. Falls back to the instruction from the submit form |

    <Note>
      Limit: 1000 items per file. Each item goes through the 24K character check. In the UI each item appears as a separate job named `file.json [1/300]`.
    </Note>

    ## OCR Pipeline

    Combine OCR with LLM post-processing:

    ```python theme={null}
    resp = httpx.post(
        "https://app.lapathoniia.top/batch/jobs",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={
            "job_type": "ocr",
            "drive": {"file_id": "YOUR_DRIVE_FILE_ID"},
            "pipeline": "ocr_then_chat",
            "pipeline_instruction": "Extract: date, signatories, amounts. Return JSON.",
            "pipeline_model": "MamayLM-Gemma-3-27B-IT-v2.0",
        },
    )
    ```

    ## Google Drive Integration

    ```python theme={null}
    resp = httpx.post(
        "https://app.lapathoniia.top/batch/jobs",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={
            "job_type": "auto",
            "drive": {"folder_id": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs"},
            "pipeline": "ocr_then_chat",
            "pipeline_instruction": "Translate to modern Ukrainian",
            "pipeline_model": "MamayLM-Gemma-3-27B-IT-v2.0",
        },
    )
    ```

    Share your Drive folder with: `batch-worker@lapathoniia-prod.iam.gserviceaccount.com` (Editor)

    ## File Limits

    | Limit | Value | Behaviour |
    | - | - | - |
    | File size | 50 MB | File skipped with error |
    | PDF/TIFF pages | 50 pages max | First 50 processed, rest ignored |
    | Image resolution | 4 MP (≈2048×2048) | Auto-downscaled preserving aspect ratio |
    | Text (TXT/CSV/Excel) | 24,000 characters | Truncated at sentence boundary with notice |
    | OCR tokens per page | 12,000 | Dense pages may be cut off |
    | Files per folder | Unlimited | 100 files per Drive API page, auto-paginated |

    <Note>
      Multi-page PDFs and TIFFs are processed page by page. Each region in the result has a `page` field. The OCR quota (4 images/hour) applies **per page**.
    </Note>

    ## 40% Discount

    All batch mode requests automatically get a 40% discount. Applied hourly. View usage: **Usage → Batch mode** section in the dashboard.
  </Tab>

  <Tab title="UA">
    ## Overview

    Batch mode обробляє файли з Google Drive у фоні — на **40% дешевше** за стандартний API. Ідеально для великих архівів документів.

    | | Стандартний API | Batch Mode |
    | - | - | - |
    | Відповідь | Синхронний (streaming) | Async (polling) |
    | Ціна | 100% | **60% (знижка 40%)** |
    | Введення | Один запит | Bulk submit або папка Google Drive |
    | Виведення | В тілі відповіді | JSON або запис у Drive |

    **Підтримувані формати:** PNG · JPG · TIFF · WebP · PDF · TXT · MD · JSON · CSV · Excel

    ## Quick Start

    ### 1. Відправте завдання

    ```python theme={null}
    import httpx

    resp = httpx.post(
        "https://app.lapathoniia.top/batch/jobs",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={
            "job_type": "chat",
            "model": "MamayLM-Gemma-3-27B-IT-v2.0",
            "input": "Підсумуй наступне: ...",
        },
    )
    job_id = resp.json()["job_id"]
    ```

    ### 2. Перевірте результат

    ```python theme={null}
    import time

    while True:
        status = httpx.get(
            f"https://app.lapathoniia.top/batch/jobs/{job_id}",
            headers={"Authorization": "Bearer YOUR_API_KEY"},
        ).json()
        if status["status"] == "done":
            print(status["result"]["content"])
            break
        time.sleep(5)
    ```

    ## Batch JSON List

    Завантажте один JSON-файл з масивом промптів — кожен елемент обробляється як окремий запит. Ідеально для перекладу книг, масової обробки, пакетних аналізів.

    ```json theme={null}
    [
      {"text": "Розділ 1: Одного ранку Грегор Замза..."},
      {"text": "Розділ 2: Сестра щодня приносила їжу..."},
      {"text": "Розділ 3: Батько вже не соромився..."}
    ]
    ```

    Розширений формат з метаданими:

    ```json theme={null}
    [
      {
        "id": "page_1",
        "text": "Текст сторінки...",
        "system": "Переклади на польську мову."
      }
    ]
    ```

    | Поле | Обов’язкове | Опис |
    | - | - | - |
    | `text` | ✅ | Текст промпту для LLM |
    | `id` | — | Ідентифікатор для пошуку результатів |
    | `system` | — | Системний промпт для цього елемента |

    ## OCR Pipeline

    Комбінуйте OCR з постобробкою LLM:

    ```python theme={null}
    resp = httpx.post(
        "https://app.lapathoniia.top/batch/jobs",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={
            "job_type": "ocr",
            "drive": {"file_id": "YOUR_DRIVE_FILE_ID"},
            "pipeline": "ocr_then_chat",
            "pipeline_instruction": "Витягни: дату, підписантів, суми. Поверни JSON.",
            "pipeline_model": "MamayLM-Gemma-3-27B-IT-v2.0",
        },
    )
    ```

    ## Google Drive Integration

    Поділіться папкою з сервісним акаунтом: `batch-worker@lapathoniia-prod.iam.gserviceaccount.com` (Редактор)

    ```python theme={null}
    resp = httpx.post(
        "https://app.lapathoniia.top/batch/jobs",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        json={
            "job_type": "auto",
            "drive": {"folder_id": "YOUR_FOLDER_ID"},
            "pipeline": "ocr_then_chat",
            "pipeline_instruction": "Переклади на сучасну українську",
            "pipeline_model": "MamayLM-Gemma-3-27B-IT-v2.0",
        },
    )
    ```

    ## File Limits

    | Ліміт | Значення | Що відбувається |
    | - | - | - |
    | Розмір файлу | 50 МБ | Файл пропускається з помилкою |
    | Сторінок PDF/TIFF | 50 стор. (макс) | Перші 50 обробляються, решта ігнорується |
    | Роздільна здатність | 4 МП (≈2048×2048) | Автоматичне масштабування |
    | Текст (TXT/CSV/Excel) | 24 000 символів | Обрізається на межі речення |
    | OCR токени на сторінку | 12 000 | Щільні сторінки можуть обрізатися |
    | Файлів у папці | Необмежено | 100 файлів на сторінку API Drive |

    <Note>
      Квота OCR (4 зображення/год) діє на кожну **сторінку** окремо, не на файл.
    </Note>

    ## 40% Discount

    Всі запити через пакетний режим автоматично отримують знижку 40%. Знижка застосовується щогодини.
  </Tab>
</Tabs>
