{"_id":"@agentbill/sdk","name":"@agentbill/sdk","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@agentbill/sdk","version":"1.0.0","description":"OpenTelemetry-based SDK for tracking AI agent usage and billing","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"scripts":{"build":"tsup","prepare":"npm run build","prepublishOnly":"npm run build"},"keywords":["opentelemetry","otel","ai","agent","billing","usage-tracking","openai","anthropic","llm","observability"],"author":{"name":"AgentBill"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/yourusername/agentbill-sdk.git"},"peerDependencies":{"openai":">=4.0.0","@anthropic-ai/sdk":">=0.9.0"},"peerDependenciesMeta":{"openai":{"optional":true},"@anthropic-ai/sdk":{"optional":true}},"dependencies":{"tsup":"^8.0.0","typescript":"^5.0.0"},"_id":"@agentbill/sdk@1.0.0","bugs":{"url":"https://github.com/yourusername/agentbill-sdk/issues"},"homepage":"https://github.com/yourusername/agentbill-sdk#readme","_nodeVersion":"22.19.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-Hehpa//AUbPRXHrU8RQKR22S/u1y1GLboKp63mQOR/YS6DfLkaI86iebOiyzZDMKUhAf1wUK4aNbB2HOoYS8VA==","shasum":"3d6c821423cffac18ef4f53f18985cda749815d8","tarball":"https://registry.npmjs.org/@agentbill/sdk/-/sdk-1.0.0.tgz","fileCount":8,"unpackedSize":223940,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC1yktmo4J1nbEx89cEsKGa6br6NsfMOJpyv3OnDKiKBQIgVDIuMnAQPgxIRdy0Eva9C4vdIElJB+Y9WU1fPmqlzGM="}]},"_npmUser":{"name":"premchandulingamaneni","email":"premchandu.lingamaneni@gmail.com"},"directories":{},"maintainers":[{"name":"premchandulingamaneni","email":"premchandu.lingamaneni@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sdk_1.0.0_1761054395745_0.501131106364247"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-21T13:46:35.574Z","1.0.0":"2025-10-21T13:46:35.927Z","modified":"2025-10-21T13:46:36.295Z"},"maintainers":[{"name":"premchandulingamaneni","email":"premchandu.lingamaneni@gmail.com"}],"description":"OpenTelemetry-based SDK for tracking AI agent usage and billing","homepage":"https://github.com/yourusername/agentbill-sdk#readme","keywords":["opentelemetry","otel","ai","agent","billing","usage-tracking","openai","anthropic","llm","observability"],"repository":{"type":"git","url":"git+https://github.com/yourusername/agentbill-sdk.git"},"author":{"name":"AgentBill"},"bugs":{"url":"https://github.com/yourusername/agentbill-sdk/issues"},"license":"MIT","readme":"# @agentbill/sdk\n\nOpenTelemetry-based SDK for automatic AI agent usage tracking and billing. Zero-config instrumentation for OpenAI, Anthropic, AWS Bedrock, Azure OpenAI, Mistral AI, and other AI providers.\n\n## Features\n\n✨ **Zero-config instrumentation** - Wrap your AI client once, track everything automatically  \n📊 **Accurate token & cost tracking** - Captures real usage from API responses  \n🔍 **OpenTelemetry standard** - Industry-standard observability protocol  \n🚀 **Multi-provider support** - OpenAI, Anthropic, AWS Bedrock, Azure OpenAI, Mistral AI, Cohere, custom endpoints  \n⚡ **Automatic batching** - Efficient data export with configurable batch sizes  \n🎯 **Rich metadata** - Track model, tokens, latency, costs, and custom attributes  \n\n## Supported Providers\n\n### ✅ OpenAI\nAll GPT models (GPT-4, GPT-5, etc.) - Auto-captures tokens, model, cost, latency\n\n### ✅ Anthropic  \nAll Claude models (Claude 3.5 Sonnet, Opus, etc.) - Auto-captures tokens, model, cost, latency\n\n### ✅ AWS Bedrock\nClaude, Meta Llama, Mistral, Amazon Titan, Cohere models - Auto-captures tokens, model, cost, latency\n\n### ✅ Azure OpenAI\nAll Azure-deployed OpenAI models (GPT-4, GPT-3.5, embeddings) - Auto-captures tokens, model, cost, latency\n\n### ✅ Mistral AI\nMistral Large/Medium/Small, Codestral, Ministral, open models - Auto-captures tokens, model, cost, latency\n\n## Installation\n\n### From GitHub (Recommended)\n```bash\nnpm install github:YOUR-ORG/agentbill-typescript\n# or\nyarn add github:YOUR-ORG/agentbill-typescript\n# or\npnpm add github:YOUR-ORG/agentbill-typescript\n```\n\n### From npm\n```bash\nnpm install @agentbill/sdk\n# or\nyarn add @agentbill/sdk\n# or\npnpm add @agentbill/sdk\n```\n\n### From Source\n```bash\ngit clone https://github.com/YOUR-ORG/agentbill-typescript.git\ncd agentbill-typescript\nnpm install\nnpm run build\nnpm link\n```\n\n## File Structure\n\n```\nagentbill-typescript/\n├── README.md\n├── package.json\n├── tsconfig.json\n├── index.ts\n├── tracer.ts\n├── types.ts\n├── wrapper.ts\n└── examples/\n    └── basic-usage.ts\n```\n\n## Quick Start\n\n### OpenAI\n\n```typescript\nimport { AgentBill } from '@agentbill/sdk';\nimport OpenAI from 'openai';\n\n// Initialize AgentBill\nconst agentBill = AgentBill.init({\n  apiKey: 'your-agentbill-api-key',\n  customerId: 'customer-123',\n  baseUrl: 'https://your-agentbill-instance.com', // Your AgentBill API endpoint\n  debug: true // Enable debug logging (optional)\n});\n\n// Wrap your OpenAI client\nconst openai = agentBill.wrapOpenAI(new OpenAI({\n  apiKey: process.env.OPENAI_API_KEY\n}));\n\n// Use normally - all calls automatically tracked!\nconst response = await openai.chat.completions.create({\n  model: \"gpt-4\",\n  messages: [{ role: \"user\", content: \"Hello!\" }]\n});\n\n// Tokens, costs, and latency automatically captured ✨\n```\n\n### Anthropic\n\n```typescript\nimport { AgentBill } from '@agentbill/sdk';\nimport Anthropic from '@anthropic-ai/sdk';\n\nconst agentBill = AgentBill.init({\n  apiKey: 'your-agentbill-api-key',\n  customerId: 'customer-123',\n  baseUrl: 'https://your-agentbill-instance.com'\n});\n\nconst anthropic = agentBill.wrapAnthropic(new Anthropic({\n  apiKey: process.env.ANTHROPIC_API_KEY\n}));\n\nconst response = await anthropic.messages.create({\n  model: \"claude-opus-4\",\n  max_tokens: 1024,\n  messages: [{ role: \"user\", content: \"Hello!\" }]\n});\n```\n\n### AWS Bedrock\n\n```typescript\nimport { AgentBill } from '@agentbill/sdk';\nimport { BedrockRuntimeClient, InvokeModelCommand } from '@aws-sdk/client-bedrock-runtime';\n\nconst agentBill = AgentBill.init({\n  apiKey: 'your-agentbill-api-key',\n  customerId: 'customer-123'\n});\n\nconst bedrock = agentBill.wrapBedrock(new BedrockRuntimeClient({\n  region: 'us-east-1'\n}));\n\nconst response = await bedrock.send(new InvokeModelCommand({\n  modelId: 'anthropic.claude-3-5-sonnet-20241022-v2:0',\n  body: JSON.stringify({\n    messages: [{ role: \"user\", content: \"Hello!\" }],\n    max_tokens: 1024\n  })\n}));\n```\n\n### Azure OpenAI\n\n```typescript\nimport { AgentBill } from '@agentbill/sdk';\nimport { AzureOpenAI } from '@azure/openai';\n\nconst agentBill = AgentBill.init({\n  apiKey: 'your-agentbill-api-key',\n  customerId: 'customer-123'\n});\n\nconst azure = agentBill.wrapAzureOpenAI(new AzureOpenAI({\n  apiKey: process.env.AZURE_OPENAI_API_KEY,\n  endpoint: 'https://YOUR_RESOURCE.openai.azure.com',\n  apiVersion: '2024-02-01'\n}));\n\nconst response = await azure.chat.completions.create({\n  model: \"gpt-4o\",\n  messages: [{ role: \"user\", content: \"Hello!\" }]\n});\n```\n\n### Mistral AI\n\n```typescript\nimport { AgentBill } from '@agentbill/sdk';\nimport MistralClient from '@mistralai/mistralai';\n\nconst agentBill = AgentBill.init({\n  apiKey: 'your-agentbill-api-key',\n  customerId: 'customer-123'\n});\n\nconst mistral = agentBill.wrapMistral(new MistralClient(\n  process.env.MISTRAL_API_KEY\n));\n\nconst response = await mistral.chat.complete({\n  model: \"mistral-large-latest\",\n  messages: [{ role: \"user\", content: \"Hello!\" }]\n});\n```\n\n## Configuration\n\n```typescript\ninterface AgentBillConfig {\n  apiKey: string;          // Required: Your AgentBill API key\n  baseUrl?: string;        // Optional: AgentBill endpoint (default: production)\n  customerId?: string;     // Optional: Associate all calls with a customer\n  debug?: boolean;         // Optional: Enable debug logging (default: false)\n}\n```\n\n## What Gets Tracked\n\nEvery AI API call is automatically instrumented with:\n\n- **Model information** - Provider, model name, version\n- **Token usage** - Prompt tokens, completion tokens, total tokens\n- **Cost calculation** - Real-time cost based on current pricing\n- **Prompt tracking** - Full prompts hashed for profitability analysis\n- **Performance metrics** - Request latency, timestamps\n- **Status tracking** - Success/failure, error messages\n- **OpenTelemetry context** - Full trace and span data\n\n## Prompt Profitability Tracking\n\nTrack which prompts are profitable or costing you money:\n\n```typescript\nconst agentBill = AgentBill.init({\n  apiKey: 'your-key',\n  customerId: 'customer-123'\n});\n\nconst openai = agentBill.wrapOpenAI(new OpenAI());\n\n// All automatically captured:\n// ✅ Prompt text (hashed for privacy)\n// ✅ Model and provider\n// ✅ Token usage (input/output)\n// ✅ API costs (auto-calculated)\nconst response = await openai.chat.completions.create({\n  model: \"gpt-4o-mini\",\n  messages: [{ role: \"user\", content: \"Your prompt here\" }]\n});\n\n// Optional: Add revenue to calculate profit\nawait agentBill.trackSignal(\"ai_completion\", 0.01);\n```\n\n**Dashboard shows:**\n- Cost per prompt (auto-calculated)\n- Revenue per prompt (if you set it)\n- Net margin per prompt\n- Execution count by prompt\n- Most/least profitable prompts\n\n## Data Export\n\nThe SDK automatically batches and exports telemetry data:\n\n- **Batch size**: Up to 10 spans per export\n- **Batch timeout**: Maximum 1 second between exports\n- **Format**: OpenTelemetry Protocol (OTLP)\n- **Endpoint**: POST to `/functions/v1/otel-collector`\n\n## Manual Flush\n\n```typescript\n// Flush any pending telemetry data before shutdown\nawait agentBill.flush();\n```\n\n## Advanced Usage\n\n### Custom Base URL\n\n```typescript\nconst agentBill = AgentBill.init({\n  apiKey: 'your-key',\n  baseUrl: 'https://custom-agentbill.example.com'\n});\n```\n\n### Per-Customer Tracking\n\n```typescript\n// Track different customers\nconst customerABill = AgentBill.init({\n  apiKey: 'your-key',\n  customerId: 'customer-a'\n});\n\nconst customerBBill = AgentBill.init({\n  apiKey: 'your-key',\n  customerId: 'customer-b'\n});\n```\n\n## TypeScript Support\n\nFully typed with TypeScript. All types are exported:\n\n```typescript\nimport type { \n  AgentBillConfig, \n  TraceContext, \n  SpanData,\n  AICallMetrics,\n  SupportedProvider \n} from '@agentbill/sdk';\n```\n\n## Requirements\n\n- Node.js 16+\n- TypeScript 5.0+ (for TypeScript projects)\n- OpenAI SDK 4.0+ (if using OpenAI)\n- Anthropic SDK 0.9+ (if using Anthropic)\n\n## License\n\nMIT\n\n## Support\n\nFor issues, questions, or feature requests, visit: https://github.com/yourusername/agentbill-sdk\n","readmeFilename":"README.md","_rev":"1-51a3a833a5925f6006878cb4424b4105"}