Skip to main content

Update Classifier

Modify an existing Classifier — update its name, label set, model, or page range. Only the fields you include in the request body are updated; omitted fields retain their current values.

API Endpoint

PUT https://api.documentpro.ai/v1/classifiers/{classifier_id}

Path Parameters

  • classifier_id (required): The unique identifier of the Classifier to update.

Headers

  • x-api-key (required): Your API key for authentication.
  • Content-Type: application/json

Request Body

Same flat body as Create Classifier — fields are not nested under a configs object. All fields are optional; include only the fields you want to change. If you include classes, it replaces the entire array (it is not merged with the existing labels).

FieldTypeDescription
namestringNew name for the classifier.
classesarrayReplaces the full label list. Each item: label, description, optional template_id. See Create Classifier for field details.
default_template_idstringFallback extraction template for unmapped or low-confidence classifications.
min_confidencenumber (0.0–1.0)Confidence threshold below which routing falls back to default_template_id.
classifier_typestring"document" (default).
query_modelstring"gpt-4o-mini" or "gpt-4o". Invalid values return 400.
use_ocrbooleanDefaults to true.
page_rangestringe.g. "1-2".

Example Implementation

Using cURL

curl --location --request PUT 'https://api.documentpro.ai/v1/classifiers/f47ac10b-58cc-4372-a567-0e02b2c3d479' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"name": "Document Type Router v2",
"classes": [
{ "label": "invoice", "description": "A document requesting payment for goods or services rendered", "template_id": "tmpl_invoice" },
{ "label": "purchase_order", "description": "A buyer-issued document authorizing a purchase from a supplier", "template_id": "tmpl_po" },
{ "label": "contract", "description": "A legally binding agreement between two or more parties" },
{ "label": "receipt", "description": "A confirmation of payment already made" },
{ "label": "other", "description": "Any document that does not fit the above categories" }
],
"default_template_id": "tmpl_generic",
"min_confidence": 0.6,
"query_model": "gpt-4o"
}'

Using Python

import requests
import json

classifier_id = "f47ac10b-58cc-4372-a567-0e02b2c3d479"
url = f"https://api.documentpro.ai/v1/classifiers/{classifier_id}"

headers = {
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
}

payload = {
"name": "Document Type Router v2",
"classes": [
{ "label": "invoice", "description": "A document requesting payment for goods or services rendered", "template_id": "tmpl_invoice" },
{ "label": "purchase_order", "description": "A buyer-issued document authorizing a purchase from a supplier", "template_id": "tmpl_po" },
{ "label": "contract", "description": "A legally binding agreement between two or more parties" },
{ "label": "receipt", "description": "A confirmation of payment already made" },
{ "label": "other", "description": "Any document that does not fit the above categories" }
],
"default_template_id": "tmpl_generic",
"min_confidence": 0.6,
"query_model": "gpt-4o"
}

response = requests.put(url, headers=headers, data=json.dumps(payload))

if response.status_code == 200:
result = response.json()
print(f"Classifier updated: {result['name']}")
else:
print('Failed to update classifier')
print(response.text)

Response

Successful Response (Status Code: 200)

{
"classifier_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"name": "Document Type Router v2",
"user_id": "4449b25a-9bba-4de4-be67-c06233d2f305",
"configs": {
"classifier_type": "document",
"classes": [
{ "label": "invoice", "description": "A document requesting payment for goods or services rendered", "template_id": "tmpl_invoice" },
{ "label": "purchase_order", "description": "A buyer-issued document authorizing a purchase from a supplier", "template_id": "tmpl_po" },
{ "label": "contract", "description": "A legally binding agreement between two or more parties" },
{ "label": "receipt", "description": "A confirmation of payment already made" },
{ "label": "other", "description": "Any document that does not fit the above categories" }
],
"default_template_id": "tmpl_generic",
"min_confidence": 0.6,
"query_model": "gpt-4o",
"page_range": "1-2",
"use_ocr": true
},
"created_at": "2024-07-25T14:16:44.540197",
"updated_at": "2024-08-01T09:22:11.381004"
}

Error Response (Status Codes: 400, 403, 404, 500)

{
"success": false,
"error": "error_code",
"message": "descriptive error message"
}

Next Steps