---
title: "Infer Schema from File"
method: POST
path: "/v3/infer-schema"
tags: ["Schema Inference"]
---

# Infer Schema from File

`POST /v3/infer-schema`

**Analyze a file and infer a JSON Schema from its contents.**

Accepts a file via multipart form upload and uses Gemini to analyze the document,
returning a description of its contents, an inferred JSON Schema capturing all
extractable fields, and document classification metadata.

The returned schema is designed to be reusable across many similar documents of the
same type, not just the specific file uploaded. It can be used directly as the
`outputSchema` when creating a Transform function.

The endpoint also detects whether the file contains multiple bundled documents
and classifies the content nature (textual, visual, audio, video, or mixed).

## Supported file types

PDF, PNG, JPEG (including JFIF), HEIC, HEIF, WebP, CSV, XLS, XLSX, DOCX, JSON,
HTML, XML, EML, plain text, WAV, MP3, M4A, MP4.

## File size limit

Maximum file size is **20 MB**.

## Examples

Using curl:
```bash
curl -X POST https://api.bem.ai/v3/infer-schema \
  -H "x-api-key: YOUR_API_KEY" \
  -F "file=@invoice.pdf"
```

Using the Bem CLI:
```bash
bem infer-schema create --file @invoice.pdf
```

## Response `200`

The request has succeeded.

- InferSchemaResponseV3 — Response from the infer-schema endpoint.
  - `filename` string, required — Original filename of the uploaded file.
  - `analysis` InferSchemaAnalysis, required — Analysis result returned by the infer-schema endpoint.
    - `fileName` string, required — Original filename of the uploaded file.
    - `contentType` string, required — MIME content type of the uploaded file.
    - `sizeBytes` integer, required — Size of the uploaded file in bytes.
    - `fileType` string, required — High-level file category (e.g. "document", "image", "spreadsheet", "email").
    - `description` string, required — 2-3 sentence description of what the file contains.
    - `schema` object — Inferred JSON Schema representing all extractable data fields.
    - `isMultiDocument` boolean, required — Whether the file contains multiple separate documents bundled together.
    - `documentTypes` DocumentTypeInfo[], required — List of distinct document types found in the file with counts.
      - `name` string, required — Short snake_case name (e.g. "invoice", "receipt", "utility_bill").
      - `count` integer, required — Number of instances of this document type in the file.
      - `description` string, required — Brief description of this document type.
    - `contentNature` string, required — Classification of the primary content. One of: `textual`, `visual`, `audio`, `video`, `mixed`.

## Other responses

- `400` — The server could not understand the request due to invalid syntax.

---

[API](https://skmtc.dev/bem-team/apis/bem-api.md) · [All operations](https://skmtc.dev/bem-team/apis/bem-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/bem-team/bem-api/revisions/a6e4624117c6/schema)
