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

# Diff a schema

> Diff the working draft against the last published version.

Draft versus last published version. Used by the builder before publish. Not billed.


## OpenAPI

````yaml GET /api/v2/structs/{slug}/diff/
openapi: 3.1.0
info:
  title: Abacus Docs API
  version: 1.0.0
  description: |
    REST + SSE surface for Abacus Docs on the same host as the web app
    (`https://abacusdocs.com`). Paths are `/api/v2/…`.

    Authenticate with an organisation API key (`sk-abacus-*`) as a Bearer
    token, or an Auth0 access token. Cross-tenant reads return **404**, not
    403. Page-based lists use `?page=` and `?page_size=`.

    Extraction, reprocess, schema tests, and chat turns spend credits.
    See the help centre Credits pages for rates.
  contact:
    name: Abacus Docs
    url: https://abacusdocs.com/contact
servers:
  - url: https://abacusdocs.com
    description: Production (Extract)
security: []
paths:
  /api/v2/structs/{slug}/diff/:
    get:
      tags:
        - v2/structs
      summary: Diff two Struct versions (or a version against the draft)
      description: >-
        Returns a structured diff between two endpoints of a Struct's history.
        Each query parameter is either a published version number (e.g.
        ``from=1&to=3``) or the literal ``draft`` to refer to the current
        working state on the Struct row (``schema_json`` +
        ``annotations_json``).


        The response carries:


        - ``added_fields``: fields that exist in ``to`` but not ``from``.

        - ``removed_fields``: fields that exist in ``from`` but not ``to``.

        - ``modified_fields``: fields with the same ``id`` on both sides   whose
        body changed, each tagged with ``position_changed`` so   edit-in-place
        and edit-and-move render distinctly.

        - ``reordered_field_ids``: pure reorders (same body, different  
        position) — *not* duplicated into ``modified_fields``.

        - ``annotation_changes``: set-difference of annotations on the  
        ``(field_id, section_index, start_offset, end_offset,   selected_text)``
        5-tuple key, returned as ordered   ``{change: added|removed, annotation:
        {...}}`` rows.

        - ``from_schema_json`` / ``to_schema_json``: the full JSON for   each
        side so clients can render a custom comparison without a   round-trip to
        the versions detail endpoint.


        Both ``from`` and ``to`` are required. Unknown slug / other-org /
        archived struct surface as 404 transparently. Unknown version number
        returns 404. Malformed values return 400.
      operationId: v2_structs_diff_retrieve
      parameters:
        - in: query
          name: from
          schema:
            type: string
          description: >-
            Diff source — either a published version number (integer >= 1) or
            the literal ``draft``.
          required: true
        - in: path
          name: slug
          schema:
            type: string
          required: true
        - in: query
          name: to
          schema:
            type: string
          description: >-
            Diff target — either a published version number (integer >= 1) or
            the literal ``draft``.
          required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StructDiff'
          description: ''
        '400':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
        '404':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
      security:
        - extractApiKey: []
        - bearerAuth: []
        - cookieAuth: []
components:
  schemas:
    StructDiff:
      type: object
      description: >-
        Response shape for GET /structs/{slug}/diff/?from=&to=.


        Compares two endpoints (each is a published version number or the

        literal "draft") and returns added / removed / modified / reordered
        field

        sets plus the full JSON bodies for client-side rendering.
      properties:
        diff_from:
          $ref: '#/components/schemas/_StructDiffEndpoint'
        diff_to:
          $ref: '#/components/schemas/_StructDiffEndpoint'
        added_fields:
          type: array
          items:
            $ref: '#/components/schemas/_SchemaField'
        removed_fields:
          type: array
          items:
            $ref: '#/components/schemas/_SchemaField'
        modified_fields:
          type: array
          items:
            $ref: '#/components/schemas/_ModifiedField'
        reordered_field_ids:
          type: array
          items:
            type: string
        annotation_changes:
          type: array
          items: {}
        from_schema_json: {}
        to_schema_json: {}
      required:
        - added_fields
        - annotation_changes
        - diff_from
        - diff_to
        - from_schema_json
        - modified_fields
        - removed_fields
        - reordered_field_ids
        - to_schema_json
    _StructDiffEndpoint:
      type: object
      description: Compact ``{version, label}`` block describing one side of a diff.
      properties:
        version:
          type:
            - integer
            - 'null'
        label:
          type: string
      required:
        - label
        - version
    _SchemaField:
      type: object
      description: |-
        Loose projection of a SchemaField from ExtractionSchema JSON.

        Kept as a permissive serializer (not a hard schema) because the schema
        builder is still iterating on field shapes — drf-spectacular only needs
        a stable component name for the SPA codegen, not full type fidelity.
      properties:
        id:
          type: string
        label:
          type: string
        type:
          type: string
      required:
        - id
    _ModifiedField:
      type: object
      description: Per-field diff descriptor for the diff endpoint.
      properties:
        field_id:
          type: string
        before:
          oneOf:
            - {}
            - type: 'null'
        after:
          oneOf:
            - {}
            - type: 'null'
        position_changed:
          type: boolean
      required:
        - after
        - before
        - field_id
        - position_changed
  securitySchemes:
    extractApiKey:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: |
        Organisation API key from Settings → API / `/api/keys/`. The secret is
        shown once. Send `Authorization: Bearer sk-abacus-…`. One active key
        per organisation. Ingest (`/api/v2/ingest/*`) refuses API keys — that
        surface is Auth0-only with `ingest:read` / `ingest:write` scopes.
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >
        Auth0 access token for a signed-in user. Send `Authorization: Bearer
        <token>`.

        The SPA and desktop agent use this. Prefer an organisation API key for

        server-to-server integrations.
    cookieAuth:
      type: apiKey
      in: cookie
      name: sessionid
      description: |
        Django session cookie from a browser login. Present so the web app can
        call `/api/v2` without a header. Do not rely on this for integrations.

````