openapi: 3.0.3
info:
  title: Introduction to the Anesya API
  version: 0.8.1
  description: >

    Welcome to the official **Anesya API** documentation.  

    This API allows you to interact with Anesya’s backend to create smart
    document extractions and retrieve structured data from them.


    ---


    ## Authentication


    {% admonition type="info" name="Create an API Token" %}
      To start using the Anesya API, you first need to [create an API token](/tutorials/api_key).
    {% /admonition %}


    The API is secured using an **API authentication token**, which must be
    included in the `Authorization` header of each request.


    ```http

    Authorization: <YOUR_API_KEY>

    ````


    > 📌 **Important:** Do not share your tokens and never commit them to
    GitHub.


    You can create your token on <a href="https://dashboard.anesya.app/api"
    target='_blank'>this page</a> of the Anesya App. Each token has a defined
    **lifetime**: `1m`, `3m`, `6m`, or `inf` (unlimited).


    ---


    ## Endpoint


    The API is accessible at the following environment:


    * `https://api.anesya.app/`


    > 📌 **Important:** Always include a trailing `/` at the end of each API
    URL.


    ---


    ## Common error codes


    | HTTP Code | Description                     |

    | --------- | ------------------------------- |

    | `200`     | Everything worked fine          |

    | `201`     | Resource successfully created   |

    | `202`     | Resource accepted but not ready |

    | `400`     | Missing or invalid fields       |

    | `401`     | Missing or invalid token        |

    | `403`     | Insufficient credits            |

    | `404`     | Resource not found              |


    ---


    ## Additional resources


    * [Create an extraction](#operation/extract_create)

    * [List Schemas](#operation/schema_list)


    ---


    Need help? Contact us at
    [support@anesya.app](mailto:support@anesya.app).<br>

    Happy integrating!
servers:
  - url: https://api.anesya.app
    description: Serveur Anesya
components:
  securitySchemes:
    tokenAuth:
      type: apiKey
      in: header
      name: Authorization
  schemas:
    AuthError:
      type: object
      properties:
        detail:
          type: string
          example: Given token not valid for any token type
    Extract:
      type: object
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        document_name:
          type: string
          readOnly: true
          nullable: true
          example: invoice.pdf
        document_url:
          type: string
          readOnly: true
          example: /document/3019eef7-3aaa-4f25-aaad-c570acaa32dc/?type=extract
        content_images:
          type: array
          items:
            $ref: '#/components/schemas/ExtractImages'
          readOnly: true
        server:
          $ref: '#/components/schemas/ServerEnum'
        content:
          type: string
          readOnly: true
          nullable: true
          example: Invoice On 25/11/2024 ...
        extracted_data:
          readOnly: true
          nullable: true
        schema:
          type: string
          format: uuid
          nullable: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        classifier:
          type: string
          format: uuid
          nullable: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        classifier_result:
          type: string
          nullable: true
          example: Invoice
        workflow:
          type: string
          format: uuid
          nullable: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        workflow_session_id:
          type: integer
          nullable: true
          example: 1758718492
        status:
          allOf:
            - $ref: '#/components/schemas/StatusEnum'
          readOnly: true
        extraction_step:
          allOf:
            - $ref: '#/components/schemas/StepEnum'
          readOnly: true
        extraction_time:
          type: number
          nullable: true
          description: Extraction time in seconds
          example: 41.09
        credit_used:
          type: integer
          nullable: true
          example: 3
          description: Anesya's credits used
        metadata:
          type: object
          nullable: true
          example:
            personal_id: '1234567890'
          description: >
            Key-value store for custom information related to the extract. Can
            be used to attach arbitrary structured data (e.g. identifiers, tags,
            integration info).
        created_at:
          type: string
          format: date-time
          readOnly: true
          example: '2025-06-12T14:56:10.682461Z'
      required:
        - content
        - content_images
        - created_at
        - document_name
        - document_url
        - error
        - extracted_data
        - id
        - server
        - status
    ExtractImages:
      type: object
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        name:
          type: string
          nullable: true
          example: _page_0_Picture_15.jpeg
        url:
          type: string
          readOnly: true
          example: /images/ee81739d-bf1f-47e8-b504-fd6e10300e06/
      required:
        - id
        - url
    ExtractList:
      type: object
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        document_name:
          type: string
          readOnly: true
          nullable: true
          example: invoice.pdf
        document_url:
          type: string
          readOnly: true
          example: /document/3019eef7-3aaa-4f25-aaad-c570acaa32dc/?type=extract
        workflow:
          type: string
          format: uuid
          readOnly: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        workflow_session_id:
          type: integer
          readOnly: true
          example: 1758716706
        schema:
          allOf:
            - $ref: '#/components/schemas/ExtractSchema'
          readOnly: true
        classifier:
          type: string
          format: uuid
          readOnly: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        server:
          allOf:
            - $ref: '#/components/schemas/ServerEnum'
          readOnly: true
        status:
          allOf:
            - $ref: '#/components/schemas/StatusEnum'
          readOnly: true
        error:
          type: string
          readOnly: true
          nullable: true
          example: Failed to extract
        created_at:
          type: string
          format: date-time
          readOnly: true
          example: '2025-06-12T14:56:10.682461Z'
      required:
        - created_at
        - document_name
        - document_url
        - error
        - id
        - status
    ExtractListParameters:
      type: object
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        document_name:
          type: string
          readOnly: true
          nullable: true
          example: invoice.pdf
        document_url:
          type: string
          readOnly: true
          example: /document/3019eef7-3aaa-4f25-aaad-c570acaa32dc/?type=extract
        workflow:
          type: string
          format: uuid
          readOnly: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        workflow_session_id:
          type: integer
          readOnly: true
          example: 1758716706
        schema:
          allOf:
            - $ref: '#/components/schemas/ExtractSchema'
          readOnly: true
        classifier:
          type: string
          format: uuid
          readOnly: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        server:
          allOf:
            - $ref: '#/components/schemas/ServerEnum'
          readOnly: true
        status:
          allOf:
            - $ref: '#/components/schemas/StatusEnum'
          readOnly: true
        error:
          type: string
          readOnly: true
          nullable: true
          example: Failed to extract
        created_at:
          type: string
          format: date-time
          readOnly: true
          example: '2025-06-12T14:56:10.682461Z'
      required:
        - created_at
        - document_name
        - document_url
        - error
        - id
        - status
    ExtractRequest:
      type: object
      properties:
        document:
          type: string
          format: binary
          description: 'Document to process, accepted : .pdf / .png / .jpg / .jpeg'
        server:
          $ref: '#/components/schemas/ServerEnum'
        schema:
          type: string
          format: uuid
          nullable: true
          description: ID of the schema you want to use
          example: 1f25b8af-eb35-4caf-8f3f-5edd3a79beee
        classifier:
          type: string
          format: uuid
          nullable: true
          description: ID of the classifier you want to use
          example: 1f25b8af-eb35-4caf-8f3f-5edd3a79beee
        metadata:
          type: object
          nullable: true
          example:
            personal_id: '1234567890'
          description: >
            Key-value store for custom information related to the extract. Can
            be used to attach arbitrary structured data (e.g. identifiers, tags,
            integration info).
      required:
        - document
        - server
    JWTError:
      type: object
      properties:
        detail:
          type: string
          description: Message principal de l'erreur
          example: Given token not valid for any token type
        code:
          type: string
          description: Code d'erreur JWT
          example: token_not_valid
        messages:
          type: array
          items:
            $ref: '#/components/schemas/JWTErrorMessage'
          description: Liste des messages d'erreur détaillés
      required:
        - code
        - detail
        - messages
    JWTErrorMessage:
      type: object
      properties:
        token_class:
          type: string
          description: Type de token JWT
          example: AccessToken
        token_type:
          type: string
          description: 'Type de token (ex: access)'
          example: access
        message:
          type: string
          description: Description de l'erreur
          example: Token is expired
      required:
        - message
        - token_class
        - token_type
    NotFound:
      type: object
      properties:
        detail:
          type: string
          default: Matching query does not exist.
          example: No Extract matches the given query.
    PaginatedExtract:
      type: object
      properties:
        count:
          type: integer
          example: 1
        next:
          type: string
          nullable: true
          example: https://api.anesya.app/schema/?page=3&size=50
        previous:
          type: string
          nullable: true
          example: https://api.anesya.app/schema/?page=2&size=50
        results:
          type: array
          items:
            $ref: '#/components/schemas/ExtractList'
      required:
        - count
        - next
        - previous
        - results
    RequiredError:
      type: object
      properties:
        field_name:
          type: array
          items:
            type: string
          description: Liste des erreurs pour un champ spécifique
      required:
        - field_name
    ServerEnum:
      enum:
        - EU-1
        - FR-1
        - FR-2
        - FR-3
      type: string
      description: |-
        * `EU-1` - Eu1
        * `FR-1` - Fr1
        * `FR-2` - Fr2
        * `FR-3` - Fr3
      example: FR-3
    StatusEnum:
      enum:
        - CREATED
        - IN_PROGRESS
        - FINISHED
        - ERROR
      type: string
      description: |-
        * `CREATED` - Created
        * `IN_PROGRESS` - In Progress
        * `FINISHED` - Finished
        * `ERROR` - Error
    StepEnum:
      enum:
        - OCR
        - CLASSIFICATION
        - IMAGES
        - PARSING
        - LOCATION
      type: string
      description: |-
        * `OCR` - Document parsing
        * `CLASSIFICATION` - Document classification
        * `IMAGES` - Document image analysis
        * `PARSING` - Target data extraction
        * `LOCATION` - Visual rendering of data
    Theme:
      type: object
      properties:
        id:
          type: string
          format: uuid
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
          readOnly: true
        fields:
          type: array
          items:
            $ref: '#/components/schemas/ThemeField'
        field_groups:
          type: array
          items:
            $ref: '#/components/schemas/ThemeFieldGroup'
        field_objects:
          type: array
          items:
            $ref: '#/components/schemas/ThemeFieldObject'
        name:
          type: string
          maxLength: 200
          example: Invoice Theme
        description:
          type: string
          example: Theme to extract invoice number and delivery address
        created_at:
          type: string
          format: date-time
          readOnly: true
          example: '2025-06-12T14:56:10.682461Z'
        updated_at:
          type: string
          format: date-time
          readOnly: true
          example: '2025-06-12T14:56:10.682461Z'
      required:
        - created_at
        - description
        - field_groups
        - field_objects
        - fields
        - id
        - name
        - updated_at
    ThemeField:
      type: object
      properties:
        id:
          type: string
          format: uuid
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        name:
          type: string
          maxLength: 200
          example: Invoice number
        description:
          type: string
          example: Invoice's number
        type:
          $ref: '#/components/schemas/ThemeFieldTypeEnum'
      required:
        - description
        - name
        - type
    ThemeFieldGroup:
      type: object
      properties:
        id:
          type: string
          format: uuid
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        fields:
          type: array
          items:
            $ref: '#/components/schemas/ThemeField'
        name:
          type: string
          maxLength: 200
          example: Items
        description:
          type: string
          nullable: true
          example: Items in invoice
      required:
        - fields
        - name
    ThemeFieldObject:
      type: object
      properties:
        id:
          type: string
          format: uuid
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        fields:
          type: array
          items:
            $ref: '#/components/schemas/ThemeField'
        name:
          type: string
          maxLength: 200
          example: Invoice delivery address
        description:
          type: string
          nullable: true
          example: Invoice's delivery address
      required:
        - fields
        - name
    ExtractSchema:
      type: object
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        name:
          type: string
          maxLength: 200
          example: Invoice schema
        description:
          type: string
          example: Schema used for extracting data from customs invoices
        additional_informations:
          type: string
          nullable: true
          example: >
            Common abbreviations: "CB" = credit card, "TVA" = VAT. Amounts use a
            comma as the decimal separator.
          description: >
            Free-form context to help the AI interpret the document (business
            jargon, abbreviations, locale/date/currency formats, vendor aliases,
            layout quirks). Use this when relevant details are missing from the
            file itself.
        schema:
          type: object
          nullable: true
          description: Schema definition in OpenAPI JSON format
        created_at:
          type: string
          format: date-time
          readOnly: true
          example: '2025-06-12T14:56:10.682461Z'
        updated_at:
          type: string
          format: date-time
          readOnly: true
          example: '2025-06-12T14:56:10.682461Z'
      required:
        - id
        - name
        - description
        - schema
    PaginatedExtractSchema:
      type: object
      properties:
        count:
          type: integer
          example: 50
        next:
          type: string
          nullable: true
          example: https://api.anesya.app/schema/?page=3&size=50
        previous:
          type: string
          nullable: true
          example: https://api.anesya.app/schema/?page=1&size=50
        results:
          type: array
          items:
            $ref: '#/components/schemas/ExtractSchema'
      required:
        - count
        - next
        - previous
        - results
    ExtractSchemaRequest:
      type: object
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 200
          example: Invoice schema
        description:
          type: string
          minLength: 1
          example: Schema used for extracting data from customs invoices
        custom_prompt:
          type: string
          nullable: true
          example: >-
            _ may occasionally be missing from the document. If so, it should be
            added manually.
        schema:
          type: object
          nullable: true
          description: OpenAPI JSON format
      required:
        - description
        - name
    ThemeFieldTypeEnum:
      enum:
        - STRING
        - NUMBER
        - DATE
        - BOOL
      type: string
      example: STRING
      description: |-
        * `STRING` - String
        * `NUMBER` - Number
        * `DATE` - Date
        * `BOOL` - Boolean
    Workflow:
      type: object
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
          example: 300f339f-da71-4f9f-80f6-c25a63baae75
        title:
          type: string
          maxLength: 200
          example: Extraction de factures
        schema:
          allOf:
            - $ref: '#/components/schemas/ExtractSchema'
          readOnly: true
        description:
          type: string
          nullable: true
          example: Flux de traitement automatique des factures fournisseurs.
        source:
          $ref: '#/components/schemas/OutputExtractedDataEnum'
          example: DIRECT_FILES
        use_splitter:
          type: boolean
          example: true
        use_classification:
          type: boolean
          example: false
        output:
          $ref: '#/components/schemas/OutputExtractedDataEnum'
          example: GOOGLE_DRIVE
        output_extracted_data:
          $ref: '#/components/schemas/OutputExtractedDataEnum'
          example: DIRECT_FILES
        server:
          $ref: '#/components/schemas/ServerEnum'
          example: FR-1
        created_at:
          type: string
          format: date-time
          readOnly: true
          example: '2025-06-26T13:12:00.123Z'
        updated_at:
          type: string
          format: date-time
          readOnly: true
          example: '2025-06-26T13:14:52.456Z'
      required:
        - created_at
        - id
        - schema
        - title
        - updated_at
    WorkflowExtractRequest:
      type: object
      properties:
        extracts:
          type: array
          items:
            $ref: '#/components/schemas/ExtractUploadRequest'
          example:
            - document: (binary file)
      required:
        - extracts
    ExtractUploadRequest:
      type: object
      properties:
        document:
          type: string
          format: binary
          example: invoice_march_2025.pdf
      required:
        - document
    OutputExtractedDataEnum:
      enum:
        - DIRECT_FILES
        - GOOGLE_DRIVE
        - DROPBOX
      type: string
      description: |-
        * `DIRECT_FILES` - Fichier importé  
        * `GOOGLE_DRIVE` - Google Drive  
        * `DROPBOX` - Dropbox
      example: DIRECT_FILES
security:
  - tokenAuth: []
tags:
  - name: Extracts
    description: >
      Groups all endpoints related to extractions:

      - <a href="/api/schema/extracts/extract_list">Create an extraction</a>

      - <a href="/api/schema/extracts/extract_destroy">Delete an extraction</a>

      - <a href="/api/schema/extracts/extract_retrieve">Get extraction
      details</a>

      - <a href="/api/schema/extracts/extract_list">List all existing
      extractions</a>
  - name: Schemas
    description: |
      Groups all endpoints related to extraction schema management:
      - <a href="/api/schema/schemas/schema_list">List all schemas</a>
      - <a href="/api/schema/schemas/schema_create">Create new schema</a>
      - <a href="/api/schema/schemas/schema_retrieve">Retrieve a schema</a>
      - <a href="/api/schema/schemas/schema_update">Update a schema</a>
      - <a href="/api/schema/schemas/schema_destroy">Delete a schema</a>
  - name: Workflows
    description: >
      Groups all endpoints related to workflow management:

      - <a href="/api/schema/workflows/workflow_extract_create">Create a
      workflow extract</a>
paths:
  /extract/:
    get:
      operationId: extract_list
      tags:
        - Extracts
      summary: List all extracts
      description: Fetch a list of all available extractions.
      security:
        - tokenAuth: []
      parameters:
        - in: query
          name: page
          schema:
            type: integer
            default: 1
          description: Number of the page.
        - in: query
          name: search
          schema:
            type: string
          description: >
            <strong style="color:#99DDE7">(Optional)</strong> Allows searching
            within the fields <strong>extract.document_name</strong> and
            <strong>extract.schema.name</strong>
        - in: query
          name: size
          schema:
            type: integer
            default: 50
          description: Page size.
        - in: query
          name: workflow_id
          schema:
            type: string
            format: uuid
          description: >
            <strong style="color:#99DDE7">(Optional)</strong> Optional id of a
            <strong>workflow</strong> to filter by.
        - in: query
          name: workflow_session_id
          schema:
            type: integer
          description: >
            <strong style="color:#99DDE7">(Optional)</strong> Optional id of a
            <strong>workflow session</strong> to filter by.
        - in: query
          name: meta_key
          schema:
            type: string
          description: >
            <strong style="color:#99DDE7">(Optional)</strong> Recherche un
            extract qui contient la clé `meta_key` dans ses metadatas.
        - in: query
          name: meta_value
          schema:
            type: string
          description: >
            <strong style="color:#99DDE7">(Optional)</strong> Recherche un
            extract qui contient la valeur `meta_value` dans ses metadatas.
      responses:
        '200':
          description: List of extractions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaginatedExtract'
        '401':
          description: Authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthError'
    post:
      operationId: extract_create
      description: Creates a new extraction with or without a theme (extraction schema).
      summary: Creates a new extraction.
      parameters:
        - in: query
          name: pdf_page_start
          schema:
            type: integer
            default: 1
            minimum: 1
          description: Start page (PDF only)
        - in: query
          name: pdf_page_end
          schema:
            type: integer
            default: 30
            maximum: 30
          description: End page (PDF only)
      tags:
        - Extracts
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ExtractRequest'
        required: true
      security:
        - tokenAuth: []
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Extract'
          description: Extract successfully created.
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RequiredError'
          description: Missing one or more required fields.
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JWTError'
          description: Invalid or missing authentication token.
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RequiredError'
          description: Insufficient credits.
      x-codeSamples:
        - lang: Python
          source: |
            import requests, mimetypes

            API_TOKEN = "YOUR_API_TOKEN"
            FILE_PATH = "invoice.pdf"  

            # Guess the file's MIME type
            mime_type, _ = mimetypes.guess_type(FILE_PATH)
            mime_type = mime_type or "application/pdf"

            # Prepare headers and payload
            headers = {
                "Authorization": f"Bearer {API_TOKEN}"
            }

            data = {
                "server": "FR-1",
                "schema": "<YOUR_SCHEMA_ID>"  // Optional
            }

            with open(FILE_PATH, "rb") as f:
                files = {
                    "document": (FILE_PATH, f, mime_type)
                }

                response = requests.post(
                    url="https://api.anesya.app/extract/",
                    headers=headers,
                    data=data,
                    files=files
                )

            # Handle response
            if response.status_code == 201:
                extract = response.json()
                print("✅ Extract created:", extract["id"])
            else:
                print("❌ Error:", response.status_code, response.text)
        - lang: Node.js
          source: |
            const axios = require('axios');
            const fs = require('fs');
            const FormData = require('form-data');
            const mime = require('mime-types');

            // Configuration
            const API_URL = 'https://api.anesya.app/extract/';
            const API_TOKEN = 'YOUR_API_TOKEN';
            const FILE_PATH = 'invoice.pdf'; // Supported: .pdf, .jpg, .png
            const SCHEMA_ID = 'optional-SCHEMA-uuid'; // Leave empty if not used
            const SERVER = 'FR-1'; // Options: EU-1, FR-1, FR-2, FR-3

            // Prepare the form data
            const form = new FormData();
            form.append('document', fs.createReadStream(FILE_PATH), {
              filename: FILE_PATH,
              contentType: mime.lookup(FILE_PATH) || 'application/pdf',
            });
            form.append('server', SERVER);
            if (SCHEMA_ID) {
              form.append('schema', SCHEMA_ID);
            }

            // Make the POST request
            axios.post(API_URL, form, {
              headers: {
                Authorization: `Bearer ${API_TOKEN}`,
                ...form.getHeaders(),
              },
            })
            .then((response) => {
              console.log('✅ Extract created:', response.data.id);
            })
            .catch((error) => {
              if (error.response) {
                console.error('❌ Error:', error.response.status, error.response.data);
              } else {
                console.error('❌ Request failed:', error.message);
              }
            });
  /extract/{id}/:
    get:
      operationId: extract_retrieve
      description: Extraction details.
      summary: Extraction details
      parameters:
        - in: query
          name: download
          schema:
            type: string
            enum:
              - csv
              - images
              - json
            default: csv
          description: >
            <strong style="color:#99DDE7">(Optional)</strong> Content download
            format:

            <ul>
              <li><code>csv</code> → Download tabular data</li>
              <li><code>images</code> → Download associated images (.zip)</li>
              <li><code>json</code> → Download the full JSON</li>
            </ul>

            ⚠️ If not specified, CSV is selected by default.<br>

            ⚠️ If no schema is present in the extraction, nothing will be
            downloaded.<br><br>
          required: false
        - in: path
          name: id
          schema:
            type: string
          required: true
      tags:
        - Extracts
      security:
        - tokenAuth: []
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Extract'
          description: Extract details
        '202':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Extract'
          description: Extract details (Still in progress)
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JWTError'
          description: Invalid or missing authentication token.
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFound'
          description: Extract does not exist.
    delete:
      operationId: extract_destroy
      description: ⚠️ Permanently delete an extraction.
      summary: Delete an extraction
      parameters:
        - in: path
          name: id
          schema:
            type: string
          required: true
      tags:
        - Extracts
      security:
        - tokenAuth: []
      responses:
        '204':
          description: No response body
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JWTError'
          description: Invalid or missing authentication token.
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFound'
          description: No extraction matches the given query.
  /schema/:
    get:
      operationId: schema_list
      summary: List all schemas
      description: Retrieve a paginated list of all available schemas.
      tags:
        - Schemas
      security:
        - tokenAuth: []
      parameters:
        - in: query
          name: page
          schema:
            type: integer
            default: 1
          description: Page number (starts at 1).
        - in: query
          name: size
          schema:
            type: integer
            default: 50
          description: Number of items per page.
      responses:
        '200':
          description: A paginated list of extract schemas.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaginatedExtractSchema'
        '401':
          description: Invalid or missing authentication token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JWTError'
    post:
      operationId: schema_create
      description: >
        Create a new extraction schema.


        If you're unsure how to structure your schema, check out the guide : 

        <a href="/tutorials/schemas/create_schema" target="_blank">How to Build
        a JSON Extraction Schema</a>.
      summary: Create new schema
      tags:
        - Schemas
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExtractSchema'
        required: true
      security:
        - tokenAuth: []
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExtractSchema'
          description: Extract schema successfully created.
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RequiredError'
          description: Missing one or more required fields.
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JWTError'
          description: Invalid or missing authentication token.
  /schema/{id}/:
    get:
      operationId: schema_retrieve
      summary: Retrieve a schema
      description: Get the details of a specific extract schema by its ID.
      tags:
        - Schemas
      security:
        - tokenAuth: []
      parameters:
        - in: path
          name: id
          schema:
            type: string
          required: true
          description: The UUID of the extract schema.
      responses:
        '200':
          description: Extract schema details.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExtractSchema'
        '401':
          description: Invalid or missing authentication token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JWTError'
        '404':
          description: No extract schema matches the given ID.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFound'
    put:
      operationId: schema_update
      summary: Update a schema
      description: Update an existing extract schema by its ID.
      tags:
        - Schemas
      security:
        - tokenAuth: []
      parameters:
        - in: path
          name: id
          schema:
            type: string
          required: true
          description: The UUID of the extract schema.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExtractSchema'
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/ExtractSchema'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ExtractSchema'
      responses:
        '200':
          description: Extract schema successfully updated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExtractSchema'
        '400':
          description: Missing or invalid fields.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RequiredError'
        '401':
          description: Invalid or missing authentication token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JWTError'
        '404':
          description: Extract schema not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFound'
    delete:
      operationId: schema_destroy
      summary: Delete a schema
      description: Permanently delete an extract schema by its ID.
      tags:
        - Schemas
      security:
        - tokenAuth: []
      parameters:
        - in: path
          name: id
          schema:
            type: string
          required: true
          description: The UUID of the extract schema.
      responses:
        '204':
          description: Schema successfully deleted. No content returned.
        '401':
          description: Invalid or missing authentication token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JWTError'
        '404':
          description: Extract schema not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFound'
  /workflow/{id}/extract/:
    post:
      operationId: workflow_extract_create
      summary: Create an extract from a workflow
      description: >-
        Upload a document to create a new extract associated with a specific
        workflow.
      tags:
        - Workflows
      parameters:
        - in: path
          name: id
          description: UUID of the Workflow
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/WorkflowExtractRequest'
      security:
        - tokenAuth: []
      responses:
        '201':
          description: Extract successfully created and linked to Workflow.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Extract'
        '400':
          description: Missing or invalid required fields.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RequiredError'
        '401':
          description: Invalid or missing authentication token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JWTError'
        '404':
          description: Workflow not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFound'
      x-codeSamples:
        - lang: Python
          source: |
            import requests, mimetypes

            # Configuration
            API_TOKEN = "YOUR_API_TOKEN"
            WORKFLOW_ID = "fc43e8e3-226b-4a33-bfb9-1306573ff271"
            FILE_PATH = "path/to/document.pdf"  # Replace with your actual path

            # Detect MIME type
            mime_type, _ = mimetypes.guess_type(FILE_PATH)
            mime_type = mime_type or "application/pdf"

            # Prepare headers
            headers = {
                "Authorization": f"Bearer {API_TOKEN}"
            }

            # Prepare file payload
            with open(FILE_PATH, "rb") as file:
                files = {
                    "extracts[0].document": (file.name, file, mime_type)
                }

                response = requests.post(
                    url=f"https://api.anesya.app/workflow/{WORKFLOW_ID}/extract/",
                    headers=headers,
                    files=files
                )

            # Handle response
            if response.status_code == 201:
                print("✅ Extract created inside workflow:")
                print(response.json())
            else:
                print("❌ Error:", response.status_code, response.text)
