Integrate MarginFront with Non-LLM Tools
Not everything your agent does is an LLM call. Your agent might send SMS messages via Twilio, scrape web pages, generate PDFs, send emails, process images, or transcribe audio. MarginFront tracks all of it through the same event endpoint. What this does for you: Every tool your agent uses — LLM or not — shows up in one dashboard. You see the full cost picture, not just the AI part.How non-LLM events differ from LLM events
Same endpoint (POST /v1/usage/record), same SDK method (mf.usage.record()). The difference is which fields carry the “how much” information:
| Event type | ”How much” field | Example |
|---|---|---|
| LLM | inputTokens + outputTokens | 523 input tokens, 117 output tokens |
| Non-LLM | quantity | 1 SMS sent, 12 pages scraped |
model and modelProvider are descriptive labels you choose. Use something readable — they’ll show up in your dashboard and analytics. inputTokens and outputTokens are always optional; leave them out for non-LLM work.
Prerequisites
Example 1: Twilio SMS
Your agent sends a text message to a customer’s phone number. You want to track each SMS as one unit of usage.model: 'sms-send'? For non-LLM services, model is just a label that helps you identify what happened when you look at the dashboard later. Pick something readable. Other good options: 'outbound-sms', 'sms-notification', 'transactional-sms'.
Example 2: Web scraping (variable quantity)
Your research agent scrapes a website and returns multiple pages of content. The number of pages varies per job, soquantity changes each time.
modelProvider: 'internal'? If the tool is something you built (not a third-party service), use 'internal' as the provider. MarginFront won’t find it in any pricing table, so the cost will be null — which is fine. You’re tracking the signal quantity for billing purposes, not calculating LLM costs.
Example 3: PDF generation
Your reporting agent generates a multi-page PDF for a customer. You bill by the number of pages in the report.Example 4: Email sending (via Resend, SendGrid, etc.)
Example 5: Mixing LLM and non-LLM in one workflow
Real agents often use an LLM to generate content and then a non-LLM tool to deliver it. Track both:cost = null (because 'pdf-generator' isn’t in any pricing table), but the quantity is tracked for billing through your pricing plan.
What you pick vs what MarginFront calculates
For non-LLM events, here’s what’s yours to define and what MarginFront handles:| Field | You set it | MarginFront calculates it |
|---|---|---|
model | Yes — pick a descriptive label | No |
modelProvider | Yes — the service name or 'internal' | No |
quantity | Yes — how many units of work | No |
inputTokens | Optional (leave out for non-LLM) | No |
outputTokens | Optional (leave out for non-LLM) | No |
| Service cost | No | Yes, if model+provider is in the pricing table. Otherwise null. |
| Revenue | No | Yes, from pricing plan: quantity x price_per_unit |
Including tokens AND quantity
Some events straddle both worlds. For example, an image generation call uses tokens (for the prompt) but also produces a quantity (number of images):quantity, inputTokens, outputTokens) are always optional. Use whichever ones are relevant to the work that happened.
Cost tracking for non-LLM tools
MarginFront’s built-in pricing table covers 300+ LLM models. For non-LLM tools like Twilio, your PDF generator, or your web scraper, the model+provider won’t be in the table. That’s fine:- The event saves with
cost = null(never dropped, never zero). - Revenue is still calculated from your pricing plan (
quantity x price_per_unit). - If you want to track the actual cost of a non-LLM tool (e.g., Twilio charges $0.0079 per SMS), you can map the model in the dashboard to a custom pricing entry. But this is optional — many users only care about the revenue side for non-LLM tools.
Fire-and-forget still applies
Just like with LLM events, the SDK’s default fire-and-forget mode means:- If MarginFront is down, events retry automatically from a local buffer.
- If there’s a validation error, the SDK logs a warning and moves on.
- Your agent never stalls waiting for MarginFront.

