Llm.Extract
Overview
Available Operations
- extract - Extract structured data with inline JSON Schema
- createSchema - Create reusable extraction schema template
- getSchema - Get extraction schema by ID
- updateSchema - Update extraction schema by ID
- deleteSchema - Delete extraction schema by ID
- extractWithSchema - Extract data using saved schema template
extract
Extract structured data from files (images, PDFs, documents) using vision-capable AI models and a custom JSON Schema. Define your extraction schema inline to specify exactly what data to extract and its structure. The model analyzes the file content and returns data conforming to your schema. Supports optional metadata for additional context and custom prompts to guide the extraction process. Ideal for one-off extractions or when schema templates aren't needed. Upload files via multipart/form-data with schema and metadata as JSON strings.
Example Usage
import { SDK } from "@meetkai/mka1";
const sdk = new SDK({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await sdk.llm.extract.extract({
model: "openai:gpt-4o",
schema: {
"type": "object",
"properties": {
"invoice_number": {
"type": "string",
},
"total_amount": {
"type": "number",
},
"date": {
"type": "string",
},
},
},
file: "<value>",
});
console.log(result);
}
run();Standalone function
The standalone function version of this method:
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmExtractExtract } from "@meetkai/mka1/funcs/llmExtractExtract.js";
// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await llmExtractExtract(sdk, {
model: "openai:gpt-4o",
schema: {
"type": "object",
"properties": {
"invoice_number": {
"type": "string",
},
"total_amount": {
"type": "number",
},
"date": {
"type": "string",
},
},
},
file: "<value>",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("llmExtractExtract failed:", res.error);
}
}
run();React hooks and utilities
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Mutation hook for triggering the API call.
useLlmExtractExtractMutation
} from "@meetkai/mka1/react-query/llmExtractExtract.js";Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | components.DirectExtractionRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.ExtractionResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.APIError | 4XX, 5XX | */* |
createSchema
Create and store a reusable JSON Schema template for structured data extraction. Define the schema structure, add a descriptive name (1-100 chars), optional description (max 500 chars), and custom metadata for your extraction use case. Once created, the schema can be referenced by ID for consistent extraction across multiple files. Useful for building libraries of extraction templates for different document types (invoices, receipts, forms, contracts, etc.). The schema is validated before storage to ensure it's a valid JSON Schema structure.
Example Usage
import { SDK } from "@meetkai/mka1";
const sdk = new SDK({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await sdk.llm.extract.createSchema({
name: "Invoice Extraction",
description: "Schema for extracting invoice data from PDF documents",
schema: {
"type": "object",
"properties": {
"invoice_number": {
"type": "string",
},
"vendor_name": {
"type": "string",
},
"total_amount": {
"type": "number",
},
"date": {
"type": "string",
"format": "date",
},
},
"required": [
"invoice_number",
"total_amount",
],
},
});
console.log(result);
}
run();Standalone function
The standalone function version of this method:
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmExtractCreateSchema } from "@meetkai/mka1/funcs/llmExtractCreateSchema.js";
// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await llmExtractCreateSchema(sdk, {
name: "Invoice Extraction",
description: "Schema for extracting invoice data from PDF documents",
schema: {
"type": "object",
"properties": {
"invoice_number": {
"type": "string",
},
"vendor_name": {
"type": "string",
},
"total_amount": {
"type": "number",
},
"date": {
"type": "string",
"format": "date",
},
},
"required": [
"invoice_number",
"total_amount",
],
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("llmExtractCreateSchema failed:", res.error);
}
}
run();React hooks and utilities
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Mutation hook for triggering the API call.
useLlmExtractCreateSchemaMutation
} from "@meetkai/mka1/react-query/llmExtractCreateSchema.js";Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | components.ExtractionSchema | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.SchemaCreateResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.APIError | 4XX, 5XX | */* |
getSchema
Retrieve a stored extraction schema and its metadata.
Example Usage
import { SDK } from "@meetkai/mka1";
const sdk = new SDK({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await sdk.llm.extract.getSchema({
schemaId: "<id>",
});
console.log(result);
}
run();Standalone function
The standalone function version of this method:
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmExtractGetSchema } from "@meetkai/mka1/funcs/llmExtractGetSchema.js";
// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await llmExtractGetSchema(sdk, {
schemaId: "<id>",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("llmExtractGetSchema failed:", res.error);
}
}
run();React hooks and utilities
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Query hooks for fetching data.
useLlmExtractGetSchema,
useLlmExtractGetSchemaSuspense,
// Utility for prefetching data during server-side rendering and in React
// Server Components that will be immediately available to client components
// using the hooks.
prefetchLlmExtractGetSchema,
// Utilities to invalidate the query cache for this query in response to
// mutations and other user actions.
invalidateLlmExtractGetSchema,
invalidateAllLlmExtractGetSchema,
} from "@meetkai/mka1/react-query/llmExtractGetSchema.js";Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.GetExtractSchemaRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.SchemaGetResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.APIError | 4XX, 5XX | */* |
updateSchema
Update an existing extraction schema and its metadata.
Example Usage
import { SDK } from "@meetkai/mka1";
const sdk = new SDK({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await sdk.llm.extract.updateSchema({
schemaId: "<id>",
requestBody: {},
});
console.log(result);
}
run();Standalone function
The standalone function version of this method:
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmExtractUpdateSchema } from "@meetkai/mka1/funcs/llmExtractUpdateSchema.js";
// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await llmExtractUpdateSchema(sdk, {
schemaId: "<id>",
requestBody: {},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("llmExtractUpdateSchema failed:", res.error);
}
}
run();React hooks and utilities
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Mutation hook for triggering the API call.
useLlmExtractUpdateSchemaMutation
} from "@meetkai/mka1/react-query/llmExtractUpdateSchema.js";Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.UpdateExtractSchemaRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.SchemaUpdateResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.APIError | 4XX, 5XX | */* |
deleteSchema
Remove a stored extraction schema.
Example Usage
import { SDK } from "@meetkai/mka1";
const sdk = new SDK({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await sdk.llm.extract.deleteSchema({
schemaId: "<id>",
});
console.log(result);
}
run();Standalone function
The standalone function version of this method:
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmExtractDeleteSchema } from "@meetkai/mka1/funcs/llmExtractDeleteSchema.js";
// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await llmExtractDeleteSchema(sdk, {
schemaId: "<id>",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("llmExtractDeleteSchema failed:", res.error);
}
}
run();React hooks and utilities
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Mutation hook for triggering the API call.
useLlmExtractDeleteSchemaMutation
} from "@meetkai/mka1/react-query/llmExtractDeleteSchema.js";Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.DeleteExtractSchemaRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.SchemaDeleteResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.APIError | 4XX, 5XX | */* |
extractWithSchema
Extract structured data from files using a previously saved extraction schema template. Reference a stored schema by ID to apply the same extraction pattern across multiple files, ensuring consistency and reusability. Perfect for repetitive extraction tasks like processing invoices, receipts, forms, or documents with standardized formats. The schema's predefined structure and metadata are automatically applied to the uploaded file. Supports custom prompts to provide file-specific instructions while maintaining the schema structure.
Example Usage
import { SDK } from "@meetkai/mka1";
const sdk = new SDK({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await sdk.llm.extract.extractWithSchema({
schemaId: "<id>",
requestBody: {
model: "Camry",
file: "<value>",
},
});
console.log(result);
}
run();Standalone function
The standalone function version of this method:
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmExtractExtractWithSchema } from "@meetkai/mka1/funcs/llmExtractExtractWithSchema.js";
// Use `SDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const sdk = new SDKCore({
bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await llmExtractExtractWithSchema(sdk, {
schemaId: "<id>",
requestBody: {
model: "Camry",
file: "<value>",
},
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("llmExtractExtractWithSchema failed:", res.error);
}
}
run();React hooks and utilities
This method can be used in React components through the following hooks and associated utilities.
Check out this guide for information about each of the utilities below and how to get started using React hooks.
import {
// Mutation hook for triggering the API call.
useLlmExtractExtractWithSchemaMutation
} from "@meetkai/mka1/react-query/llmExtractExtractWithSchema.js";Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request | operations.ExtractWithSchemaRequest | ✔️ | The request object to use for the request. |
options | RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions | RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries | RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.ExtractionResponse>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.APIError | 4XX, 5XX | */* |