Munger Chat and OCR API (1.0.16)

Download OpenAPI specification:

This API combines the OpenAI-compatible chat endpoints from the Munger BI Agent API and the OCR Service API.

OpenAI Compatible API

Create Chat Completion

Completion api.

Authorizations:
HTTPBearer
Request Body schema: application/json
required
model
required
string (Model)

Model name

required
Array of objects (Messages)

List of messages

max_tokens
integer or null (Max Tokens)

Maximum number of tokens to generate

temperature
number or null (Temperature)

Temperature parameter

top_p
number or null (Top P)

Top-p parameter

n
integer or null (N)
Default: 1

Number of completions to generate

stream
boolean or null (Stream)
Default: false

Whether to respond in a streaming manner

(Stop (string or null)) or (Array of Stop (strings or null)) (Stop)

Stop words

presence_penalty
number or null (Presence Penalty)

Presence penalty

frequency_penalty
number or null (Frequency Penalty)

Frequency penalty

object or null (Logit Bias)

Logit bias

user
string or null (User)

User identifier

Responses

Request samples

Content type
application/json
{
  • "model": "string",
  • "messages": [
    ],
  • "max_tokens": 0,
  • "temperature": 0,
  • "top_p": 0,
  • "n": 1,
  • "stream": false,
  • "stop": "string",
  • "presence_penalty": 0,
  • "frequency_penalty": 0,
  • "logit_bias": {
    },
  • "user": "string"
}

Response samples

Content type
application/json
{
  • "detail": [
    ]
}

Authentication

Get Current User Information

Get detailed information of the currently logged-in user based on the JWT token.

Authorizations:
JWT-auth

Responses

Response samples

Content type
application/json
{
  • "id": "123e4567-e89b-12d3-a456-426614174000",
  • "email": "user@example.com",
  • "username": "john_doe",
  • "fullName": "John Doe",
  • "organizationId": "456e7890-e12b-34d5-a678-426614174001",
  • "organizationName": "Example Corp",
  • "role": "user",
  • "permissions": [
    ],
  • "createdAt": "2024-01-01T00:00:00.000Z",
  • "lastLoginAt": "2024-01-01T12:00:00.000Z",
  • "isNewUser": false
}

Validate JWT Token

Validate the provided JWT token and return the user information associated with the token.

Authorizations:
JWT-auth

Responses

Response samples

Content type
application/json
{
  • "valid": true,
  • "user": {
    },
  • "error": "Token has expired"
}

Users

Get Current User Information

Authorizations:
JWT-auth

Responses

Document Management

Generate Presigned Upload URL

Generate a presigned URL for file upload. The frontend can use this URL to upload files directly to cloud storage. Note: When uploading, be sure to set the Content-Type header to the type specified during signing.

Authorizations:
JWT-auth
Request Body schema: application/json
required
fileName
required
string

File name

fileSize
required
number [ 1 .. 52428800 ]

File size (bytes)

mimeType
required
string

File MIME type

description
string

Document description

Responses

Request samples

Content type
application/json
{
  • "fileName": "invoice-001.pdf",
  • "fileSize": 1024000,
  • "mimeType": "application/pdf",
  • "description": "January 2024 Invoice"
}

Response samples

Content type
application/json
{}

Confirm File Upload Completion

Confirm that the file has been successfully uploaded to cloud storage, set the file for public access, add it to the OCR processing queue, and return the document information including the public access link.

Authorizations:
JWT-auth
path Parameters
id
required
string

Document ID

Responses

Response samples

Content type
application/json
{}

Get Document List

Authorizations:
JWT-auth
query Parameters
page
number >= 1
Default: 1
Example: page=1

Page number

limit
number [ 1 .. 100 ]
Default: 10
Example: limit=10

Number of items per page

search
string
Example: search=Invoice

Search keyword

status
string
Enum: "uploading" "uploaded" "processing" "completed" "failed"

Filter by document status

archived
boolean
Example: archived=false

Whether to show only archived documents

documentType
string
Example: documentType=pdf

Filter by document type

createdFrom
string
Example: createdFrom=2024-01-01

Creation date range start

createdTo
string
Example: createdTo=2024-12-31

Creation date range end

Responses

Get Document Details

Authorizations:
JWT-auth
path Parameters
id
required
string

Document ID

Responses

Update Document Information

Authorizations:
JWT-auth
path Parameters
id
required
string

Document ID

Request Body schema: application/json
required
description
string

Document description

archived
boolean

Whether to archive the document

Responses

Request samples

Content type
application/json
{
  • "description": "Updated invoice description",
  • "archived": true
}

Delete Document

Delete document record and corresponding stored file.

Authorizations:
JWT-auth
path Parameters
id
required
string

Document ID

Responses

Get Document Download URL

Generate a presigned download URL for secure file download.

Authorizations:
JWT-auth
path Parameters
id
required
string

Document ID

query Parameters
expires
number
Example: expires=3600

Expiration time (seconds)

Responses

Response samples

