# Schemas

> The schema format, its limits, and the saved schema endpoints.

Page: https://doxtract.manoonlabs.com/docs/api/schemas

## Schema format

A schema is an object with `type: object` and `properties`. Each property has a type and an optional description the model reads. `array` adds `items`, one node. `object` adds `properties` and may add `required`. A date is a string in yyyy-mm-dd. Keys start with a letter or underscore, then letters, digits, underscores or hyphens.

Types: `any`, `null`, `boolean`, `string`, `number`, `date`, `array`, `object`

**Schema**

```json
{
  "type": "object",
  "properties": {
    "vendor": {
      "type": "string"
    },
    "invoiceNumber": {
      "type": "string"
    },
    "issued": {
      "type": "date"
    },
    "total": {
      "type": "number"
    },
    "lineItems": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "description": {
            "type": "string"
          },
          "amount": {
            "type": "number"
          }
        },
        "required": [
          "description",
          "amount"
        ]
      }
    }
  },
  "required": [
    "vendor",
    "invoiceNumber",
    "total"
  ]
}
```

## Limits

| Limit | Value |
| --- | --- |
| Root | object |
| Date | yyyy-mm-dd |
| Depth | 4 levels below the root |
| Keys | 100 |
| Size | 16,384 bytes |
| Key length | 64 characters |
| Description | 400 characters, optional |
| Name length | 80 characters |
| Saved schemas | 10 on Free, 100 on paid plans |

## Endpoints

| Method | Path | What it does |
| --- | --- | --- |
| `GET` | `/api/v1/schemas` | [List schemas](#list_schemas) |
| `GET` | `/api/v1/schemas/{slug}` | [Read a schema](#get_schema) |
| `POST` | `/api/v1/schemas` | [Create a schema](#create_schema) |
| `PATCH` | `/api/v1/schemas/{slug}` | [Update a schema](#update_schema) |

### List schemas

`GET /api/v1/schemas`

List the extraction schemas saved in this workspace.

- There is no request body.
- Each item has id, name, slug, keyCount, createdAt, and updatedAt.
- Read one schema when you need its definition.
- schemas is an empty array when the workspace has none.

**Request**

```bash
curl -X GET https://doxtract.manoonlabs.com/api/v1/schemas \
  -H "Authorization: Bearer mldxt_..."
```

**Response**

```json
{
  "status": "ok",
  "schemas": [
    {
      "id": "cm7schema",
      "name": "Invoice",
      "slug": "invoice",
      "keyCount": 7,
      "createdAt": "2026-10-26T00:00:00.000Z",
      "updatedAt": "2026-10-26T00:00:00.000Z"
    }
  ]
}
```

### Read a schema

`GET /api/v1/schemas/{slug}`

Read one saved extraction schema by slug.

- The slug is one path segment. URL-encode it. "invoice" is /api/v1/schemas/invoice.
- The response adds schema, the definition (JSON key name unchanged).
- A missing slug returns 404 with status "error" and message "That schema was not found.".

**Request**

```bash
curl -X GET https://doxtract.manoonlabs.com/api/v1/schemas/invoice \
  -H "Authorization: Bearer mldxt_..."
```

**Response**

```json
{
  "status": "ok",
  "id": "cm7schema",
  "name": "Invoice",
  "slug": "invoice",
  "keyCount": 7,
  "createdAt": "2026-10-26T00:00:00.000Z",
  "updatedAt": "2026-10-26T00:00:00.000Z",
  "schema": {
    "type": "object",
    "properties": {
      "vendor": {
        "type": "string"
      },
      "invoiceNumber": {
        "type": "string"
      },
      "issued": {
        "type": "date"
      },
      "total": {
        "type": "number"
      },
      "lineItems": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "description": {
              "type": "string"
            },
            "amount": {
              "type": "number"
            }
          },
          "required": [
            "description",
            "amount"
          ]
        }
      }
    },
    "required": [
      "vendor",
      "invoiceNumber",
      "total"
    ]
  }
}
```

### Create a schema

`POST /api/v1/schemas`

Save an extraction schema in this workspace. The slug is derived from the display name.

**Request body (JSON)**

| Key | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | Display name: letters, digits, spaces, underscore, and hyphen, up to 80 characters. The API slug is lowercase with underscores. |
| `schema` | object | Yes | The schema definition (JSON key name is schema). See Schema format for the key types and limits. |

- Two display names that produce the same slug (case and spacing ignored) are treated as duplicates.
- 201 returns the saved schema, including its definition.
- A duplicate returns 409 with status "error" and message "A schema with that name already exists in this workspace.".
- A Free workspace can save 10 saved schemas. A paid workspace can save 100. Past that, the status is 409.

**Request**

```bash
curl -X POST https://doxtract.manoonlabs.com/api/v1/schemas \
  -H "Authorization: Bearer mldxt_..." \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Invoice",
  "schema": {
    "type": "object",
    "properties": {
      "vendor": {
        "type": "string"
      },
      "invoiceNumber": {
        "type": "string"
      },
      "issued": {
        "type": "date"
      },
      "total": {
        "type": "number"
      },
      "lineItems": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "description": {
              "type": "string"
            },
            "amount": {
              "type": "number"
            }
          },
          "required": [
            "description",
            "amount"
          ]
        }
      }
    },
    "required": [
      "vendor",
      "invoiceNumber",
      "total"
    ]
  }
}'
```

**Response**

```json
{
  "status": "ok",
  "id": "cm7schema",
  "name": "Invoice",
  "slug": "invoice",
  "keyCount": 7,
  "createdAt": "2026-10-26T00:00:00.000Z",
  "updatedAt": "2026-10-26T00:00:00.000Z",
  "schema": {
    "type": "object",
    "properties": {
      "vendor": {
        "type": "string"
      },
      "invoiceNumber": {
        "type": "string"
      },
      "issued": {
        "type": "date"
      },
      "total": {
        "type": "number"
      },
      "lineItems": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "description": {
              "type": "string"
            },
            "amount": {
              "type": "number"
            }
          },
          "required": [
            "description",
            "amount"
          ]
        }
      }
    },
    "required": [
      "vendor",
      "invoiceNumber",
      "total"
    ]
  }
}
```

### Update a schema

`PATCH /api/v1/schemas/{slug}`

Change the display name and/or definition. Renaming updates the slug to match.

**Request body (JSON)**

| Key | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | One of | New display name, same rules as create. At most 80 characters. |
| `schema` | object | One of | The new schema definition (JSON key name is schema). It replaces the old one. |

- The path is the current slug, URL-encoded as one segment.
- Send name, schema, or both. Sending neither returns 400.
- 200 returns the schema after the change.
- A duplicate slug returns 409. A missing schema returns 404.

**Request**

```bash
curl -X PATCH https://doxtract.manoonlabs.com/api/v1/schemas/invoice \
  -H "Authorization: Bearer mldxt_..." \
  -H "Content-Type: application/json" \
  -d '{
  "schema": {
    "type": "object",
    "properties": {
      "total": {
        "type": "number"
      }
    }
  }
}'
```

**Response**

```json
{
  "status": "ok",
  "id": "cm7schema",
  "name": "Invoice",
  "slug": "invoice",
  "keyCount": 1,
  "createdAt": "2026-10-26T00:00:00.000Z",
  "updatedAt": "2026-10-26T00:00:00.000Z",
  "schema": {
    "type": "object",
    "properties": {
      "total": {
        "type": "number"
      }
    }
  }
}
```
