Paxa Labs

สกัดฟิลด์จากเอกสาร

POSThttps://api.paxalabs.com/v1/extract

POST /v1/extract อ่านไฟล์ PDF หรือรูปภาพ แล้วเติมค่าลงสคีมาของฟิลด์ที่ระบุชนิด แต่ละค่าคือข้อความที่พิมพ์อยู่ในเอกสาร หรือ null พร้อมเหตุผล คิดเครดิตรายหน้าตามจำนวนฟิลด์ย่อยของสคีมาก่อนอ่าน และคืนให้เมื่อล้มเหลว

ดูเป็น Markdown
# Encode without line wrapping: wrapped base64 breaks the JSON string.
DOC=$(base64 < invoice.pdf | tr -d '\n')
# --max-time covers a multi-page document; curl defaults to no limit.
curl -X POST https://api.paxalabs.com/v1/extract \
  --max-time 300 \
  -H "Authorization: Bearer $PAXA_API_KEY" \
  -H "Content-Type: application/json" \
  -d @- <<EOF
{
  "document": "$DOC",
  "model": "paxa-doc-extract-v1",
  "schema": {
    "fields": {
      "seller": {
        "type": "string",
        "required": true,
        "description": "The shop name as printed at the top"
      },
      "total": {
        "type": "number",
        "required": true
      },
      "issued_on": {
        "type": "date"
      },
      "items": {
        "type": "array",
        "max_items": 5,
        "items": {
          "type": "object",
          "fields": {
            "name": {
              "type": "string"
            },
            "amount": {
              "type": "number"
            }
          }
        }
      }
    }
  }
}
EOF
{
  "status": "complete",
  "fields": {
    "seller": "ร้านข้าวแกงบ้านสวน สาขาสีลม",
    "total": 70,
    "issued_on": null,
    "items": [
      {
        "name": "ข้าวแกงเขียวหวานไก่",
        "amount": 60
      },
      {
        "name": "น้ำเปล่า",
        "amount": 10
      }
    ]
  },
  "missing": [],
  "unverified": [],
  "truncated": [],
  "assumed": [],
  "usage": {
    "pages": 1,
    "leaves": 13,
    "credits": 13
  }
}

ส่งไฟล์เป็น base64 ในฟิลด์ document และส่งฟิลด์ที่ต้องการเป็น schema รูปภาพนับเป็นหนึ่งหน้า คู่มือ Document Extraction อธิบายภาษาสคีมา ชนิดฟิลด์ทุกชนิด กฎการนับฟิลด์ย่อย และวิธีอ่าน missing unverified truncated และ assumed สคีมาที่อยู่นอกภาษาสคีมาตอบ 400 schema_invalid พร้อม path และ reason โดยไม่คิดเครดิต

เฮดเดอร์#

authorizationBearer pxa_...จำเป็น

Authorization: Bearer pxa_... (recommended).

x-api-keypxa_...

Alternative to the Authorization header. Ignored when Authorization is present.

idempotency-keystring

Makes a retry safe. Two requests carrying the same key charge once and synthesize the same content. One request per key runs at a time. A concurrent duplicate answers 409 idempotency_in_flight. Reuse a key only to retry an identical request. A changed payload is rejected with 422. Accepts up to 200 printable ASCII characters.

1 to 200 characterspattern ^[!-~]+$

การยืนยันตัวตน

เนื้อหา#

documentstringจำเป็น

The document to extract from, as the base64 encoding of a PDF, PNG, JPEG, or WebP file. An image counts as one page. Cost is 13 credits per page for a schema of up to 50 leaf fields and 19.5 credits per page beyond that, charged before extraction and refunded automatically when extraction fails. A PDF may carry up to 20 pages, and more answers 400 too_many_pages. The decoded file may be up to 10,485,760 bytes, and larger answers 413 document_too_large. A file that cannot be read as one of the four formats answers 400 document_invalid, and a PDF that needs a password to open answers 400 document_password_required. Send one document per request. A file holding several documents gets one object, with no promise which document it describes. GET /v1/models reports the ceilings as max_pages, max_bytes, and max_leaves.

1 to 41,000,000 characters
modelstringจำเป็น

Extraction model id, for example paxa-doc-extract-v1. The id is the contract version: the dialect, the response shape, and the leaf-counting rule are fixed under it, and a change ships as a new id served beside it. GET /v1/models lists the served catalog.

1 to 100 charactersตัวอย่าง "paxa-doc-extract-v1"
schemaobjectจำเป็น

The fields to extract, as an object with one key, fields, mapping each field name to its definition. A definition carries a type, an optional required flag, an optional description of up to 200 characters the model reads, and the keys its type offers. Leaf types: "string", "integer", "number", "date", "time", "enum", "id", "thai_id", "email", "phone", "postal_code", "province", "bank", "insurer", "card_scheme", "payment_method", "legal_form", "currency", "unit", "amount_words". Containers: "object" with its own fields, and "array" with items (a leaf or an object) and a required max_items of 1 to 200. Names are 1 to 64 characters of letters, digits, and underscores. At most 3 containers sit below the root. An array holds leaves or objects, and an array inside an array is refused. The schema's leaf count is every leaf once plus every leaf inside an array once per element the array is sized for, and it must stay within the model's max_leaves. A schema outside the dialect answers 400 schema_invalid with the offending path and a reason, uncharged. A serialized schema over 131,072 bytes answers the same code with reason too_large. The Document Extraction guide is the full reference for every type, its keys, and its delivered form.

include_pagesboolean

