Skip to main content
This cookbook walks through the core Morphik workflow in TypeScript—multimodal ingestion for high-accuracy retrieval, text ingestion for OCR-driven chunks, and piping the results into the LLM you control.
Prerequisites
  • Install the Morphik SDK: npm install morphik
  • Provide credentials via MORPHIK_API_KEY
  • For the optional OpenAI example, set OPENAI_API_KEY and (optionally) OPENAI_MODEL

1. Initialize the Morphik client

2. Helper utilities

3. Multimodal workflow (direct file indexing)

This path indexes the original file contents directly, yielding higher accuracy for scanned pages, tables, and images.

Retrieve multimodal chunks first

At this point you can either:
  • ask Morphik to draft the answer for you, or
  • forward the curated chunks to your own LLM (see Use your own LLM).

Option A: generate a Morphik completion (multimodal)

4. Text workflow (OCR + chunking)

This path OCRs the document before chunking it, making the text immediately available for retrieval.

Retrieve text chunks first

Choose the same fork as above:
  • stick with Morphik completions for a managed response, or
  • jump to Use your own LLM to prompt your custom model with these chunks.

Option A: generate a Morphik completion (text)

5. Use your own LLM (OpenAI example)

For production workloads, forward Morphik’s curated context to your preferred LLM. This gives you full control over system prompts, orchestration, and rate limits, while Morphik focuses on delivering retrieval tools your agent can trust.
Morphik stays focused on high-quality retrieval and chunking. Pair it with the LLM of your choice to enforce your policies, prompts, and cost controls end to end.