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

# Reprocess Source

> Re-process an existing source with a different partition method using the Graphor SDK (async)

The **`reprocess`** method (same name as the API endpoint) re-runs the ingestion pipeline on an existing source using a different partition method. Processing is **asynchronous**: the method returns a **`build_id`** immediately; poll [Get build status](/sdk/sources/upload#get-build-status) until the job completes.

## Method overview

<Tabs>
  <Tab title="Python">
    <CardGroup cols={2}>
      <Card title="Sync" icon="code">
        **`client.sources.reprocess()`**
      </Card>

      <Card title="Async" icon="code">
        **`await client.sources.reprocess()`**
      </Card>
    </CardGroup>
  </Tab>

  <Tab title="TypeScript">
    **`await client.sources.reprocess()`**
  </Tab>
</Tabs>

## Method signature

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    client.sources.reprocess(
        file_id: str,                           # Required
        method: str | None = None,             # Optional: auto, fast, balanced, accurate, agentic
        timeout: float | None = None
    ) -> SourceReprocessResponse
    ```

    Returns **`SourceReprocessResponse`** with `.build_id`.
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    await client.sources.reprocess({
      file_id: string,                                   // Required
      method?: 'auto' | 'fast' | 'balanced' | 'accurate' | 'agentic',
    }): Promise<SourceReprocessResponse>
    ```

    Returns **`SourceReprocessResponse`** with `.build_id`.
  </Tab>
</Tabs>

## Parameters

<Tabs>
  <Tab title="Python">
    | Parameter | Type          | Description                                                                | Required |
    | --------- | ------------- | -------------------------------------------------------------------------- | -------- |
    | `file_id` | `str`         | Unique identifier of the source to re-process                              | Yes      |
    | `method`  | `str \| None` | One of: `auto`, `fast`, `balanced`, `accurate`, `agentic`. Default: `fast` | No       |
    | `timeout` | `float`       | Request timeout in seconds                                                 | No       |
  </Tab>

  <Tab title="TypeScript">
    | Parameter | Type     | Description                                               | Required |
    | --------- | -------- | --------------------------------------------------------- | -------- |
    | `file_id` | `string` | Unique identifier of the source to re-process             | Yes      |
    | `method`  | `string` | One of: `auto`, `fast`, `balanced`, `accurate`, `agentic` | No       |
  </Tab>
</Tabs>

### Partition method values (v2)

| Value      | Name     | Description                                                                                                                                               |
| ---------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `auto`     | Auto     | Per-page routing: classifies each page and runs the cheapest parser that fits. Best for mixed PDFs (body + tables + scans in one document). **PDF-only.** |
| `fast`     | Fast     | Fast processing with heuristic classification. No OCR.                                                                                                    |
| `balanced` | Balanced | OCR-based extraction with structure classification.                                                                                                       |
| `accurate` | Accurate | Fine-tuned model for highest accuracy (Premium).                                                                                                          |
| `agentic`  | Agentic  | Highest accuracy for complex layouts, tables, and diagrams.                                                                                               |

### Method comparison

| Method       | Speed            | Text parsing      | Element classification | Best use cases                               | OCR         |
| ------------ | ---------------- | ----------------- | ---------------------- | -------------------------------------------- | ----------- |
| **Auto**     | Mixed (per page) | Best for the page | Best for the page      | Mixed PDFs with body + tables + scans        | When needed |
| **Fast**     | High             | Good              | Good                   | Simple text files, testing                   | No          |
| **Balanced** | Medium           | Very good         | Very good              | Complex layouts, mixed content               | Yes         |
| **Accurate** | Medium           | Excellent         | Excellent              | Premium accuracy needed                      | Yes         |
| **Agentic**  | Medium           | Excellent         | Excellent              | Complex layouts, multi-page tables, diagrams | Yes         |

### Return value

The method returns a **`build_id`** (string). Use it with [Get build status](/sdk/sources/upload#get-build-status) to poll until processing completes (`Completed` or failure). The **`file_id`** does not change.

## Code examples

### Basic usage

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from graphor import Graphor

    client = Graphor()
    file_id = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"  # from list() or get_build_status

    response = client.sources.reprocess(
        file_id=file_id,
        method="balanced"
    )
    print(f"Build ID: {response.build_id}")
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    const client = new Graphor();
    const fileId = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';

    const { build_id: buildId } = await client.sources.reprocess({
      file_id: fileId,
      method: 'balanced',
    });
    console.log('Build ID:', buildId);
    ```
  </Tab>
</Tabs>

### Reprocess and poll until complete

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import time
    from graphor import Graphor

    client = Graphor()
    file_id = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"

    response = client.sources.reprocess(file_id=file_id, method="balanced")
    build_id = response.build_id

    while True:
        status = client.sources.get_build_status(build_id)
        if status.status == "Completed":
            print("Done. file_id:", status.file_id)
            break
        if status.error and status.status != "not_found":
            raise RuntimeError(status.error)
        time.sleep(2)
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    const client = new Graphor();
    const fileId = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';
    const { build_id: buildId } = await client.sources.reprocess({ file_id: fileId, method: 'balanced' });

    while (true) {
      const status = await client.sources.getBuildStatus(buildId);
      if (status.status === 'Completed') {
        console.log('Done. file_id:', status.file_id);
        break;
      }
      if (status.error && status.status !== 'not_found') throw new Error(status.error);
      await new Promise((r) => setTimeout(r, 2000));
    }
    ```
  </Tab>
</Tabs>

### With partition method

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    response = client.sources.reprocess(file_id=file_id, method="agentic")
    build_id = response.build_id
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    const { build_id: buildId } = await client.sources.reprocess({
      file_id: fileId,
      method: 'agentic',
    });
    ```
  </Tab>
</Tabs>

<Warning>
  Reprocessing runs in the background and can take several minutes. Use [Get build status](/sdk/sources/upload#get-build-status) to poll until completion.
</Warning>

### Error handling

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import graphor
    from graphor import Graphor

    client = Graphor()
    try:
        response = client.sources.reprocess(file_id=file_id, method="balanced")
        print("Scheduled. Build ID:", response.build_id)
    except graphor.NotFoundError as e:
        print("Source not found:", e)
    except graphor.BadRequestError as e:
        print("Invalid request:", e)
    except graphor.APIStatusError as e:
        print("API error:", e)
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    try {
      const { build_id: buildId } = await client.sources.reprocess({ file_id: fileId, method: 'balanced' });
      console.log('Scheduled. Build ID:', buildId);
    } catch (err) {
      if (err instanceof Graphor.NotFoundError) {
        console.log('Source not found:', err.message);
      } else if (err instanceof Graphor.APIError) {
        console.log('API error:', err.message);
      } else {
        throw err;
      }
    }
    ```
  </Tab>
</Tabs>

### Batch reprocess

Reprocess multiple sources by `file_id`; each call returns a `build_id`. Poll [Get build status](/sdk/sources/upload#get-build-status) for each until complete.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from graphor import Graphor

    client = Graphor()
    file_ids = ["id1", "id2", "id3"]
    build_ids = []
    for fid in file_ids:
        try:
            resp = client.sources.reprocess(file_id=fid, method="balanced")
            build_ids.append(resp.build_id)
            print(f"Scheduled: {fid} -> {resp.build_id}")
        except Exception as e:
            print(f"FAIL - {fid}: {e}")
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    const client = new Graphor();
    const fileIds = ['id1', 'id2', 'id3'];
    const buildIds: string[] = [];
    for (const fid of fileIds) {
      try {
        const { build_id: bid } = await client.sources.reprocess({ file_id: fid, method: 'balanced' });
        buildIds.push(bid);
        console.log(`Scheduled: ${fid} -> ${bid}`);
      } catch (err) {
        console.log(`FAIL - ${fid}:`, err);
      }
    }
    ```
  </Tab>
</Tabs>

## When to reprocess

<AccordionGroup>
  <Accordion icon="eye" title="Poor text extraction">
    **Symptoms**: Missing text, garbled characters, incomplete content\
    **Recommended**: `balanced` or `accurate` for complex layouts.
  </Accordion>

  <Accordion icon="table" title="Table detection issues">
    **Symptoms**: Tables not recognized, merged cells, structure lost\
    **Recommended**: `balanced`, `accurate`, or `agentic` for multi-page tables.
  </Accordion>

  <Accordion icon="image" title="Image and figure handling">
    **Symptoms**: Missing captions, poor figure recognition\
    **Recommended**: `balanced`, `accurate`, or `agentic` for rich image annotations.
  </Accordion>

  <Accordion icon="list" title="Document structure problems">
    **Symptoms**: Headers/footers mixed with content, poor section detection\
    **Recommended**: `balanced`, `accurate`, or `agentic` for better structure and semantics.
  </Accordion>
</AccordionGroup>

## Best practices

* **Use `file_id`**: Always use the source’s `file_id` (from list sources or build status).
* **Poll build status**: After calling `reprocess`, poll [Get build status](/sdk/sources/upload#get-build-status) with a reasonable interval (e.g. 2–5 seconds) and timeout.
* **Choose method by need**: Start with `fast` for testing; use `balanced` or `accurate` for better quality; use `agentic` for complex layouts and tables.

## Error Reference

| Error Type              | Status Code | Description                                   |
| ----------------------- | ----------- | --------------------------------------------- |
| `BadRequestError`       | 400         | Invalid request format or partition method    |
| `AuthenticationError`   | 401         | Invalid or missing API key                    |
| `PermissionDeniedError` | 403         | Access denied to the specified project        |
| `NotFoundError`         | 404         | Source not found for the given file\_id       |
| `RateLimitError`        | 429         | Too many requests, please retry after waiting |
| `InternalServerError`   | ≥500        | Processing failure or server error            |
| `APIConnectionError`    | N/A         | Network connectivity issues                   |
| `APITimeoutError`       | N/A         | Request timed out                             |

## Troubleshooting

<AccordionGroup>
  <Accordion icon="clock" title="Processing timeouts">
    **Causes**: Large files, complex documents, or heavy server load

    **Solutions**:

    * Increase request timeout (5+ minutes recommended)
    * Try a simpler processing method first
    * Process during off-peak hours

    <Tabs>
      <Tab title="Python">
        ```python theme={null}
        client = Graphor(timeout=600.0)  # 10 minutes
        ```
      </Tab>

      <Tab title="TypeScript">
        ```typescript theme={null}
        const client = new Graphor({ timeout: 600 * 1000 }); // 10 minutes
        ```
      </Tab>
    </Tabs>
  </Accordion>

  <Accordion icon="file-xmark" title="Source not found (404)">
    **Causes**: Invalid `file_id`, source deleted, or wrong project

    **Solutions**:

    * Use `client.sources.list()` to get valid `file_id`s
    * Ensure you're using the correct API key for the project

    <Tabs>
      <Tab title="Python">
        ```python theme={null}
        sources = client.sources.list()
        for s in sources:
            print(s.file_id, s.file_name)
        ```
      </Tab>

      <Tab title="TypeScript">
        ```typescript theme={null}
        const sources = await client.sources.list();
        for (const s of sources) {
          console.log(s.file_id, s.file_name);
        }
        ```
      </Tab>
    </Tabs>
  </Accordion>

  <Accordion icon="exclamation-triangle" title="Processing failures">
    **Causes**: Corrupted file, unsupported content, or method incompatibility

    **Solutions**:

    * Try a different `method` (e.g. `balanced`, `agentic`)
    * Check file integrity; re-ingest if necessary using `client.sources.ingest_file()`
  </Accordion>

  <Accordion icon="gauge" title="Poor processing quality">
    **Solutions**:

    * Use `balanced` or `accurate` for complex layouts
    * Use `agentic` for complex layouts with tables and diagrams
  </Accordion>
</AccordionGroup>

## Next steps

After reprocessing, poll [Get build status](/sdk/sources/upload#get-build-status) until complete, then:

<CardGroup cols={2}>
  <Card title="Get build status" icon="circle-info" href="/sdk/sources/upload#get-build-status">
    Poll status and get parsed elements for a build
  </Card>

  <Card title="List sources" icon="list" href="/sdk/sources/list">
    View all sources and their status
  </Card>

  <Card title="Upload" icon="arrow-up-from-bracket" href="/sdk/sources/upload">
    Ingest new files, URLs, GitHub repos, or YouTube videos
  </Card>

  <Card title="Get elements" icon="file-dashed-line" href="/sdk/sources/list-elements">
    Retrieve parsed elements from a source
  </Card>

  <Card title="Delete source" icon="trash" href="/sdk/sources/delete">
    Remove a source by file\_id
  </Card>
</CardGroup>
