Skip to main content
MarkItDown can integrate with Large Language Models (LLMs) to generate detailed descriptions for images during conversion, making the output more accessible and useful for text analysis.

Overview

When an LLM client is configured, MarkItDown:
  1. Extracts image metadata using ExifTool (if available)
  2. Encodes the image as a base64 data URI
  3. Sends the image to the LLM with a prompt
  4. Includes the AI-generated description in the Markdown output
LLM integration is currently supported for JPEG and PNG images only.

Prerequisites

1

Install OpenAI Package

The openai package is not included in MarkItDown’s dependencies and must be installed separately.
2

Get API Key

Obtain an API key from OpenAI or your LLM provider
3

Optional: Install ExifTool

For enhanced image metadata extraction:

Basic Usage

Python API

Output:

Configuration Options

LLM Client

Any OpenAI-compatible client that supports the chat completions API:

LLM Model

Specify the model to use for image descriptions:
Supported models (vision-capable):
  • gpt-4o - Recommended, high quality
  • gpt-4o-mini - Faster, more cost-effective
  • gpt-4-turbo - Previous generation
  • gpt-4-vision-preview - Legacy

Custom Prompt

Customize the prompt sent to the LLM:
Default prompt:

Per-Conversion Override

Override settings for individual conversions:

Implementation Details

Image Processing

The LLM integration in _image_converter.py:

Supported Image Types

LLM descriptions are generated for:
  • .jpg, .jpeg (JPEG images)
  • .png (PNG images)
Other image formats are not currently supported.

Advanced Examples

Multiple Images with Different Prompts

Accessibility Captions

Content Moderation

Custom OpenAI Client Configuration

Azure OpenAI

Alternative LLM Providers

Any OpenAI-compatible API:

Cost Considerations

LLM API calls incur costs. Each image conversion with LLM integration makes one API request.
Cost factors:
  • Model choice: gpt-4o-mini is more cost-effective than gpt-4o
  • Image size: Larger images consume more tokens
  • Prompt length: Longer prompts increase costs
  • Frequency: Each image conversion = one API call
Estimated costs (as of 2024):
  • gpt-4o: ~$0.01-0.02 per image
  • gpt-4o-mini: ~$0.001-0.002 per image

Minimize Costs

Error Handling

Without LLM Integration

If no LLM client is configured, image conversion includes only metadata:
Output:

Troubleshooting

OpenAI Package Not Installed

Solution:

Invalid API Key

Check:
  • API key is correct
  • API key has not expired
  • Account has available credits

Model Not Found

Ensure:
  • Model name is correct
  • Your account has access to the model
  • Using correct API endpoint (OpenAI vs Azure)

No Description Generated

If the description is missing:

Best Practices

  • Use gpt-4o-mini for cost-effective descriptions
  • Customize prompts for your specific use case
  • Handle API errors gracefully with fallbacks
  • Consider caching results for repeated conversions
  • Monitor API usage and costs
  • Use appropriate image sizes (resize large images if needed)