slash-tokens 0.3.0 → 1.0.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 +8 -20
- package/dist/auto.js +22 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,35 +4,23 @@ Pre-flight checks for API calls. 4.8 KB WASM. Sub-millisecond. Zero dependencies
|
|
|
4
4
|
|
|
5
5
|
**Fly First. Pay Economy.**
|
|
6
6
|
|
|
7
|
-
## Install
|
|
8
|
-
|
|
9
7
|
```bash
|
|
10
8
|
npm install slash-tokens
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
## Use
|
|
14
|
-
|
|
15
11
|
```js
|
|
16
|
-
import {
|
|
12
|
+
import { preflight } from 'slash-tokens'
|
|
17
13
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
if (tokens > contextWindow) trim(prompt)
|
|
21
|
-
if (tokens < cheapThreshold) useHaiku()
|
|
14
|
+
const check = preflight(prompt, 'claude-opus')
|
|
15
|
+
// tokens: 47,000 | cost: $0.71 | 11 cheaper options | save 99%
|
|
22
16
|
```
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
## Evaluate a repo
|
|
18
|
+
Or one line — every API call pre-flighted automatically:
|
|
27
19
|
|
|
28
|
-
```
|
|
29
|
-
|
|
20
|
+
```js
|
|
21
|
+
import 'slash-tokens/auto'
|
|
30
22
|
```
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Everything is at **[slashtokens.com](https://slashtokens.com)**
|
|
35
|
-
|
|
36
|
-
## License
|
|
24
|
+
Full docs, examples, and model pricing at **[GitHub](https://github.com/Wolfe-Jam/slash-tokens)**
|
|
37
25
|
|
|
38
|
-
MIT
|
|
26
|
+
[slashtokens.com](https://slashtokens.com) | MIT
|
package/dist/auto.js
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { patchFetch, onIntercept } from './intercept.js';
|
|
2
|
+
import { report } from './transact.js';
|
|
3
|
+
import { hasKey } from './config.js';
|
|
2
4
|
// Auto mode: import this file and every LLM call is pre-flighted.
|
|
3
5
|
// Usage: import 'slash-tokens/auto'
|
|
6
|
+
//
|
|
7
|
+
// No key: console logging only (free forever)
|
|
8
|
+
// With key (init or SLASH_KEY): flight records sent to API
|
|
9
|
+
//
|
|
10
|
+
// Auto mode observes every call — it doesn't block.
|
|
11
|
+
// The data shows what you're spending and what you COULD save.
|
|
12
|
+
// When you start acting on preflight results (skip/reduce/route),
|
|
13
|
+
// the savings become real.
|
|
4
14
|
patchFetch();
|
|
5
|
-
// Default handler: log to console
|
|
6
15
|
onIntercept((event) => {
|
|
7
16
|
const status = event.fits ? 'OK' : 'OVER LIMIT';
|
|
8
17
|
console.log(`[slash] ${event.provider} ${event.model} | ${event.tokens.toLocaleString()} tokens | $${event.cost.toFixed(4)} | ${status}`);
|
|
18
|
+
// If key is configured, log the flight record (non-blocking)
|
|
19
|
+
if (hasKey() && event.tokens > 0) {
|
|
20
|
+
report({
|
|
21
|
+
tokens_estimated: event.tokens,
|
|
22
|
+
tokens_saved: 0,
|
|
23
|
+
model: event.model,
|
|
24
|
+
action: 'routed',
|
|
25
|
+
cost_saved_usd: 0,
|
|
26
|
+
}).catch(() => {
|
|
27
|
+
// Silent — never break the app for billing failures
|
|
28
|
+
});
|
|
29
|
+
}
|
|
9
30
|
});
|
package/dist/config.d.ts
CHANGED
package/dist/config.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export { MODELS, listModels } from './models.js';
|
|
|
5
5
|
export type { ModelInfo } from './models.js';
|
|
6
6
|
export { report } from './transact.js';
|
|
7
7
|
export type { ReportOptions, ReportResult } from './transact.js';
|
|
8
|
-
export { init } from './config.js';
|
|
8
|
+
export { init, hasKey } from './config.js';
|
|
9
9
|
export { resolveKey } from './config.js';
|
package/dist/index.js
CHANGED
package/package.json
CHANGED