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

# Publish a schema

> Publish the draft as an immutable schema version.

Snapshots the draft into an immutable version and makes it available to batches and Apply schema. **422** if the draft violates a hard contract (field id, field cap for the mode, table with no columns).

An API key cannot satisfy the role gate on publish — call this as a signed-in user.


## OpenAPI

````yaml POST /api/v2/structs/{slug}/publish/
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}/publish/:
    post:
      tags:
        - v2/structs
      summary: Publish the working draft as an immutable StructVersion
      description: >-
        Snapshots the Struct's working draft (``schema_json`` +
        ``annotations_json``) into a new immutable ``StructVersion`` row and
        points ``current_version`` at it. ``next_version_number`` is bumped
        under a row lock so concurrent publishes serialize cleanly. The first
        publish on a DRAFT struct also flips status to ACTIVE; subsequent
        publishes leave status untouched.


        Validates ``schema_json`` against the ``ExtractionSchema`` Pydantic
        model before creating the version — unpublishable drafts (missing field
        ids, malformed types, etc.) return 400 with the Pydantic error list
        under ``details``.


        Returns 422 with ``code=schema_field_count_exceeded`` when the draft has
        more than 18 fields (per AD-211 — Vertex's structured output compiler
        rejects schemas above this cap with 400 INVALID_ARGUMENT, so we surface
        an actionable error instead of letting extraction fail silently
        downstream).


        Returns 422 with ``code=schema_table_columns_required`` when any TABLE
        field has empty or missing ``columns`` (per AD-258 — Lynx's extraction
        adapter refuses to build the per-row Pydantic model in that case and
        falls back to OCR-only, leaving every schema-driven field on every
        document in the batch null with no error signal).
      operationId: v2_structs_publish_create
      parameters:
        - in: path
          name: slug
          schema:
            type: string
          required: true
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PublishRequestRequest'
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StructVersionDetail'
          description: ''
        '400':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
        '404':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
        '422':
          content:
            application/json:
              schema:
                type: object
                additionalProperties: {}
          description: ''
      security:
        - extractApiKey: []
        - bearerAuth: []
        - cookieAuth: []
components:
  schemas:
    PublishRequestRequest:
      type: object
      description: Body for POST /structs/{slug}/publish/.
      properties:
        publish_note:
          type: string
          maxLength: 500
    StructVersionDetail:
      type: object
      description: Detail shape for a single ``StructVersion`` — adds full JSON bodies.
      properties:
        version_number:
          type: integer
          maximum: 2147483647
          minimum: 0
        published_at:
          type: string
          format: date-time
          readOnly: true
        published_by:
          oneOf:
            - $ref: '#/components/schemas/_PublishedBy'
            - type: 'null'
          readOnly: true
        publish_note:
          type: string
          maxLength: 500
        field_count:
          type: integer
          readOnly: true
        is_deprecated:
          type: boolean
          readOnly: true
        deprecated_at:
          type:
            - string
            - 'null'
          format: date-time
        deprecated_by:
          oneOf:
            - $ref: '#/components/schemas/_PublishedBy'
            - type: 'null'
          readOnly: true
        deprecation_note:
          type: string
          maxLength: 500
        schema_json: {}
        annotations_json: {}
      required:
        - annotations_json
        - deprecated_by
        - field_count
        - is_deprecated
        - published_at
        - published_by
        - schema_json
        - version_number
    _PublishedBy:
      type: object
      description: Compact projection of the user who published / deprecated a version.
      properties:
        id:
          type: integer
        email:
          type: string
          format: email
      required:
        - email
        - id
  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.

````