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

# Get Sources

> Return the extraction result enriched with per-leaf source provenance.

Each extracted leaf value is wrapped as {value, source} where source
contains citation content, surrounding context, and a format-specific
anchor (bbox for PDFs, cell ref for spreadsheets, text span for plain text, etc.).

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

  client = Retab()

  result = client.extractions.sources("extr_01G34H8J2K")
  print(result)
  ```

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

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

  const result = await client.extractions.sources("extr_01G34H8J2K");
  console.log(result);
  ```

  ```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)
  	}

  	result, err := client.Extractions.Sources(ctx, "extr_01G34H8J2K")
  	if err != nil {
  		log.Fatal(err)
  	}
  	fmt.Println(*result)
  }
  ```

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

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

  result = client.extractions.sources(extraction_id: 'extr_01G34H8J2K')
  puts result
  ```

  ```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 result = client.extractions().sources("extr_01G34H8J2K").await?;
      println!("{:?}", result);
      Ok(())
  }
  ```

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

  use Retab\Client;

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

  $result = $client->extractions()->sources(
      extractionId: 'extr_01G34H8J2K',
  );
  print_r($result);
  ```

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

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

  var result = await client.Extractions.SourcesAsync("extr_01G34H8J2K");
  Console.WriteLine(result);
  ```

  ```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 result = client.extractions().sources("extr_abc123");
      System.out.println(result);
    }
  }
  ```

  ```curl cURL theme={null}
  curl -X 'GET' \
    'https://api.retab.com/v1/extractions/extr_01G34H8J2K/sources' \
    -H 'accept: application/json' \
    -H 'Authorization: Bearer <your-api-key>'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "object": "extraction.sources",
    "extraction_id": "extr_01G34H8J2K",
    "document_type": "pdf",
    "file": {
      "id": "file_abc123",
      "filename": "invoice_001.pdf",
      "mime_type": "application/pdf"
    },
    "extraction": {
      "invoice_number": "INV-1032",
      "customer": {
        "name": "Acme Inc."
      },
      "total_amount": 1240.0
    },
    "sources": {
      "invoice_number": {
        "value": "INV-1032",
        "source": {
          "content": "INV-1032",
          "anchor": {
            "kind": "pdf_bbox",
            "page": 1,
            "left": 0.6,
            "top": 0.12,
            "width": 0.25,
            "height": 0.03
          }
        }
      },
      "customer": {
        "name": {
          "value": "Acme Inc.",
          "source": {
            "content": "Acme Inc.",
            "anchor": {
              "kind": "pdf_bbox",
              "page": 1,
              "left": 0.1,
              "top": 0.25,
              "width": 0.3,
              "height": 0.03
            }
          }
        }
      },
      "total_amount": {
        "value": 1240.0,
        "source": {
          "content": "1,240.00",
          "anchor": {
            "kind": "pdf_bbox",
            "page": 1,
            "left": 0.65,
            "top": 0.85,
            "width": 0.2,
            "height": 0.03
          }
        }
      }
    }
  }
  ```

  ```json 404 theme={null}
  {
    "detail": "No extraction found for extraction_id 'extr_01G34H8J2K'"
  }
  ```

  ```json 422 theme={null}
  {
    "detail": "Extraction has no output to source"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml GET /v1/extractions/{extraction_id}/sources
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.retab.com
security: []
paths:
  /v1/extractions/{extraction_id}/sources:
    get:
      tags:
        - Extractions
      summary: Get Extraction Sources
      description: >-
        Return the extraction result enriched with per-leaf source provenance.


        Each extracted leaf value is wrapped as {value, source} where source

        contains citation content, surrounding context, and a format-specific

        anchor (bbox for PDFs, cell ref for spreadsheets, text span for plain
        text, etc.).
      operationId: get_extraction_sources
      parameters:
        - in: path
          name: extraction_id
          required: true
          schema:
            type: string
            title: Extraction Id
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExtractionSources'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    ExtractionSources:
      properties:
        object:
          type: string
          const: extraction.sources
          title: Object
          default: extraction.sources
        extraction_id:
          type: string
          title: Extraction Id
          description: ID of the extraction
        document_type:
          type: string
          enum:
            - pdf
            - image
            - csv
            - xlsx
            - docx
            - txt
          title: Document Type
          description: Detected document type of the source file
        file:
          $ref: '#/components/schemas/FileRef'
          description: Source file metadata (id, filename, mime_type).
        extraction:
          additionalProperties: true
          type: object
          title: Extraction
          description: Original extraction output
        sources:
          additionalProperties: true
          type: object
          title: Sources
          description: >-
            Same shape as extraction but leaves are {value, source} objects.
            Non-null source entries include file_id.
      type: object
      required:
        - document_type
        - extraction
        - extraction_id
        - file
        - sources
      title: ExtractionSources
      description: >-
        An extraction's output annotated with the source that backs each value.


        Returned when fetching the sources for an extraction. Carries the source
        `file`

        and its detected `document_type`, the original `extraction` output, and
        a

        parallel `sources` tree where each leaf is a `{value, source}` object
        locating

        the value in the document (a page region for PDFs, a cell for
        spreadsheets, a

        text span for plain text, and so on).
    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.
    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
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````