Menu Close

Labdoc SDK

Labdoc SDK is a collection of tools for interacting with the Labdoc API. It provides a Query client for making API requests and a PDF parser for parsing PDF documents client side. It also provides a NextJS HOC for setting up the React Query client and the PDF parser in your NextJS app.


The Inference Client

This client leverages the power of trpc and React’s Context API to provide a simple and efficient interface for interacting with the Labdoc API. To initialize this client, you must provide an API secret key, which is used to authenticate your requests with the Labdoc API.


Setting up the Provider

To enable the usage of Labdoc API throughout your application, you first need to set up the `LabProvider` at the root level of your application. You can provide your API secret key and optional custom HTTP link `customHttpLink` as props to this provider, when a custom HTTP link is not provided, the default HTTP link `` is used.


import { LabProvider } from '@tecmie/labdoc-sdk';

<LabProvider secretOrKey="my-secret-or-key">

<App />


The `LabProvider` makes use of context to provide the necessary functions and hooks to its descendant components.

### Calling the Inference Method

The `useLabInference` hook provides an easy way to interact with the Labdoc API. Before calling the inference method, ensure that your page text is properly parsed.


import { usePDFParser, useLabInference } from '@tecmie/labdoc-sdk';

const canvasRef = useRef < HTMLCanvasElement > null;

const { document, executeUpload, parsePageText } = usePDFParser({ canvasRef });

const { query } = useLabInference();

/** Form submission handler */

const onSubmit = async (data: UploadFormOptions) => {

// Create a blob URL from the uploaded file

const blobUrl = URL.createObjectURL(data.document[0]);

// Execute the upload

await executeUpload(blobUrl);

// Parse the text on the first page

const text = await parsePageText(1);

// Call the inference method

const diagnosis = await query({ documents: [text] });

console.log({ document, blobUrl, text, diagnosis });