← 返回
数据分析 Key

Drip Billing

Track AI agent usage and costs with Drip metered billing. Use when you need to record aggregate LLM usage, tool calls, agent runs, or other metered usage for...
使用 Drip 计费追踪 AI 智能体使用量和成本。当您需要记录聚合 LLM 使用量、工具调用、智能体运行或其他计量使用情况时使用。
lucas-309
数据分析 clawhub v1.0.3 1 版本 99795.1 Key: 需要
★ 0
Stars
📥 487
下载
💾 5
安装
1
版本
#latest

概述

Drip Billing Integration

Track usage and costs for AI agents, LLM calls, tool invocations, and any metered workload.

When to Use This Skill

  • Recording LLM usage quantities (for example total tokens per call)
  • Tracking tool/function call costs
  • Logging agent execution traces
  • Metering API requests for billing
  • Attributing costs to customers or workflows

Security & Data Privacy

Key scoping (least privilege):

  • Use pk_ (public) keys for usage tracking, customer management, and billing. This is sufficient for all skill operations.
  • Only use sk_ (secret) keys if you need admin operations: webhook management, API key rotation, or feature flags.
  • Public keys (pk_) cannot manage webhooks, rotate API keys, or toggle feature flags — this limits blast radius if the key is compromised.

Metadata safety:

  • Include only minimal non-sensitive operational context in metadata.
  • Never include PII, secrets, passwords, API keys, raw user prompts, model outputs, or full request/response bodies.
  • Use a strict allowlist and redaction policy before telemetry writes.
  • Prefer hashes/IDs (for example queryHash) instead of raw user text.

What data is transmitted:

  • Usage quantities (meter name + numeric value)
  • Customer identifiers
  • Run lifecycle events (start/end, status, duration)
  • Sanitized metadata you explicitly provide (model family, tool name, status code, latency, hashed IDs)

What is NOT transmitted:

  • Raw prompts, completions, or model outputs
  • Environment variables or secrets
  • File contents or source code

Installation

npm install @drip-sdk/node

Environment Setup

# Recommended: public key — sufficient for all usage tracking and billing
export DRIP_API_KEY=pk_live_...

# Only if you need admin operations (webhooks, key management, feature flags):
# export DRIP_API_KEY=sk_live_...

Telemetry Safety Contract

  • Send only metadata needed for billing and diagnostics.
  • Do not send raw prompts, raw model outputs, raw query text, full request/response bodies, or credentials.
  • Prefer stable identifiers and hashes (for example queryHash) over raw user content.
  • Emit telemetry only to a trusted DRIP_BASE_URL.

Quick Start

1. Initialize the SDK

import { Drip } from '@drip-sdk/node';

// Reads DRIP_API_KEY from environment automatically (pk_live_... recommended)
const drip = new Drip({
  apiKey: process.env.DRIP_API_KEY
});

2. Track Usage (Simple)

await drip.trackUsage({
  customerId: 'customer_123',
  meter: 'llm_tokens',
  quantity: 1500,
  // metadata is optional — only include operational context, never PII or secrets
  metadata: { model: 'gpt-4' }
});

3. Record Agent Runs (Complete Execution)

await drip.recordRun({
  customerId: 'cus_123',
  workflow: 'research-agent',
  events: [
    { eventType: 'llm.call', model: 'gpt-4', quantity: 1700, units: 'tokens' },
    { eventType: 'tool.call', name: 'web-search', duration: 1500 },
    { eventType: 'llm.call', model: 'gpt-4', quantity: 1000, units: 'tokens' },
  ],
  status: 'COMPLETED',
});

4. Streaming Execution (Real-Time)

// Start the run
const run = await drip.startRun({
  customerId: 'cus_123',
  workflowSlug: 'document-processor',
});

// Log each step as it happens
await drip.emitEvent({
  runId: run.id,
  eventType: 'llm.call',
  model: 'gpt-4',
  quantity: 1700,
  units: 'tokens',
});

await drip.emitEvent({
  runId: run.id,
  eventType: 'tool.call',
  name: 'web-search',
  duration: 1500,
});

// Complete the run
await drip.endRun(run.id, { status: 'COMPLETED' });

Event Types

Event TypeDescriptionKey Fields
-------------------------------------
llm.callLLM API callmodel, quantity, units
tool.callTool invocationname, duration, status
agent.planPlanning stepdescription
agent.executeExecution stepdescription, metadata
errorError occurreddescription, metadata

Common Patterns

Wrap Tool Calls

async function trackedToolCall<T>(runId: string, toolName: string, fn: () => Promise<T>): Promise<T> {
  const start = Date.now();
  try {
    const result = await fn();
    await drip.emitEvent({
      runId,
      eventType: 'tool.call',
      name: toolName,
      duration: Date.now() - start,
      status: 'success',
    });
    return result;
  } catch (error: unknown) {
    const message = error instanceof Error ? error.message : 'Unknown error';
    await drip.emitEvent({
      runId,
      eventType: 'tool.call',
      name: toolName,
      duration: Date.now() - start,
      status: 'error',
      // Only include the error message — never include stack traces, env vars, or user data
      metadata: { error: message },
    });
    throw error;
  }
}

LangChain Auto-Tracking

import { DripCallbackHandler } from '@drip-sdk/node/langchain';

const handler = new DripCallbackHandler({
  drip,
  customerId: 'cus_123',
  workflow: 'research-agent',
});

// All LLM calls and tool usage automatically tracked
const result = await agent.invoke(
  { input: 'Research the latest AI news' },
  { callbacks: [handler] }
);

API Reference

See references/API.md for complete SDK documentation.

版本历史

共 1 个版本

  • v1.0.3 当前
    2026-03-30 12:55 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

data-analysis

A股量化 AkShare

mbpz
A股量化数据分析工具,基于AkShare库获取A股行情、财务数据、板块信息等。用于回答关于A股股票查询、行情数据、财务分析、选股等问题。
★ 164 📥 59,894
data-analysis

Data Analysis

ivangdavila
{"answer":"数据分析与可视化。查询数据库、生成报告、自动化电子表格,将原始数据转化为清晰可行的见解。适用于:(1) 您……"}
★ 198 📥 65,032
data-analysis

Stock Analysis

udiedrichsen
{"answer":"基于雅虎财经数据,分析股票与加密货币。支持投资组合管理、自选股预警、股息分析、8维评分、热门趋势扫描及传闻/早期信号探测。适用于股票分析、持仓追踪、财报异动、加密监控、热门股追踪或提前发掘非主流传闻。"}
★ 270 📥 56,934