Skip to content

Document AI

Document AI uses vision models (e.g. GPT-4o) to extract structured data from PDFs and images — invoices, forms, receipts, contracts, or any document with visible text.

The SDK exposes two namespaces:

  • client.chatAi / client.chat_ai — direct document processing and model listing
  • client.documentAi / client.document_ai — agent-based document processing with schema management, agent CRUD, and end-to-end orchestration

Initialize the client first (see Installation or Quick Start).


client.chatAi — Processing Documents

Listing available models

const models = await client.chatAi.listDocumentModels();

Direct document processing

const result = await client.chatAi.processDocument({
modelName: "gpt-4o",
url: "https://example.com/invoice.pdf",
organizationId: "org_xxx",
});

Parameter reference

ParameterTS fieldPython paramTypeRequired
Model namemodelNamemodel_namestring / strYes
Document URLurlurlstring / strYes
Organization IDorganizationIdorganization_idstring / strYes
Board IDboardIdboard_idstring / strNo
Languagelanguagelanguagestring / strNo
Additional instructionsadditionalInstructionsadditional_instructionsstring / strNo
Additional document instructionsadditionalDocumentInstructionsadditional_document_instructionsstring / strNo
Process model nameprocessModelNameprocess_model_namestring / strNo
File URL to fillfileUrlToFillfile_url_to_fillstring / strNo
ToolstoolstoolsRecord<string, unknown>[] / List[Dict]No
UTC offsetutcutcnumber / intNo
Chunk sizechunkSizechunk_sizenumber / intNo
Max concurrentmaxConcurrentmax_concurrentnumber / intNo
Max retriesmaxRetriesmax_retriesnumber / intNo
Enhanced processinguseEnhancedProcessinguse_enhanced_processingboolean / boolNo

PDF form filling example

const result = await client.chatAi.processDocument({
modelName: "gpt-4o",
url: "https://example.com/blank-invoice.pdf",
organizationId: "org_xxx",
fileUrlToFill: "https://example.com/blank-invoice.pdf",
language: "en",
});
if (result.success && result.data.filledPdfUrl) {
console.log("Filled PDF:", result.data.filledPdfUrl);
}

client.documentAi — Agent CRUD

Document AI Agents store extraction schema, instructions, and model configuration for repeated use.

List agents

// All agents
const agents = await client.documentAi.listAgents();
// Filter by name
const filtered = await client.documentAi.listAgents({ nameContains: "Invoice" });
// Document AI agents only (created via createFull or webapp)
const docAiAgents = await client.documentAi.listAgents({ documentAiOnly: true });

Get agent

const agent = await client.documentAi.getAgent("agent_id");

Create agent

const agent = await client.documentAi.createAgent({
name: "Invoice Extractor",
instructions: "Extract invoice fields. Dates as YYYY-MM-DD.",
model_id: "gpt-4o",
schema: {
invoice_number: { type: "string", description: "Invoice ID" },
total: { type: "number" },
date: { type: "string", format: "date" },
},
});

Update agent

await client.documentAi.updateAgent("agent_id", {
name: "Invoice Extractor v2",
instructions: "Updated extraction logic.",
});

Delete agent

await client.documentAi.deleteAgent("agent_id");

client.documentAi — Processing with an Agent

Process a document using a configured agent (looks up model + instructions from the agent).

const result = await client.documentAi.process({
agentId: "agent_id",
url: "https://example.com/invoice.pdf",
organizationId: "org_xxx",
});

You can also override the agent’s model or instructions:

const result = await client.documentAi.process({
agentId: "agent_id",
url: "https://example.com/invoice.pdf",
organizationId: "org_xxx",
modelName: "gpt-4o", // override agent's model
instructions: "Custom prompt", // override agent's instructions
});

client.documentAi — Suggest Schema

Automatically propose a JSON schema by analyzing a sample document.

const schema = await client.documentAi.suggestSchema({
url: "https://example.com/invoice.pdf",
organizationId: "org_xxx",
modelName: "gpt-4o", // optional, defaults to "gpt-4o"
});

client.documentAi — Create Full (Orchestrator)

End-to-end Document AI agent creation (what the iMBRACE webapp does): creates a board with extraction schema, then creates a UseCase + AI Agent linked to that board.

const result = await client.documentAi.createFull({
name: "Invoice Extractor",
instructions: "Extract invoice fields. Dates as YYYY-MM-DD.",
schemaFields: [
{ name: "invoice_number", type: "ShortText", description: "Invoice ID" },
{ name: "total", type: "Number", description: "Total amount" },
{ name: "date", type: "Date", description: "Invoice date" },
],
modelId: "gpt-4o",
providerId: "system",
});
console.log(result.board_id); // "brd_xxx"
console.log(result.ai_agent_id); // UUID of the created AI Agent
console.log(result.usecase_id); // UUID of the created UseCase

Create Full options

ParameterTS fieldPython paramTypeDefault
Namenamenamestring / str
Instructionsinstructionsinstructionsstring / str
Schema fieldsschemaFieldsschema_fieldsCreateBoardFieldInput[] / List[Dict]
Model IDmodelIdmodel_idstring / str
Provider IDproviderIdprovider_idstring / str
Descriptiondescriptiondescriptionstring / strNone
VLM modelvlmModelvlm_modelstring / strmodelId
VLM providervlmProviderIdvlm_provider_idstring / strproviderId
Source languagessourceLanguagessource_languagesstring[] / List[str]["English"]
Handwriting supporthandwritingSupporthandwriting_supportboolean / boolfalse
Time offsettimeOffsettime_offsetstring / str"UTC+00:00"
Continue on failurecontinueOnFailurecontinue_on_failureboolean / boolfalse
Retry timeretryTimeretry_timenumber / int2
Temperaturetemperaturetemperaturenumber / float0.1
Demo URLdemoUrldemo_urlstring / strNone
Team IDsteamIdsteam_idsstring[] / List[str][]
Extra AI Agent fieldsextraAiAgentextra_ai_agentRecord<string, unknown> / DictNone

Async usage (Python)

from imbrace import AsyncImbraceClient
async with AsyncImbraceClient() as client:
# Direct processing (chat_ai)
models = await client.chat_ai.list_document_models()
result = await client.chat_ai.process_document(
model_name="gpt-4o",
url="https://example.com/invoice.pdf",
organization_id="org_xxx",
)
# Agent-based processing (document_ai)
agents = await client.document_ai.list_agents(document_ai_only=True)
result2 = await client.document_ai.process(
agent_id=agents[0]["_id"],
url="https://example.com/receipt.pdf",
organization_id="org_xxx",
)

See also