Content type
application/json
{
  • "downloadUrl": "string"
}

Generate Extraction Template from Document

Automatically analyze the content of an uploaded file using AI and generate a structured data extraction template.

Authorizations:
JWT-auth
path Parameters
id
required
string

Document ID

Request Body schema: application/json
required

Template generation configuration

templateName
required
string

Template name

description
string

Template description

Responses

Request samples

Content type
application/json
{
  • "templateName": "Invoice Template",
  • "description": "Extracts key information from invoices"
}

Response samples

Content type
application/json
{
  • "templateId": "tpl-550e8400-e29b-41d4-a716-446655440000",
  • "message": "Template generation started"
}

OCR

Process Document OCR Recognition

Authorizations:
JWT-auth
Request Body schema: application/json
required
documentId
required
string

Document ID

webhookUrl
string

Webhook URL for receiving processing results

Responses

Request samples

Content type
application/json
{}

Response samples

Content type
application/json
{
  • "message": "OCR processing has been initiated.",
  • "documentId": "doc_clx123456789"
}

Get OCR Results for a Document

Authorizations:
JWT-auth
path Parameters
documentId
required
string

Responses

Response samples

Content type
application/json
[
  • {
    }
]

Retry Processing Failed Document

Authorizations:
JWT-auth
path Parameters
documentId
required
string

Responses

Response samples

Content type
application/json
{
  • "message": "Reprocessing has been initiated.",
  • "documentId": "doc_clx123456789"
}

Check OCR Service Health Status

Authorizations:
JWT-auth

Responses

Response samples

Content type
application/json
{
  • "status": "ok",
  • "message": "OCR service is running"
}

Card Management

Get All Cards for a Document

Get all card objects for a document by its ID, including OCR content, classification information, and processing status.

Authorizations:
JWT-auth
path Parameters
documentId
required
string
Example: clh1234567890abcdef

Unique identifier for the document.

Responses

Response samples

Content type
application/json
[
  • {
    }
]

Update Card Status

Update the processing status of a specific card, used for user confirmation, rejection, or archiving.

Authorizations:
JWT-auth
path Parameters
id
required
string
Example: clh1234567890abcdef

Unique identifier for the card.

Request Body schema: application/json
required
status
string

Card status

Responses

Request samples

Content type
application/json
{
  • "status": "confirmed"
}

Response samples

Content type
application/json
{
  • "id": "card-550e8400-e29b-41d4-a716-446655440000",
  • "documentId": "doc-550e8400-e29b-41d4-a716-446655440000",
  • "ocrResultId": "ocr-550e8400-e29b-41d4-a716-446655440000",
  • "status": "pending",
  • "content": "This is a card.",
  • "classification": "invoice",
  • "createdAt": "2024-01-01T00:00:00.000Z",
  • "updatedAt": "2024-01-01T00:00:00.000Z"
}

Manually Generate Cards

Manually generate card objects based on document ID and OCR results. Supports specifying an OCR result ID or using the latest OCR result.

Authorizations:
JWT-auth
Request Body schema: application/json
required
documentId
required
string

Document ID

ocrResultId
string

OCR result ID (optional, uses latest if not provided)

Responses

Request samples

Content type
application/json
{
  • "documentId": "doc-550e8400-e29b-41d4-a716-446655440000",
  • "ocrResultId": "ocr-550e8400-e29b-41d4-a716-446655440000"
}

Response samples

Content type
application/json
{
  • "message": "Card generation successful.",
  • "documentId": "doc_clx123456789",
  • "count": 5
}

Apply Template for Structured Extraction

Apply a prompt template to a specified document to extract structured information. This is an asynchronous operation that immediately returns an identifier for the extraction task.

Authorizations:
JWT-auth
path Parameters
documentId
required
string
Example: doc_clx123456789

Unique identifier for the document.

Request Body schema: application/json
required
templateId
required
string

Template ID

Responses

Request samples

Content type
application/json
{
  • "templateId": "tpl-550e8400-e29b-41d4-a716-446655440000"
}

Response samples

Content type
application/json
{
  • "extractionId": "ext-550e8400-e29b-41d4-a716-446655440000",
  • "documentId": "doc-550e8400-e29b-41d4-a716-446655440000",
  • "status": "pending",
  • "message": "Extraction has been initiated"
}

Get All Extraction Results for a Document

Get all structured extraction history and generated cards for a specified document. The frontend can use this for grouped display.

Authorizations:
JWT-auth
path Parameters
documentId
required
string
Example: doc_clx123456789

Unique identifier for the document.

Responses

Response samples

Content type
application/json
[
  • {
    }
]

Get Extraction Status

Get the current processing status via the extraction ID, used for frontend polling to check if extraction is complete. Recommended polling interval: 2-5 seconds.

Authorizations:
JWT-auth
path Parameters
extractionId
required
string
Example: clx5aefd0000008l9g7z2h4a1

Unique identifier for the extraction result.

Responses

Response samples

