Skip to main content
This cookbook walks through the core Morphik workflow using the REST API—multimodal ingestion for high-accuracy retrieval, text ingestion for OCR-driven chunks, and integrating with your own LLM.
Prerequisites
  • Morphik API endpoint (e.g., http://localhost:8000 or https://api.morphik.ai)
  • API credentials via MORPHIK_API_KEY (if authentication is enabled)
  • For the optional OpenAI example, set OPENAI_API_KEY

1. Environment setup

2. Multimodal ingestion (ColPali)

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

Wait for processing to complete

Response when ready:

3. Text ingestion (OCR + chunking)

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

4. Query with Morphik completion

Generate a completion directly using Morphik’s configured LLM.

Multimodal query (ColPali)

Response:

Text query (standard)

5. Query with system prompt override

Override the default system prompt to customize the LLM’s behavior and response style.
Example with different persona:
Response:

6. Retrieve chunks for your own LLM

For production workloads, retrieve Morphik’s curated chunks and forward them to your preferred LLM. This gives you full control over prompts, orchestration, and rate limits.

Step 1: Retrieve relevant chunks

Response:

Step 2: Forward to your LLM (OpenAI example)

Text-only chunks with OpenAI

Multimodal chunks with OpenAI (vision)

Step 3: Using other LLM providers

The same pattern works with any LLM provider. Morphik handles retrieval and chunking; you control the completion: Anthropic Claude:
Google Gemini:

7. Advanced: Custom prompt template

You can also override the prompt template that formats the context and question:

Summary

Morphik’s REST API provides flexible integration options:
  1. Managed completions: Use Morphik’s configured LLM with optional system prompt overrides
  2. Bring your own LLM: Retrieve curated chunks and forward to any LLM provider
  3. Multimodal support: Handle both text and visual content seamlessly
  4. Full control: Override system prompts, prompt templates, and completion parameters
This separation of concerns lets you focus on your application logic while Morphik handles high-quality retrieval and chunking.