@modelcost/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +57 -0
- package/dist/index.d.mts +1208 -0
- package/dist/index.d.ts +1208 -0
- package/dist/index.js +2068 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2045 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +46 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@modelcost/sdk` will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2026-03-01
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial alpha release
|
|
12
|
+
- Cost tracking with automatic provider wrapping (OpenAI, Anthropic, Google)
|
|
13
|
+
- Budget enforcement with configurable actions (alert, throttle, block)
|
|
14
|
+
- PII detection scanning for SSN, email, phone, API keys, and credit cards
|
|
15
|
+
- Token bucket rate limiting
|
|
16
|
+
- Automatic background telemetry flushing
|
|
17
|
+
- Full TypeScript support with ESM and CommonJS builds
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 ModelCost
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @modelcost/sdk
|
|
2
|
+
|
|
3
|
+
Node.js SDK for ModelCost -- AI cost protection, budget enforcement, and PII detection.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @modelcost/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { ModelCost } from "@modelcost/sdk";
|
|
15
|
+
import OpenAI from "openai";
|
|
16
|
+
|
|
17
|
+
// Initialize
|
|
18
|
+
ModelCost.init({
|
|
19
|
+
apiKey: "mc_your_api_key_here",
|
|
20
|
+
orgId: "your-org-id",
|
|
21
|
+
monthlyBudget: 500,
|
|
22
|
+
budgetAction: "block",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Wrap your AI client
|
|
26
|
+
const openai = ModelCost.wrap(new OpenAI());
|
|
27
|
+
|
|
28
|
+
// All calls are now tracked and budget-enforced
|
|
29
|
+
const response = await openai.chat.completions.create({
|
|
30
|
+
model: "gpt-4o",
|
|
31
|
+
messages: [{ role: "user", content: "Hello!" }],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Check budget status
|
|
35
|
+
const budget = await ModelCost.checkBudget("organization", "your-org-id");
|
|
36
|
+
console.log(`Allowed: ${budget.allowed}`);
|
|
37
|
+
|
|
38
|
+
// Scan for PII
|
|
39
|
+
const pii = await ModelCost.scanPii("My SSN is 123-45-6789");
|
|
40
|
+
console.log(`PII detected: ${pii.detected}`);
|
|
41
|
+
|
|
42
|
+
// Shutdown gracefully
|
|
43
|
+
await ModelCost.shutdown();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Environment Variables
|
|
47
|
+
|
|
48
|
+
| Variable | Description |
|
|
49
|
+
|---|---|
|
|
50
|
+
| `MODELCOST_API_KEY` | API key (mc_ prefix) |
|
|
51
|
+
| `MODELCOST_ORG_ID` | Organization ID |
|
|
52
|
+
| `MODELCOST_ENV` | Environment (default: production) |
|
|
53
|
+
| `MODELCOST_BASE_URL` | API base URL |
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
MIT
|