Quickstart
You'll install the SDK, ship a test event, and watch it appear in the dashboard. This takes about three minutes.
1. Create a workspace
Sign up at app.margint.dev with your GitHub or Google account. A workspace is created for you.
2. Get an API key
In the dashboard, go to Settings → API Keys and create one. Copy it — you'll only see the full value once.
API keys are prefixed m_live_. The same key authenticates the SDK, the public REST API, and the MCP server.
3. Install the SDK
npm install @margint-ai/sdk
pnpm add @margint-ai/sdk
pip install margint
uv pip install margint
4. Send your first event
import { Margint } from '@margint-ai/sdk'
const m = new Margint({ apiKey: process.env.MARGINT_API_KEY! })
m.track({
customerId: 'cust_demo',
feature: 'chat',
provider: 'openai',
model: 'gpt-4o',
inputTokens: 820,
outputTokens: 310
})
await m.flush()
import os
from margint import Margint
m = Margint(api_key=os.environ["MARGINT_API_KEY"])
m.track(
customer_id="cust_demo",
feature="chat",
provider="openai",
model="gpt-4o",
input_tokens=820,
output_tokens=310,
)
m.flush()
curl -X POST https://app.margint.dev/api/ingest/events \
-H "Content-Type: application/json" \
-d '{
"apiKey": "'"$MARGINT_API_KEY"'",
"events": [{
"customerId": "cust_demo",
"feature": "chat",
"provider": "openai",
"model": "gpt-4o",
"inputTokens": 820,
"outputTokens": 310
}]
}'
5. See it in the dashboard
Open Customers in the dashboard. cust_demo should appear within ~10 seconds. At $2.50/M input and $10.00/M output for gpt-4o, that single call costs about half a cent.
Next: wire it into your real app
Most teams use the wrap() pattern — you install the SDK once and forget about it.
import OpenAI from 'openai'
import { Margint } from '@margint-ai/sdk'
const m = new Margint({ apiKey: process.env.MARGINT_API_KEY! })
// In your request handler:
const openai = m.wrap(new OpenAI(), {
customerId: user.id,
feature: 'chat'
})
// Use openai normally — every call is tracked
const res = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: prompt }]
})
import openai
from margint import Margint
m = Margint(api_key=os.environ["MARGINT_API_KEY"])
# In your request handler:
client = m.wrap(
openai.OpenAI(),
customer_id=user.id,
feature="chat",
)
# Use client normally — every call is tracked
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": prompt}],
)
Framework-specific setup (Next.js, Nuxt, FastAPI, Django, Flask, Express) lives in the SDK reference pages: