Core Fundamentals ⏱ 7 min read 📁 examples/10_multimodal.mjs

Lesson 05: Multimodal Vision and Media

Deliver multimodal prompts with images and binary media across OpenAI, Anthropic Claude, Google Gemini, and Vertex AI using unified media message creators.

1. Why This Feature Exists

Every major AI provider has an entirely different representation for image payloads (OpenAI uses image_url base64 data URIs; Gemini uses inlineData parts; Claude uses image source objects). Merci SDK isolates this divergence into a single helper.

2. Key Symbols and Exports

createUnifiedMediaMessages()
Constructs multimodal message structures containing text and base64 or URL media.
mimeType normalization
Standardizes image/png, image/jpeg, image/webp formats across provider payload expectations.
inline_data vs image_url
Adapts transparently between OpenAI image_url format and Gemini inline_data structures.

3. Implementation Walkthrough

import {
    ProviderType,
    resolveProvider,
    initializeClient,
    loadCredentials,
    getDefaultModel,
    createUnifiedMediaMessages
} from 'merci-sdk';

const PROVIDER = resolveProvider();
const { client } = await initializeClient({ provider: PROVIDER, options: loadCredentials({ provider: PROVIDER }) });

const mediaMessages = await createUnifiedMediaMessages({
    provider: PROVIDER,
    prompt: 'Describe what you see in this image in detail.',
    imagePath: 'examples/fixtures/image.png'
});

const session = client.session(getDefaultModel({ provider: PROVIDER }));
const stream = session.step({ messages: mediaMessages });

for await (const event of stream) {
    if (event.type === 'text') process.stdout.write(event.content);
}

4. Wire and Telemetry Mechanics

The adapter inspects the current PROVIDER and transforms the unified media message into the provider's exact specification before dispatching the HTTP request.

5. Run the Example

Execute the runnable example directly from the repository root:

node examples/10_multimodal.mjs

Read the full example: examples/10_multimodal.mjs →

Expected Output: Reads examples/image.png, formats the media message, and streams the vision model's detailed visual description to the console.