Quickstart
Add MargIQ without rewriting model calls.
This path keeps your current server-side model calls intact while MargIQ learns workflow-level savings, latency, and safety evidence.
1. Install
npm install margiq2. Add MargIQ environment variables
MargIQ Cloud is used by default, so setup only needs a MargIQ API key. Keep your existing model-provider credentials exactly where they are today.
MARGIQ_API_KEY=...
# Keep your existing model-provider credentials unchanged.
# Example names may include OPENAI_API_KEY, OPENROUTER_API_KEY,
# ANTHROPIC_API_KEY, or a provider-specific key your app already uses.3. Wrap the existing provider client
Use your current OpenAI-compatible provider client. The example below is intentionally provider-neutral; replace the provider name and model IDs with the namespace your app already uses.
import OpenAI from "openai";
import { wrapClient } from "margiq";
const providerClient = new OpenAI({
apiKey: process.env.YOUR_PROVIDER_API_KEY!,
baseURL: process.env.YOUR_PROVIDER_BASE_URL,
});
export const ai = wrapClient(providerClient, {
provider: "your-provider",
availableModels: [
"provider/model-large",
"provider/model-fast",
"provider/model-economy",
],
backend: {
apiKey: process.env.MARGIQ_API_KEY!,
},
});4. Send traffic normally
const response = await ai.chat.completions.create({
model: "provider/model-large",
messages,
});5. Review dashboard evidence
Use the dashboard to inspect workflows, routing paths, potential savings, model choices, and safety guards before enabling Automatic mode.
Verify the setup
- Send one low-risk request through the wrapped server-side client.
- Open dashboard transactions and confirm requested and selected model fields appear.
- Review workflows after repeated traffic creates enough profile data.
- Request Pro access only when workflow-level routing should be activated.
Optional provider examples
These are examples only. MargIQ is platform agnostic and works around your existing OpenAI-compatible provider client. Install the OpenAI package only if you want to use these examples or do not already have an OpenAI-compatible SDK in your server-side AI layer.
npm install openaiimport OpenAI from "openai";
import { wrapClient } from "margiq";
const openrouter = new OpenAI({
apiKey: process.env.OPENROUTER_API_KEY!,
baseURL: "https://openrouter.ai/api/v1",
});
export const ai = wrapClient(openrouter, {
provider: "openrouter",
availableModels: [
"openai/gpt-4o",
"openai/gpt-4.1-mini",
"openai/gpt-4.1-nano",
"openai/gpt-4o-mini",
"google/gemini-2.5-flash",
"google/gemini-2.5-flash-lite",
"anthropic/claude-3.5-haiku",
],
backend: {
apiKey: process.env.MARGIQ_API_KEY!,
},
});import OpenAI from "openai";
import { wrapClient } from "margiq";
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY!,
});
export const ai = wrapClient(openai, {
provider: "openai",
availableModels: [
"gpt-4o",
"gpt-4.1-mini",
"gpt-4.1-nano",
"gpt-4o-mini",
],
backend: {
apiKey: process.env.MARGIQ_API_KEY!,
},
});