Intuitive AI API¶
The V1_IntuitiveAIAPI group of the KnowledgeLake REST API reads and changes Intuitive AI classes from your own code. Use it to create classes in bulk, add training documents, and review or update Auto Extraction field hints across many classes at once. The older V1_LearnAPI group is legacy; do not use it for new work.
At a glance
- Endpoint
POST https://{tenant}/api/V1_IntuitiveAIAPI/{Action}with a JSON body (AddDocumentFiletakes multipart form data) - Auth
TempIdentityTokenheader. See API Authentication. - Token feature
openapi_api_ft_manage_fingerprints, for every action in this group - Best for Bulk hint reviews, bulk class set-up, loading training documents
Before you call it¶
- Success HTTP 200 with
{ "Success": true, "MessageKey": ..., "Data": ... }. - Application error HTTP 412 with details in
Messages. Always checkSuccess. - Token Acts as the user who created it. Use a service account that may change Intuitive AI classes.
Actions¶
| Action | What it does |
|---|---|
CreateNewClass |
Creates a class and returns its id. Optional content type and Zero-Shot Classifier set-up. |
GetAllKnownClassInformation |
Lists every class with its subclasses and training documents. No body. |
GetClass |
Returns one class with its template (rules, zones) and class-level training documents |
GetSubclass |
Returns one subclass with its template |
GetDefaultRuleAutoExtractionAction |
Returns the Auto Extraction action on the Default Rule of a class or subclass |
SetDefaultRuleAutoExtractionAction |
Replaces the Auto Extraction settings on the Default Rule |
AddDocumentFile |
Adds a training document (PDF or TIFF), with optional correct values for extraction examples |
Request bodies¶
CreateNewClass¶
{
"Name": "Vendor Invoice",
"Tags": ["AP"],
"ContentTypeId": "6f1c2e3d-4b5a-4c7d-8e9f-0a1b2c3d4e5f",
"SkipConfiguringZeroShot": false
}
Tags, ContentTypeId and SkipConfiguringZeroShot are optional. With a ContentTypeId, the class gets a Default Rule that sets the content type and an Auto Extraction action for the content type's fields. It also gets a Zero-Shot Classifier condition, unless SkipConfiguringZeroShot is true. Data is the new class id.
GetClass and GetSubclass¶
GetDefaultRuleAutoExtractionAction¶
{
"ClassId": "a1b2c3d4-0000-4000-8000-000000000001",
"SubclassId": "a1b2c3d4-0000-4000-8000-000000000002"
}
Data is the action, or null if the Default Rule has no Auto Extraction action. The settings are in Data.AutoExtractorSettings:
{
"FieldDefinitions": [
{
"MetadataKey": "Invoice Total",
"ConfiguredUI": { "UIKind": "Number", "UIConfig": null },
"AIHint": "The total amount due on the invoice.",
"HighConfThresh": 0.93
}
],
"ExtractorMode": "TextOnly"
}
- ExtractorMode
TextOnly,StructuredTextorImageOnly. - HighConfThresh A fraction (0.93), not a percent. A null or 0 threshold uses the default, 0.93.
- Table columns Stored in
ConfiguredUI.UIConfigas items whoseKeystarts withcolumn__and whoseValueis a JSON field definition.
SetDefaultRuleAutoExtractionAction¶
{
"ClassId": "a1b2c3d4-0000-4000-8000-000000000001",
"SubclassId": "a1b2c3d4-0000-4000-8000-000000000002",
"Config": { "FieldDefinitions": [ ], "ExtractorMode": "TextOnly" }
}
- Config Replaces the whole Auto Extraction configuration. Send every field, not only the ones you changed.
- No Auto Extraction action The call adds one to the Default Rule.
- No Default Rule The call fails with "Class or subclass has no default interaction".
AddDocumentFile (multipart form data)¶
| Part | Value |
|---|---|
ClassId |
The class id |
SubclassId |
Optional subclass id |
File |
The PDF or TIFF file |
FileName |
The file name with extension |
mimeType |
application/pdf or image/tiff |
CorrectExtractedValues |
Optional JSON object of field name to correct value. Auto Extraction uses these as examples. |
OcrData |
Optional OCR for the file |
The call fails if another user has the class locked.
Sample: review and update the hints of a class¶
This script finds a class by name, prints its Auto Extraction hints, updates one field's hint and threshold, and writes the full configuration back. Set the environment variable KL_TOKEN to your token first.
import os
import requests
TENANT = "https://your-tenant.example.com"
HEADERS = {"TempIdentityToken": os.environ["KL_TOKEN"], "Content-Type": "application/json"}
def call(action, body=None):
url = f"{TENANT}/api/V1_IntuitiveAIAPI/{action}"
response = requests.post(url, json=body if body is not None else {}, headers=HEADERS, timeout=60)
payload = response.json()
if response.status_code != 200 or not payload.get("Success"):
raise RuntimeError(f"{action} failed: HTTP {response.status_code} {payload}")
return payload.get("Data")
classes = call("GetAllKnownClassInformation")
target = next(c for c in classes if c["Name"] == "AR Document")
request = {"ClassId": target["Id"]}
if target.get("Subclasses"):
# With subclasses, always name the one you mean.
request["SubclassId"] = target["Subclasses"][0]["Id"]
action = call("GetDefaultRuleAutoExtractionAction", request)
if action is None:
raise RuntimeError("The Default Rule has no Auto Extraction action")
settings = action["AutoExtractorSettings"]
for field in settings["FieldDefinitions"]:
print(f'{field["MetadataKey"]}: {field.get("AIHint")!r} threshold={field.get("HighConfThresh")}')
if field["MetadataKey"] == "Amount Due":
field["AIHint"] = (
"The total amount the customer must pay now. "
"On a statement it is labeled Balance Due. "
"Do not use a line-item amount. "
"Return a number with two decimals and no currency symbol."
)
field["HighConfThresh"] = 0.95
call("SetDefaultRuleAutoExtractionAction", {**request, "Config": settings})
print("Updated")
$Tenant = "https://your-tenant.example.com"
$Headers = @{ "TempIdentityToken" = $env:KL_TOKEN }
function Invoke-KL([string]$Action, $Body) {
$uri = "$Tenant/api/V1_IntuitiveAIAPI/$Action"
$json = if ($null -eq $Body) { "{}" } else { $Body | ConvertTo-Json -Depth 20 }
try {
$response = Invoke-RestMethod -Method Post -Uri $uri -Headers $Headers -ContentType "application/json" -Body $json
} catch {
throw "$Action failed: $($_.Exception.Message) $($_.ErrorDetails.Message)"
}
if (-not $response.Success) { throw "$Action failed: $($response | ConvertTo-Json -Depth 5)" }
return $response.Data
}
$classes = Invoke-KL "GetAllKnownClassInformation" $null
$target = $classes | Where-Object { $_.Name -eq "AR Document" } | Select-Object -First 1
$request = @{ ClassId = $target.Id }
if ($target.Subclasses -and $target.Subclasses.Count -gt 0) {
# With subclasses, always name the one you mean.
$request.SubclassId = $target.Subclasses[0].Id
}
$action = Invoke-KL "GetDefaultRuleAutoExtractionAction" $request
if ($null -eq $action) { throw "The Default Rule has no Auto Extraction action" }
$settings = $action.AutoExtractorSettings
foreach ($field in $settings.FieldDefinitions) {
Write-Output ("{0}: {1} threshold={2}" -f $field.MetadataKey, $field.AIHint, $field.HighConfThresh)
if ($field.MetadataKey -eq "Amount Due") {
$field.AIHint = "The total amount the customer must pay now. On a statement it is labeled Balance Due. Do not use a line-item amount. Return a number with two decimals and no currency symbol."
$field.HighConfThresh = 0.95
}
}
$request.Config = $settings
Invoke-KL "SetDefaultRuleAutoExtractionAction" $request | Out-Null
Write-Output "Updated"
Gotchas¶
Watch out
- Pass
SubclassIdwhen a class has subclasses. Without it, the Get and Set actions use the first template stored for the class, which can be a subclass template. - Set replaces everything. A
Configwith one field deletes the other fields from the action. Always read, change and write back the full list. - Thresholds are fractions in the API. The class builder shows percent (93). The API stores 0.93. A value of 93 in the API means nothing is ever high confidence.
- Set does not check the class lock. Coordinate with anyone who has the class open in the class builder, or their save can overwrite your change.
- HTTP 412 is an application error. Read
Messagesfor the reason. The published spec lists 400 for errors, but the server returns 412.