the-token-company 0.1.1 → 0.2.1

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 CHANGED
@@ -1,7 +1,17 @@
1
+ <div align="center">
2
+
1
3
  # The Token Company Node.js SDK
2
4
 
3
5
  Compress LLM prompts to reduce costs and latency. 100K tokens compressed in ~85ms.
4
6
 
7
+ [![CI](https://github.com/TheTokenCompany/the-token-company-node/actions/workflows/ci.yml/badge.svg)](https://github.com/TheTokenCompany/the-token-company-node/actions/workflows/ci.yml)
8
+ [![npm version](https://img.shields.io/npm/v/the-token-company)](https://www.npmjs.com/package/the-token-company)
9
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/TheTokenCompany/the-token-company-node/blob/main/LICENSE)
10
+
11
+ [Docs](https://thetokencompany.com/docs) · [Website](https://thetokencompany.com) · [Dashboard](https://app.thetokencompany.com) · [Python SDK](https://github.com/TheTokenCompany/the-token-company-python)
12
+
13
+ </div>
14
+
5
15
  ## Install
6
16
 
7
17
  ```bash
@@ -107,8 +117,6 @@ const model = wrapLanguageModel({
107
117
  |------------|------------------------|
108
118
  | `bear-2` | Latest, recommended |
109
119
  | `bear-1.2` | Previous generation |
110
- | `bear-1.1` | Legacy |
111
- | `bear-1` | Legacy |
112
120
 
113
121
  ## Aggressiveness
114
122
 
@@ -131,6 +139,24 @@ withCompression(client, {
131
139
  | `system` | `role: "system"` messages | `system` parameter | System messages |
132
140
  | `tool` | `tool` + `function` messages | `tool_result` content blocks | Tool result parts |
133
141
 
142
+ ## App ID
143
+
144
+ Tag compression requests with an application identifier for usage tracking:
145
+
146
+ ```ts
147
+ // Set on the client — applies to all requests
148
+ const client = new TheTokenCompany({ apiKey: "ttc-...", appId: "my-chatbot" });
149
+
150
+ // Or per-request (overrides the client-level value)
151
+ const result = await client.compress(text, { model: "bear-2", appId: "my-chatbot" });
152
+ ```
153
+
154
+ Also supported in wrappers:
155
+
156
+ ```ts
157
+ const client = withCompression(new OpenAI(), { compressionApiKey: "ttc-...", appId: "my-chatbot" });
158
+ ```
159
+
134
160
  ## Gzip
135
161
 
136
162
  Gzip compression of request payloads is on by default. Disable with:
package/dist/ai-sdk.js CHANGED
@@ -17,7 +17,7 @@ import { CompressionStats } from "./types.js";
17
17
  */
18
18
  export function compressionMiddleware(options) {
19
19
  const stats = new CompressionStats();
20
- const analytics = new AnalyticsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey }), stats);
20
+ const analytics = new AnalyticsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId }), stats);
21
21
  const compressionModel = options.model ?? "bear-2";
22
22
  const roleAggr = resolveAggressiveness(options.aggressiveness ?? 0.2);
23
23
  const middleware = {
package/dist/anthropic.js CHANGED
@@ -24,7 +24,7 @@ import { CompressionStats } from "./types.js";
24
24
  */
25
25
  export function withCompression(client, options) {
26
26
  const stats = new CompressionStats();
27
- const analytics = new AnalyticsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey }), stats);
27
+ const analytics = new AnalyticsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId }), stats);
28
28
  const model = options.model ?? "bear-2";
29
29
  const roleAggr = resolveAggressiveness(options.aggressiveness ?? 0.2);
30
30
  const systemAggr = roleAggr["system"];
package/dist/client.d.ts CHANGED
@@ -8,10 +8,12 @@ export declare class TheTokenCompany {
8
8
  private readonly apiKey;
9
9
  private readonly timeout;
10
10
  private readonly gzip;
11
+ private readonly appId?;
11
12
  constructor(options: TheTokenCompanyOptions);
12
13
  compress(text: string, options?: {
13
14
  model?: string;
14
15
  aggressiveness?: number;
16
+ appId?: string;
15
17
  }): Promise<CompressResult>;
16
18
  private parseError;
17
19
  }
package/dist/client.js CHANGED
@@ -13,11 +13,13 @@ export class TheTokenCompany {
13
13
  apiKey;
14
14
  timeout;
15
15
  gzip;
16
+ appId;
16
17
  constructor(options) {
17
18
  this.apiKey = options.apiKey;
18
19
  this.baseUrl = (options.baseUrl ?? BASE_URL).replace(/\/$/, "");
19
20
  this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
20
21
  this.gzip = options.gzip ?? true;
22
+ this.appId = options.appId;
21
23
  }
22
24
  async compress(text, options = {}) {
23
25
  const { model = "bear-2", aggressiveness = 0.2 } = options;
@@ -27,10 +29,12 @@ export class TheTokenCompany {
27
29
  if (aggressiveness < 0 || aggressiveness > 1) {
28
30
  throw new InvalidRequestError("aggressiveness must be between 0.0 and 1.0");
29
31
  }
32
+ const resolvedAppId = options.appId ?? this.appId;
30
33
  const payload = {
31
34
  model,
32
35
  input: text,
33
36
  compression_settings: { aggressiveness },
37
+ ...(resolvedAppId !== undefined && { app_id: resolvedAppId }),
34
38
  };
35
39
  const jsonBody = JSON.stringify(payload);
36
40
  const headers = {
package/dist/openai.js CHANGED
@@ -22,7 +22,7 @@ import { CompressionStats } from "./types.js";
22
22
  */
23
23
  export function withCompression(client, options) {
24
24
  const stats = new CompressionStats();
25
- const analytics = new AnalyticsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey }), stats);
25
+ const analytics = new AnalyticsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId }), stats);
26
26
  const model = options.model ?? "bear-2";
27
27
  const roleAggr = resolveAggressiveness(options.aggressiveness ?? 0.2);
28
28
  const originalCreate = client.chat.completions.create.bind(client.chat.completions);
package/dist/types.d.ts CHANGED
@@ -4,6 +4,7 @@ export interface CompressRequest {
4
4
  compression_settings: {
5
5
  aggressiveness: number;
6
6
  };
7
+ app_id?: string;
7
8
  }
8
9
  export interface CompressResponse {
9
10
  output: string;
@@ -22,12 +23,14 @@ export interface TheTokenCompanyOptions {
22
23
  baseUrl?: string;
23
24
  timeout?: number;
24
25
  gzip?: boolean;
26
+ appId?: string;
25
27
  }
26
28
  export type Aggressiveness = number | Record<string, number>;
27
29
  export interface WithCompressionOptions {
28
30
  compressionApiKey: string;
29
31
  model?: string;
30
32
  aggressiveness?: Aggressiveness;
33
+ appId?: string;
31
34
  }
32
35
  export interface TurnStats {
33
36
  inputTokens: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "the-token-company",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "Node.js SDK for The Token Company — compress LLM prompts to reduce costs and latency",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",