Opsmeter logo
Opsmeter
AI Cost & Inference Control
Integration docs

Developer Docs

Ship telemetry fast with LLM cost tracking and OpenAI cost monitoring. Request-level budget alerts are available on Pro+ plans.

Updated for 2026API v1GitHub

Quickstart

01

Generate a workspace API key

After sign-in, rotate a new key in Settings. Keys are shown only once.

02

Send telemetry

Post LLM request metadata to the ingest endpoint after each model call. Include externalRequestId on every request for idempotency. Treat it like a unique, per-request key you generate on your side.

03

Track budgets

Use the Dashboard to monitor spend, latency and budget alerts in real time. Ingest responses include budgetWarning and budgetExceeded plus plan metadata for client-side UX.

Prod-ready quickstart

Move from hello-world telemetry to production-grade instrumentation with clear guardrails.

01

externalRequestId playbook

Generate one ID per LLM call and reuse it on retries. Store it in request context (middleware/local variable) so the same ID flows through every retry.

const ctx = { externalRequestId: existingId ?? null };
const externalRequestId = ctx.externalRequestId ?? crypto.randomUUID();
ctx.externalRequestId = externalRequestId;

for (let attempt = 0; attempt < 3; attempt++) {
  try {
    return await llmCall();
  } catch (err) {
    if (attempt === 2) throw err;
  }
}
// telemetry uses the same externalRequestId from ctx
DoDon't
Generate once per LLM call, reuse on retry.Create a new ID on every retry.
Pass the same ID through all telemetry fields.Use timestamps alone as the ID.
Store it in request context for downstream access.Recompute the ID in each layer.
02

endpointTag examples

Tag = product feature, not endpoint path. Example tags: checkout.ai_summary, support.reply, invoice.extract.

03

promptVersion strategy

Treat prompt versions like deploy labels: summarizer_v3, chat-v5.2. Rule: new deploy = new version.

04

userId optional + PII warning

userId is optional. If omitted, requests group into unknown. Never send PII; hash identifiers if you need stable user grouping.

05

Latency measurement

Capture a timestamp before the LLM call and compute latency after it finishes.

const start = Date.now();
const latencyMs = Date.now() - start;
06

Token sources

  • Provider response usage fields.
  • Approximate with a tokenizer library.
07

Telemetry should never break prod (Golden Rule)

  • Non-blocking calls only.
  • Timeouts: 300-800ms.
  • Try/catch and swallow telemetry errors.
  • Fire-and-forget ingestion.
  • On 429, show/log: Telemetry throttled, retry after Xs.
08

402 Telemetry Paused handling

402 = telemetry pause. LLM calls continue. Do not retry telemetry immediately. Pause ingestion for X minutes (for example 10-15), show a UI banner, and surface an upgrade CTA.

09

Batching / queue (high volume)

For high throughput, queue and batch telemetry. Opsmeter ingestion can be async and should not sit on the request path.

SDK roadmap

Official packages (coming soon)

We are shipping official SDKs and middleware for the most popular stacks.

NuGet

Opsmeter .NET SDK with automatic telemetry capture.

Coming soon

npm

Node.js SDK + Express/Nest middleware for request tracing.

Coming soon

Python

FastAPI middleware and typed client for ingestion.

Coming soon