Content type
application/json
{
  • "status": "completed",
  • "message": "Extraction completed successfully"
}

Get Cards from Extraction Result

Get all card details and statistics generated by this extraction via the extraction ID. It is recommended to call this interface when the status is COMPLETED.

Authorizations:
JWT-auth
path Parameters
extractionId
required
string
Example: clx5aefd0000008l9g7z2h4a1

Unique identifier for the extraction result.

Responses

Response samples

Content type
application/json
{
  • "cards": [
    ],
  • "count": 5
}

Template Management

Create New Processing Template

Create a new document processing template, including prompts and field configurations.

Authorizations:
JWT-auth
Request Body schema: application/json
required
name
required
string

Template name

prompt
required
string

Template prompt

required
Array of objects

Responses

Request samples

Content type
application/json
{
  • "name": "Invoice Template",
  • "prompt": "Extract the following fields from the invoice: ...",
  • "fields": [
    ]
}

Response samples

Content type
application/json
{
  • "id": "clx5aefd0000008l9g7z2h4a1",
  • "name": "訂單資訊提取模板",
  • "description": "適用於訂單文件的結構化資訊提取",
  • "systemPrompt": "你是一名結構化資料提取助手,負責從訂單文件中提取並整理訂單基本資料和商品資訊...",
  • "fields": [
    ],
  • "successRate": 0.95,
  • "usageCount": 42,
  • "status": "active",
  • "createdAt": "2025-07-10T10:00:00.000Z",
  • "updatedAt": "2025-07-10T11:00:00.000Z"
}

Get Template List

Get all processing templates for the current organization, with support for pagination and search.

Authorizations:
JWT-auth
query Parameters
page
number >= 1
Example: page=1

Page number

limit
number [ 1 .. 100 ]
Example: limit=10

Number of items per page

search
string
Example: search=Invoice

Search keyword

includeInactive
boolean
Example: includeInactive=false

Whether to include inactive templates.

status
string
Enum: "active" "inactive" "archived"

Filter by template status.

Responses

Response samples

Content type
application/json
{
  • "data": [
    ],
  • "total": 50,
  • "page": 1,
  • "limit": 10,
  • "totalPages": 5,
  • "hasNext": true,
  • "hasPrev": false
}

Get Template Usage Statistics

Get usage statistics for templates, including usage counts, success rates, etc.

Authorizations:
JWT-auth
query Parameters
days
number
Example: days=30

Number of days for statistics.

Responses

Response samples

Content type
application/json
[
  • {
    }
]

Get Template Details

Get detailed information for a specific template by its ID.

Authorizations:
JWT-auth
path Parameters
id
required
string
Example: clx5aefd0000008l9g7z2h4a1

Unique identifier for the template.

Responses

Response samples

Content type
application/json
{
  • "id": "clx5aefd0000008l9g7z2h4a1",
  • "name": "訂單資訊提取模板",
  • "description": "適用於訂單文件的結構化資訊提取",
  • "systemPrompt": "你是一名結構化資料提取助手,負責從訂單文件中提取並整理訂單基本資料和商品資訊...",
  • "fields": [
    ],
  • "successRate": 0.95,
  • "usageCount": 42,
  • "status": "active",
  • "createdAt": "2025-07-10T10:00:00.000Z",
  • "updatedAt": "2025-07-10T11:00:00.000Z"
}

Update Template

Update information for a specified template.

Authorizations:
JWT-auth
path Parameters
id
required
string
Example: clx5aefd0000008l9g7z2h4a1

Unique identifier for the template.

Request Body schema: application/json
required
name
string

模板名稱

description
string

模板描述

systemPrompt
string

系統提示詞

fields
Array of strings

欄位列表

status
string
Enum: "active" "inactive" "archived"

模板狀態

Responses

Request samples

Content type
application/json
{
  • "name": "更新後的訂單模板",
  • "description": "更新後的描述",
  • "systemPrompt": "string",
  • "fields": [
    ],
  • "status": "active"
}

Response samples

Content type
application/json
{
  • "id": "clx5aefd0000008l9g7z2h4a1",
  • "name": "訂單資訊提取模板",
  • "description": "適用於訂單文件的結構化資訊提取",
  • "systemPrompt": "你是一名結構化資料提取助手,負責從訂單文件中提取並整理訂單基本資料和商品資訊...",
  • "fields": [
    ],
  • "successRate": 0.95,
  • "usageCount": 42,
  • "status": "active",
  • "createdAt": "2025-07-10T10:00:00.000Z",
  • "updatedAt": "2025-07-10T11:00:00.000Z"
}

Delete Template

Delete the specified template (soft delete, sets the status to archived).

Authorizations:
JWT-auth
path Parameters
id
required
string
Example: clx5aefd0000008l9g7z2h4a1

Unique identifier for the template.

Responses

Health Check

Health Check

Responses

Response samples

Content type
application/json
{
  • "status": "ok"
}

System Metrics

Responses

Response samples

Content type
application/json
{ }