Skip to content

Llm.Extract ​

Overview ​

Available Operations ​

extract ​

Extracts structured data from files using a custom inline JSON schema.

Example Usage ​

typescript
import { SDK } from "@meetkai/mka1";
import { openAsBlob } from "node:fs";

const sdk = new SDK({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await sdk.llm.extract.extract({
    requestBody: {
      model: "meetkai:functionary-urdu-mini-pak",
      schema: "[object Object]",
      file: await openAsBlob("example.file"),
      prompt: "Extract invoice number, vendor, total, and date from this invoice.",
    },
  });

  console.log(result);
}

run();

Standalone function ​

The standalone function version of this method:

typescript
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmExtractExtract } from "@meetkai/mka1/funcs/llmExtractExtract.js";
import { openAsBlob } from "node:fs";

// 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, {
    requestBody: {
      model: "meetkai:functionary-urdu-mini-pak",
      schema: "[object Object]",
      file: await openAsBlob("example.file"),
      prompt: "Extract invoice number, vendor, total, and date from this invoice.",
    },
  });
  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.

tsx
import {
  // Mutation hook for triggering the API call.
  useLlmExtractExtractMutation
} from "@meetkai/mka1/react-query/llmExtractExtract.js";

Parameters ​

ParameterTypeRequiredDescription
requestoperations.ExtractRequest✔️The request object to use for the request.
optionsRequestOptions➖Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit➖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.retriesRetryConfig➖Enables retrying HTTP requests under certain failure conditions.

Response ​

Promise<components.ExtractionResponse>

Errors ​

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*

createSchema ​

Creates and stores a reusable JSON Schema template for structured data extraction.

Example Usage ​

typescript
import { SDK } from "@meetkai/mka1";

const sdk = new SDK({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await sdk.llm.extract.createSchema({
    extractionSchema: {
      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",
        ],
      },
      metadata: {
        "document_type": "invoice",
      },
    },
  });

  console.log(result);
}

run();

Standalone function ​

The standalone function version of this method:

typescript
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, {
    extractionSchema: {
      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",
        ],
      },
      metadata: {
        "document_type": "invoice",
      },
    },
  });
  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.

tsx
import {
  // Mutation hook for triggering the API call.
  useLlmExtractCreateSchemaMutation
} from "@meetkai/mka1/react-query/llmExtractCreateSchema.js";

Parameters ​

ParameterTypeRequiredDescription
requestoperations.CreateExtractSchemaRequest✔️The request object to use for the request.
optionsRequestOptions➖Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit➖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.retriesRetryConfig➖Enables retrying HTTP requests under certain failure conditions.

Response ​

Promise<components.SchemaCreateResponse>

Errors ​

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*

getSchema ​

Retrieve a stored extraction schema and its metadata.

Example Usage ​

typescript
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: "schema_invoice_123",
  });

  console.log(result);
}

run();

Standalone function ​

The standalone function version of this method:

typescript
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: "schema_invoice_123",
  });
  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.

tsx
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 ​

ParameterTypeRequiredDescription
requestoperations.GetExtractSchemaRequest✔️The request object to use for the request.
optionsRequestOptions➖Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit➖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.retriesRetryConfig➖Enables retrying HTTP requests under certain failure conditions.

Response ​

Promise<components.SchemaGetResponse>

Errors ​

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*

updateSchema ​

Update an existing extraction schema and its metadata.

Example Usage ​

typescript
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: "schema_invoice_123",
    requestBody: {
      name: "Invoice Extraction v2",
      metadata: {
        "document_type": "invoice",
        "version": "2",
      },
    },
  });

  console.log(result);
}

run();

Standalone function ​

The standalone function version of this method:

typescript
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: "schema_invoice_123",
    requestBody: {
      name: "Invoice Extraction v2",
      metadata: {
        "document_type": "invoice",
        "version": "2",
      },
    },
  });
  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.

tsx
import {
  // Mutation hook for triggering the API call.
  useLlmExtractUpdateSchemaMutation
} from "@meetkai/mka1/react-query/llmExtractUpdateSchema.js";

Parameters ​

ParameterTypeRequiredDescription
requestoperations.UpdateExtractSchemaRequest✔️The request object to use for the request.
optionsRequestOptions➖Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit➖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.retriesRetryConfig➖Enables retrying HTTP requests under certain failure conditions.

Response ​

Promise<components.SchemaUpdateResponse>

Errors ​

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*

deleteSchema ​

Remove a stored extraction schema.

Example Usage ​

typescript
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: "schema_invoice_123",
  });

  console.log(result);
}

run();

Standalone function ​

The standalone function version of this method:

typescript
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: "schema_invoice_123",
  });
  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.

tsx
import {
  // Mutation hook for triggering the API call.
  useLlmExtractDeleteSchemaMutation
} from "@meetkai/mka1/react-query/llmExtractDeleteSchema.js";

Parameters ​

ParameterTypeRequiredDescription
requestoperations.DeleteExtractSchemaRequest✔️The request object to use for the request.
optionsRequestOptions➖Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit➖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.retriesRetryConfig➖Enables retrying HTTP requests under certain failure conditions.

Response ​

Promise<components.SchemaDeleteResponse>

Errors ​

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*

extractWithSchema ​

Extracts structured data from files using a previously saved extraction schema template.

Example Usage ​

typescript
import { SDK } from "@meetkai/mka1";
import { openAsBlob } from "node:fs";

const sdk = new SDK({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await sdk.llm.extract.extractWithSchema({
    schemaId: "schema_invoice_123",
    requestBody: {
      model: "meetkai:functionary-urdu-mini-pak",
      file: await openAsBlob("example.file"),
      prompt: "Extract the structured invoice fields.",
    },
  });

  console.log(result);
}

run();

Standalone function ​

The standalone function version of this method:

typescript
import { SDKCore } from "@meetkai/mka1/core.js";
import { llmExtractExtractWithSchema } from "@meetkai/mka1/funcs/llmExtractExtractWithSchema.js";
import { openAsBlob } from "node:fs";

// 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: "schema_invoice_123",
    requestBody: {
      model: "meetkai:functionary-urdu-mini-pak",
      file: await openAsBlob("example.file"),
      prompt: "Extract the structured invoice fields.",
    },
  });
  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.

tsx
import {
  // Mutation hook for triggering the API call.
  useLlmExtractExtractWithSchemaMutation
} from "@meetkai/mka1/react-query/llmExtractExtractWithSchema.js";

Parameters ​

ParameterTypeRequiredDescription
requestoperations.ExtractWithSchemaRequest✔️The request object to use for the request.
optionsRequestOptions➖Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit➖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.retriesRetryConfig➖Enables retrying HTTP requests under certain failure conditions.

Response ​

Promise<components.ExtractionResponse>

Errors ​

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*