PerfectParser Docs

Detect Fields

Reference for the POST /v1/parsers/:id/detect-fields endpoint.

POST /v1/parsers/:id/detect-fields

Runs AI-powered layout detection on a sample document and automatically generates a JSON Schema for the parser.

Generating a schema with AI costs 1 credit per page of the sample document. Future manual modifications to the schema are free.

By default, if the parser already has a schema configured, this request returns SCHEMA_ALREADY_EXISTS. Set replace_existing_schema to true to overwrite.

Path Parameters

ParameterTypeRequiredDescription
idstringThe unique ID of the parser.

Upload a sample file and detect fields in one request using multipart/form-data.

Body Parameters (multipart)

ParameterTypeRequiredDescription
filefileSample PDF or image.
promptstringOptional hints (e.g. "focus on line items").
replace_existing_schemastring"true" to overwrite an existing schema.
curl -X POST https://api.perfectparser.com/v1/parsers/prs_999/detect-fields \
  -H "X-API-Key: pp_live_your_secret_key" \
  -F "file=@sample_invoice.pdf"

Mode B — Re-run on existing sample (JSON)

If you already uploaded a sample via Mode A, re-run detection without re-uploading:

Body Parameters (JSON)

ParameterTypeRequiredDescription
sample_file_idstringFrom a previous detect-fields response or GET /v1/parsers/:id.
promptstringOptional hints.
replace_existing_schemabooleanSet to true to overwrite (default: false).
curl -X POST https://api.perfectparser.com/v1/parsers/prs_999/detect-fields \
  -H "X-API-Key: pp_live_your_secret_key" \
  -H "Content-Type: application/json" \
  -d '{"sample_file_id": "smp_123", "replace_existing_schema": true}'

Where to get sample_file_id

  • Returned in every successful detect-fields response (sample_file_id field).
  • Available on Get Parser as parser.sample_file_id when a sample has been uploaded.

Response 200 OK

{
  "parser_id": "prs_999",
  "sample_file_id": "smp_123",
  "schema": {
    "type": "object",
    "properties": {
      "invoice_number": { "type": "string", "description": "" },
      "total_amount": { "type": "number", "description": "" }
    },
    "required": ["invoice_number", "total_amount"]
  },
  "credits_used": 3
}

Common Error Responses

HTTP StatusError CodeDescription
400INVALID_PAYLOADMissing file or sample_file_id, or malformed body.
400SCHEMA_ALREADY_EXISTSSchema exists and replace_existing_schema was not set.
401UNAUTHORIZEDInvalid or missing API key.
402INSUFFICIENT_CREDITSAccount balance too low.
404RESOURCE_NOT_FOUNDSample file not found.
404PARSER_NOT_FOUNDParser not found or belongs to another account.

On this page