Observe API

Cost and usage observability for AI features. llms.txt

Quick start

  1. Sign up — free, no credit card.
  2. Go to Data Sources → copy your obs_ API key.
  3. Add one line after each LLM call in your code:
fetch('https://observe.tansohq.com/api/events/ingest', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.OBSERVE_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    events: [{
      eventName: 'chat',
      customerReferenceId: user.id,
      featureKey: 'ai_chat',
      model: 'gpt-4o-mini',
      modelProvider: 'openai',
      inputTokens: res.usage?.prompt_tokens,
      outputTokens: res.usage?.completion_tokens,
    }],
  }),
}).catch(console.error)

That's it. Observe auto-computes cost from model + tokens. Your LLM calls are unaffected — Observe is fire-and-forget, off the critical path.

Managing API keys

From the dashboard, go to Data Sources to create, view, and revoke keys. Each key can have:

Use this to give different teams different keys: sales gets proxy.chat with a $40/month budget, analytics gets usage.read with no budget.

Connecting Stripe

Optional. Go to Data Sources → Stripe → paste a restricted API key (read-only: Customers, Subscriptions, Products, Prices). Observe imports your customer and subscription data to calculate revenue and margins per feature.

Event schema

FieldRequiredDescription
eventNameYesShort label: chat, embed, api_call
customerReferenceIdYesYour end-user's stable ID
featureKeyYesProduct feature: ai_chat, summarize
modelRecommendedModel name for auto-cost: gpt-4o-mini
modelProviderRecommendedopenai, anthropic, google, etc.
inputTokensRecommendedPrompt tokens
outputTokensRecommendedCompletion tokens
costAmountNoOverride auto-computed cost (USD)
revenueAmountNoOverride revenue attribution
durationMsNoCall latency in milliseconds
idempotencyKeyNoDedupe on retry (recommended)
traceIdNoGroup multi-step agent flows
metaNo{ stripe_customer_id: "cus_..." } for revenue matching

Full reference

See llms.txt for the complete API reference including all management endpoints, gateway integration, SDK auto-wrap, tracing, and revenue attribution details.

Self-serve signup

Create an account and get an API key in one call. No auth required. Rate limited to 3/hr per IP.

curl -X POST https://observe.tansohq.com/api/signup \
  -H "Content-Type: application/json" \
  -d '{
    "email": "agent@yourapp.com",
    "scopes": ["usage.read", "events.write", "proxy.chat"],
    "budget_cents": 5000,
    "budget_period": "month"
  }'

Response: { "key": "obs_...", "scopes": [...], "budget_cents": 5000 }

FieldDefaultDescription
emailrequiredAccount email
scopes["usage.read", "billing.read"]Key scopes (see table below)
budget_centsnull (unlimited)Per-key LLM spend cap
budget_periodnull (lifetime)"month" or "day"
expires_in_secondsnull (never)Auto-expire the key

Key introspection

curl https://observe.tansohq.com/api/sdk-keys/me \
  -H "Authorization: Bearer obs_..."

Returns your key's scopes, budget remaining, and expiry. Call this before expensive operations to check your budget.

Plan and limits

curl https://observe.tansohq.com/api/plan \
  -H "Authorization: Bearer obs_..."

Returns your account plan, per-feature limits, current usage, and remaining quota.

Ingest events

curl -X POST https://observe.tansohq.com/api/events/ingest \
  -H "Authorization: Bearer obs_..." \
  -H "Content-Type: application/json" \
  -d '{
    "events": [{
      "eventName": "chat",
      "customerReferenceId": "acme-corp",
      "featureKey": "ai_chat",
      "model": "gpt-4o-mini",
      "modelProvider": "openai",
      "inputTokens": 150,
      "outputTokens": 80
    }]
  }'

Requires events.write scope. Batch up to 1000 events per request. Cost auto-computed from model + tokens.

Scopes

ScopeAccessSignup?
proxy.chatLLM proxy/gatewayYes
usage.readFeatures, analytics, simulationsYes
events.readEvents, traces, aggregationsYes
events.writeIngest events, manage keysYes
customers.readCustomers, subscriptions, cohortsYes
billing.readPlan, entitlements, cloud costsYes
recommendations.readOptimization recommendationsYes
models.readModel pricing and statsYes
usage.writeModify features, simulationsNo
customers.writeModify customers, upload dataNo
billing.writeCloud cost integrationsNo
alerts.readAlert rules and historyNo
alerts.writeCreate/modify alert rulesNo
adminFull accessNo

Scopes marked "No" require a human to create the key via POST /sdk-keys with a Clerk session.

Management API

Analytics

GET/api/analytics/overviewDashboard KPIs
GET/api/featuresFeatures with cost/revenue stats
GET/api/customersCustomers with margins
GET/api/eventsPaginated event list
GET/api/modelsModel cost stats

Alerts

GET/api/alertsList alert rules
POST/api/alertsCreate alert rule
DEL/api/alerts/:idDelete alert rule

Recommendations

GET/api/recommendationsOptimization recommendations
POST/api/recommendations/computeTrigger recommendation engine

Full reference

See llms.txt for complete endpoint list, event schema, tracing, revenue attribution, and integration paths (direct ingest, gateway headers, SDK auto-wrap).