true adds a pages array to the response: the text read from each page as GitHub-flavored Markdown, the reading the fields were extracted from, at no extra charge. Omitted, the response carries the fields alone.

ค่าเริ่มต้น false
include_evidenceboolean

true adds an evidence object to the response, mapping each field path to the printed span its value was read from, whether or not a value could be read from it. Costs nothing extra. Omitted, the response carries no spans.

ค่าเริ่มต้น false

การตอบกลับ#

The filled-in schema.

status"complete" or "incomplete"จำเป็น

"complete" when every required field carries a value, "incomplete" otherwise. Computed from the fields alone. A file that is not what the schema describes comes back "incomplete" with most required fields in missing, which is the wrong-document signal.

fieldsobjectจำเป็น

Your schema's tree with plain values. A string field carries the printed text and a number or integer field a number. A date is ISO YYYY-MM-DD and a time is 24-hour HH:MM, with seconds when printed. An enum carries one listed value, and a closed-set field the form its format asked for. Null wherever nothing was read. Every value is a span printed in the document, or null. Nothing is inferred, computed, or looked up.

missingarray of stringsจำเป็น

Every required field delivered as null, for any reason.

unverifiedarray of objectsจำเป็น

Every field delivered as null because its span could not be read as the field's type, each with its reason. Empty when every value stood.

ดูฟิลด์ย่อย
unverified[].pathstringจำเป็น

The field delivered as null. Paths are in dot form, array elements indexed: "items[2].amount".

unverified[].reasonstringจำเป็น

Why the span could not stand as the field's value: one of not_in_readout, not_as_printed, no_number, ambiguous_number, not_an_integer, no_date, ambiguous_date, no_time, ambiguous_time, not_an_enum_value, ambiguous_match, not_13_digits, bad_checksum, wrong_digit_count, not_an_email, not_a_phone, not_a_postal_code, no_amount_words, below_min, above_max, too_many_decimals, too_short, too_long, pattern_mismatch, before_min, after_max, in_the_future. The Document Extraction reference states each one.

truncatedarray of stringsจำเป็น

Every array whose document carried more elements than it was sized for. The first max_items elements are in fields, in reading order. Raise max_items to read the rest. Empty when every array fit.

assumedarray of objectsจำเป็น

Every date whose year was printed with two digits, with the digits and the year delivered. Always present and empty when nothing was assumed. A caller who would rather decide the era reads it here.

ดูฟิลด์ย่อย
assumed[].pathstringจำเป็น

The date field. Paths are in dot form, array elements indexed: "items[2].amount".

assumed[].printedstringจำเป็น

The two digits of the year as printed, for example "69".

assumed[].read_asintegerจำเป็น

The four-digit year delivered in the field, in the Common Era.

evidenceobject

Field path to the printed span the value was read from, for every field whose span the reading carries. Present when the request set include_evidence to true.

pagesarray of objects

One entry per page of the document, in page order. The fields were extracted from this reading. Present when the request set include_pages to true.

ดูฟิลด์ย่อย
pages[].pageintegerจำเป็น

Page number, starting at 1. An image request has exactly one page.

pages[].markdownstringจำเป็น

The page's content as GitHub-flavored Markdown, in reading order. The fields were read from this text.

usageobjectจำเป็น

What the request was billed for.

ดูฟิลด์ย่อย
usage.pagesintegerจำเป็น

Pages this request was billed for.

usage.leavesintegerจำเป็น

The schema's leaf count, which decides the per-page rate: up to 50 bills at credits_per_page, more at large_schema_credits_per_page.

usage.creditsnumberจำเป็น

What this delivery cost, in credits, exact to a hundredth. An idempotent replay reports the ORIGINAL request's charge, since that one charge is what paid for this delivery too; your balance moves only once.

ข้อผิดพลาด#

400validationThe request body or headers failed validation against the endpoint schema.
400unknown_modelThe model field does not name a served model.
400schema_invalidThe extraction schema is outside the dialect. The problem body carries two extra fields: path, the offending field in dot form (empty for the schema as a whole), and reason, one stable code from the schema reasons list. Nothing was charged.
400document_invalidThe document field could not be read as a PDF, PNG, JPEG, or WebP file. A damaged or truncated PDF answers this code. Nothing was charged.
400document_password_requiredThe PDF needs a password to open. A PDF that carries permissions-only encryption, the kind that opens without being asked for a password, is read normally. Nothing was charged.
413document_too_largeThe decoded document exceeds the model's size ceiling. Nothing was charged.
400too_many_pagesThe document has more pages than the model's per-request ceiling. Nothing was charged.
401unauthorizedThe request carried no API key, or the key is invalid or disabled.
402insufficient_creditsThe account does not have enough credits for this request. Nothing was charged.
403key_limitThis API key reached its spending cap. Nothing was charged.
409idempotency_in_flightAnother request with this Idempotency-Key is in flight right now.
409idempotency_refundedThe original request under this Idempotency-Key failed and was refunded.
422idempotency_mismatchThis Idempotency-Key was already used for a different request.
422content_blockedThe upstream safety system declined to process this content. The charge was refunded.
429rate_limitedRequests per minute for the plan are exhausted. One window covers the whole account, across every product and every key.
429concurrency_limitedThe account holds the plan's full count of concurrent requests for this product. Nothing was charged. Each product is limited separately, and an open live connection holds one speech slot.
500internalRequest state was inconsistent on the server.
502provider_errorModel inference failed after the request was charged.
503provider_unavailableThe model behind this endpoint is not available right now. Nothing was charged.