Getting Started with Merci SDK
Merci SDK is a lightweight, minimal-dependency, multi-provider AI framework for Node.js. Three API standards cover seven providers — OpenAI, Anthropic Claude, Google Gemini, Vertex AI, OpenRouter, OpenCode, and Local Stack — under a single fluent interface.
1. Installation and Environment
Merci SDK requires Node.js v22+ (or modern Node with native ES Modules). Pure ES Modules — no build pipeline, and no orchestration framework underneath.
# Using pnpm (recommended)
pnpm add merci-sdk
# Or using npm
npm install merci-sdk2. Configuring Provider Credentials
Copy the shipped template to secret.env in your project root (secret.env is gitignored) and fill in one provider. Set PROVIDER to choose your active provider:
# Active provider: openai | anthropic | google_genai | vertex | openrouter | opencode | local
PROVIDER=openai
# OpenAI
OPENAI_API_KEY=sk-...
# Google Gemini
GEMINI_API_KEY=AIzaSy...
# Anthropic Claude
ANTHROPIC_API_KEY=sk-ant-...
# Local Stack
LM_STUDIO_URL=http://localhost:1234/v1secret.env via loadCredentials({ provider }).
3. Your First Completion Stream
Initialize a client, spawn a fluent session, configure system directives, and stream responses with real-time token tracking:
import {
ProviderType,
resolveProvider,
initializeClient,
loadCredentials,
getDefaultModel,
createUserMessage
} from 'merci-sdk';
// 1. Resolve the provider from env
const provider = resolveProvider();
const { client } = await initializeClient({ provider, options: loadCredentials({ provider }) });
// 2. Build a session with system directives and parameters
const session = client.session(getDefaultModel({ provider }))
.withSystemMessage('You are a high-performance cloud architecture specialist.');
// 3. Step through the stream
const stream = session.step({ messages: [
createUserMessage({ provider, content: 'Summarize the core principles of stateless microservices.' })
] });
for await (const event of stream) {
if (event.type === 'text') process.stdout.write(event.content);
}4. Core Architectural Guarantees
Model Tiering Rule
Use getDefaultModel() for orchestrator brains, planners, and judges. Use getToolModel() for cheap leaf subagents and simple tool transforms.
Stateless Resend
History lives in your application array. Replace history with finalState.messages from each turn — never push duplicates to keep wire state honest.
Per-Wire Normalization
Provider quirks (e.g. Gemini anyOf rejection, Anthropic system prompt separation) are handled invisibly inside adapters, never in your business logic.
Visible Truncation
The SDK never drops context silently. Context compaction and folding always inject explicit loss markers into the conversation stream.