@tollgateai/sdk 0.3.0 → 0.4.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/README.md +36 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Real-time gross-margin observability for AI agents. Track every LLM call's cost, attribute it to a customer, and see whether you're making money — before the invoice goes out.
|
|
4
4
|
|
|
5
|
-
**v0.
|
|
5
|
+
**v0.4.0** · [npm](https://www.npmjs.com/package/@tollgateai/sdk) · [Dashboard](https://tollgateai.vercel.app)
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -189,6 +189,7 @@ Every auto-instrumented call captures the following from the provider response:
|
|
|
189
189
|
| `cacheWrite5mTokens` | `cache_creation_input_tokens` | 5-min TTL cache write tokens |
|
|
190
190
|
| `cacheWrite1hTokens` | `cache_creation.ephemeral_1h_input_tokens` | 1-hour TTL cache write tokens |
|
|
191
191
|
| `toolCalls` | Content block / choice inspection | Number of tool calls in the response |
|
|
192
|
+
| `externalCostCents` | User-provided | Cost of external tools/services (image gen, sandbox, search) |
|
|
192
193
|
| `provider` | Wrapper default or override | `anthropic`, `openai`, `openai_compatible`, `bedrock` |
|
|
193
194
|
| `model` | Response object | Model identifier as reported by the provider |
|
|
194
195
|
|
|
@@ -224,6 +225,40 @@ For simple per-call billing, pass `revenueUnitCents` in the wrap options and ski
|
|
|
224
225
|
|
|
225
226
|
---
|
|
226
227
|
|
|
228
|
+
## External Tool Costs
|
|
229
|
+
|
|
230
|
+
AI agents often call external services — image generation, code sandboxes, search APIs, vector databases — that cost real money outside of LLM token pricing. Report these costs alongside the LLM call so Tollgate includes them in the margin calculation.
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
// Agent generates an image during the run
|
|
234
|
+
const image = await dalle.generate({ prompt: '...' }); // costs $0.04
|
|
235
|
+
|
|
236
|
+
await tollgate.track({
|
|
237
|
+
customerId: 'cust_acme',
|
|
238
|
+
runId: 'ticket_8842',
|
|
239
|
+
provider: 'openai',
|
|
240
|
+
model: 'gpt-4o',
|
|
241
|
+
tokensIn: 500,
|
|
242
|
+
tokensOut: 200,
|
|
243
|
+
toolCalls: 1, // LLM tool_use count (auto-extracted by wrappers)
|
|
244
|
+
externalCostCents: 4.0, // $0.04 for the DALL-E call
|
|
245
|
+
idempotencyKey: 'ticket_8842#step_2',
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Common examples:
|
|
250
|
+
|
|
251
|
+
| Service | Typical Cost | How to report |
|
|
252
|
+
|---|---|---|
|
|
253
|
+
| DALL-E image generation | ~$0.04/image | `externalCostCents: 4` |
|
|
254
|
+
| E2B code sandbox | ~$0.01/run | `externalCostCents: 1` |
|
|
255
|
+
| Tavily search API | ~$0.01/search | `externalCostCents: 1` |
|
|
256
|
+
| Pinecone vector query | ~$0.001/query | `externalCostCents: 0.1` |
|
|
257
|
+
|
|
258
|
+
External costs flow into the **Tools** bucket in the Customer Drawer's cost-split chart — so you can see exactly what share of each customer's cost comes from external services vs. LLM tokens.
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
227
262
|
## Customer & Plan Setup
|
|
228
263
|
|
|
229
264
|
Create customers and assign plans **before** sending usage so plan-priced revenue is recognized from the first event. Idempotent — safe to run on every boot.
|
package/dist/index.d.cts
CHANGED
|
@@ -28,6 +28,11 @@ interface TrackEventInput {
|
|
|
28
28
|
cacheWrite1hTokens?: number;
|
|
29
29
|
toolCalls?: number;
|
|
30
30
|
toolName?: string;
|
|
31
|
+
/** Cost in cents of external tools/services used in this event (image
|
|
32
|
+
* generation, code sandbox, search APIs, vector DB lookups, etc.).
|
|
33
|
+
* Added directly to the cost breakdown — no rate-card lookup needed.
|
|
34
|
+
* Fractional cents accepted (e.g. 1.5 for $0.015). */
|
|
35
|
+
externalCostCents?: number;
|
|
31
36
|
/** Terminal run outcome, set on the run's closing event only (omit on
|
|
32
37
|
* intermediate steps). Gates outcome-priced revenue. See `resolve()`. */
|
|
33
38
|
outcome?: RunOutcome;
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,11 @@ interface TrackEventInput {
|
|
|
28
28
|
cacheWrite1hTokens?: number;
|
|
29
29
|
toolCalls?: number;
|
|
30
30
|
toolName?: string;
|
|
31
|
+
/** Cost in cents of external tools/services used in this event (image
|
|
32
|
+
* generation, code sandbox, search APIs, vector DB lookups, etc.).
|
|
33
|
+
* Added directly to the cost breakdown — no rate-card lookup needed.
|
|
34
|
+
* Fractional cents accepted (e.g. 1.5 for $0.015). */
|
|
35
|
+
externalCostCents?: number;
|
|
31
36
|
/** Terminal run outcome, set on the run's closing event only (omit on
|
|
32
37
|
* intermediate steps). Gates outcome-priced revenue. See `resolve()`. */
|
|
33
38
|
outcome?: RunOutcome;
|