compress-lightreach 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/README.md +330 -80
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,25 +1,26 @@
1
1
  # Compress Light Reach
2
2
 
3
- **Intelligent compression algorithms for LLM prompts that reduce token usage**
3
+ **AI cost management SDK with intelligent model routing, prompt compression, and real-time token tracking**
4
4
 
5
5
  [![npm version](https://badge.fury.io/js/compress-lightreach.svg)](https://badge.fury.io/js/compress-lightreach)
6
6
  [![Node.js 14+](https://img.shields.io/badge/node-14+-blue.svg)](https://nodejs.org/)
7
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
8
 
9
- Compress Light Reach is a Node.js/TypeScript library that intelligently compresses LLM prompts by replacing repeated substrings with shorter placeholders, significantly reducing token usage and costs while maintaining perfect decompression.
9
+ Compress Light Reach is a Node.js/TypeScript SDK that provides intelligent model routing and prompt compression for LLM applications, reducing token usage and costs while maintaining quality.
10
10
 
11
11
  ## Features
12
12
 
13
- - **Token-aware compression**: Only replaces substrings >1 token with 1-token placeholders
14
- - **Dual algorithms**:
13
+ - **Intelligent Model Routing**: Automatically selects optimal model based on quality requirements (HLE) and available provider keys
14
+ - **Token-aware Compression**: Replaces repeated substrings with shorter placeholders
15
+ - **Dual Algorithms**:
15
16
  - Fast greedy (~99% optimal) for daily use
16
17
  - Optimal DP (O(n²)) for critical prompts
17
18
  - **Lossless**: Perfect decompression guaranteed
18
- - **Output compression**: Optional model output compression support
19
- - **Cloud API**: Uses Light Reach's cloud service for compression
20
- - **Model-aware**: Optimized for GPT-4, GPT-3.5-turbo, Claude, and more
19
+ - **Output Compression**: Optional model output compression support
20
+ - **Cloud API**: Uses Light Reach's cloud service for compression and routing
21
+ - **Multi-provider Support**: OpenAI, Anthropic, Google, DeepSeek, Moonshot
21
22
  - **TypeScript**: Full TypeScript support with type definitions
22
- - **Intelligent Routing**: Automatic model selection based on quality requirements
23
+ - **BYOK**: Provider API keys managed securely in dashboard (never passed through SDK)
23
24
 
24
25
  ## Installation
25
26
 
@@ -33,12 +34,12 @@ or
33
34
  yarn add compress-lightreach
34
35
  ```
35
36
 
36
- ## Quick Start (v1.0.0)
37
+ ## Quick Start
37
38
 
38
39
  The SDK uses **intelligent model routing** and targets `POST /api/v2/complete`.
39
40
 
40
- - Authenticate with your **LightReach API key** (env var `PCOMPRESLR_API_KEY`)
41
- - Manage **provider keys** (OpenAI/Anthropic/Google) in the dashboard (BYOK)
41
+ - Authenticate with your **LightReach API key** (env var `PCOMPRESLR_API_KEY` or `LIGHTREACH_API_KEY`)
42
+ - Manage **provider keys** (OpenAI/Anthropic/Google/etc.) in the dashboard (BYOK)
42
43
  - System automatically selects optimal model based on your requirements
43
44
 
44
45
  ```typescript
@@ -51,7 +52,7 @@ const result = await client.complete({
51
52
  { role: 'system', content: 'You are a helpful assistant.' },
52
53
  { role: 'user', content: 'Explain quantum computing in simple terms.' },
53
54
  ],
54
- desiredHle: 30, // Quality preference (0-40, where 40 is SOTA)
55
+ desired_hle: 30, // Quality preference (0-40, where 40 is SOTA)
55
56
  });
56
57
 
57
58
  console.log(result.decompressed_response);
@@ -64,14 +65,14 @@ console.log(`Token savings: ${result.compression_stats.token_savings}`);
64
65
  ```typescript
65
66
  const result = await client.complete({
66
67
  messages: [{ role: 'user', content: 'Generate a long report...' }],
67
- desiredHle: 25,
68
- compressOutput: true,
68
+ desired_hle: 25,
69
+ compress_output: true,
69
70
  });
70
71
 
71
72
  console.log(result.decompressed_response);
72
73
  ```
73
74
 
74
- ### Intelligent Model Routing (v1.0.0)
75
+ ### Intelligent Model Routing
75
76
 
76
77
  The system automatically selects the optimal model based on quality requirements and your available provider keys:
77
78
 
@@ -82,14 +83,14 @@ const client = new PcompresslrAPIClient("your-lightreach-api-key");
82
83
 
83
84
  // Cross-provider optimization: system picks cheapest model meeting your quality bar
84
85
  const result = await client.complete({
85
- messages: [{role: 'user', content: 'Explain quantum computing'}],
86
- desiredHle: 30, // Quality preference (0-40, where 40 is SOTA)
86
+ messages: [{ role: 'user', content: 'Explain quantum computing' }],
87
+ desired_hle: 30, // Quality preference (0-40, where 40 is SOTA)
87
88
  });
88
89
 
89
90
  // Check what was selected
90
- console.log(result.routing_info?.selected_model); // e.g., "gpt-4o-mini"
91
- console.log(result.routing_info?.selected_provider); // e.g., "openai"
92
- console.log(result.routing_info?.model_hle); // e.g., 32.5
91
+ console.log(result.routing_info?.selected_model); // e.g., "gpt-4o-mini"
92
+ console.log(result.routing_info?.selected_provider); // e.g., "openai"
93
+ console.log(result.routing_info?.model_hle); // e.g., 32.5
93
94
  console.log(result.routing_info?.model_price_per_million); // e.g., 0.15
94
95
  ```
95
96
 
@@ -100,24 +101,24 @@ Optionally constrain to a specific provider:
100
101
  ```typescript
101
102
  // Only use OpenAI models, but pick the cheapest one meeting HLE 35
102
103
  const result = await client.complete({
103
- messages: [{role: 'user', content: 'Write a poem'}],
104
- llmProvider: 'openai', // Optional: constrain to one provider
105
- desiredHle: 35,
104
+ messages: [{ role: 'user', content: 'Write a poem' }],
105
+ llm_provider: 'openai', // Optional: constrain to one provider
106
+ desired_hle: 35,
106
107
  });
107
108
  ```
108
109
 
109
110
  ### HLE Cascading with Admin Controls
110
111
 
111
- Admins can set quality **ceilings** via the dashboard (global or per-tag) to control costs. Your `desiredHle` is a preference, but requests will error if they exceed the admin-set ceiling:
112
+ Admins can set quality **ceilings** via the dashboard (global or per-tag) to control costs. Your `desired_hle` is a preference, but requests will error if they exceed the admin-set ceiling:
112
113
 
113
114
  ```typescript
114
115
  // Admin set global HLE ceiling to 30%
115
116
  // Requesting above the ceiling will error
116
117
  try {
117
118
  const result = await client.complete({
118
- messages: [{role: 'user', content: 'Process payment'}],
119
- desiredHle: 35, // ERROR: exceeds ceiling of 30
120
- tags: {env: 'production'},
119
+ messages: [{ role: 'user', content: 'Process payment' }],
120
+ desired_hle: 35, // ERROR: exceeds ceiling of 30
121
+ tags: { env: 'production' },
121
122
  });
122
123
  } catch (e) {
123
124
  console.error(e.message); // "Requested HLE 35% exceeds workspace maximum of 30%"
@@ -125,9 +126,9 @@ try {
125
126
 
126
127
  // Correct usage: request within ceiling
127
128
  const result = await client.complete({
128
- messages: [{role: 'user', content: 'Process payment'}],
129
- desiredHle: 25, // OK: below ceiling of 30
130
- tags: {env: 'production'},
129
+ messages: [{ role: 'user', content: 'Process payment' }],
130
+ desired_hle: 25, // OK: below ceiling of 30
131
+ tags: { env: 'production' },
131
132
  });
132
133
 
133
134
  // Check if your HLE was lowered by admin ceiling
@@ -138,6 +139,61 @@ if (result.routing_info?.hle_clamped) {
138
139
  }
139
140
  ```
140
141
 
142
+ ### Using the LightReach Wrapper Class
143
+
144
+ For a more ergonomic API with camelCase parameters, use the `LightReach` class:
145
+
146
+ ```typescript
147
+ import { LightReach } from 'compress-lightreach';
148
+
149
+ const client = new LightReach({
150
+ apiKey: 'your-lightreach-api-key',
151
+ defaultModel: 'gpt-4',
152
+ defaultProvider: 'openai',
153
+ useOptimal: false, // Use greedy algorithm by default
154
+ });
155
+
156
+ const result = await client.complete({
157
+ messages: [{ role: 'user', content: 'Hello!' }],
158
+ compress: true,
159
+ compressOutput: false,
160
+ compressionConfig: {
161
+ compressSystem: false,
162
+ compressUser: true,
163
+ compressAssistant: false,
164
+ compressOnlyLastNUser: 1,
165
+ },
166
+ temperature: 0.7,
167
+ maxTokens: 1000,
168
+ tags: { env: 'production' },
169
+ });
170
+
171
+ console.log(result.decompressed_response);
172
+ ```
173
+
174
+ ### Compression Only (No LLM Call)
175
+
176
+ ```typescript
177
+ import { PcompresslrAPIClient } from 'compress-lightreach';
178
+
179
+ const client = new PcompresslrAPIClient("your-lightreach-api-key");
180
+
181
+ // Compress text without making an LLM call
182
+ const compressed = await client.compress(
183
+ "Your text with repeated content here...",
184
+ "gpt-4", // Model for tokenization
185
+ "greedy", // Algorithm: 'greedy' or 'optimal'
186
+ { env: 'dev' } // Optional tags
187
+ );
188
+
189
+ console.log(compressed.llm_format);
190
+ console.log(`Compression ratio: ${compressed.compression_ratio}`);
191
+
192
+ // Decompress later
193
+ const decompressed = await client.decompress(compressed.llm_format);
194
+ console.log(decompressed.decompressed);
195
+ ```
196
+
141
197
  ### Command Line Interface
142
198
 
143
199
  ```bash
@@ -145,7 +201,6 @@ if (result.routing_info?.hle_clamped) {
145
201
  export PCOMPRESLR_API_KEY=your-api-key
146
202
 
147
203
  # Compress a prompt
148
- # Run the CLI directly (the published binary name is `pcompresslr`)
149
204
  npx pcompresslr "Your prompt with repeated text here..."
150
205
 
151
206
  # Use optimal algorithm only
@@ -161,67 +216,239 @@ npx pcompresslr "Your prompt here" --greedy-only
161
216
 
162
217
  Main API client for intelligent model routing and compression.
163
218
 
164
- #### Constructor Parameters
219
+ #### Constructor
220
+
221
+ ```typescript
222
+ new PcompresslrAPIClient(apiKey?: string, apiUrl?: string, timeout?: number)
223
+ ```
165
224
 
166
- - `apiKey` (string, optional): LightReach API key (or use `PCOMPRESLR_API_KEY` env var).
167
- - `apiUrl` (string, optional): Override base API URL (advanced/testing).
168
- - `timeout` (number): Request timeout in milliseconds (default: 120000).
225
+ **Parameters:**
226
+ - `apiKey` (string, optional): LightReach API key. Falls back to `LIGHTREACH_API_KEY` or `PCOMPRESLR_API_KEY` env vars.
227
+ - `apiUrl` (string, optional): Override base API URL. Falls back to `PCOMPRESLR_API_URL` env var. Default: `https://api.compress.lightreach.io`
228
+ - `timeout` (number, optional): Request timeout in milliseconds. Default: `120000` (2 minutes)
169
229
 
170
230
  #### Methods
171
231
 
172
- ##### `complete(request)`
232
+ ##### `complete(request: CompleteV2Request): Promise<CompleteResponse>`
173
233
 
174
234
  Messages-first completion with intelligent routing (POST `/api/v2/complete`).
175
235
 
176
- **Parameters (CompleteV2Request):**
177
- - `messages` (required): Conversation history as array of objects with `role` and `content`
178
- - `llmProvider` (optional): Provider constraint (`'openai'`, `'anthropic'`, `'google'`, etc.). Omit for cross-provider optimization.
179
- - `desiredHle` (optional): Quality preference (0-40, where 40 is SOTA). Must not exceed admin's global/tag-level ceilings (request will error if it does).
180
- - `tags` (optional): Object of tags for cost attribution and tag-level HLE ceilings
181
- - `compress` (optional): Whether to compress messages (default: `true`)
182
- - `compressOutput` (optional): Whether to request compressed output from LLM (default: `false`)
183
- - `algorithm` (optional): Compression algorithm (`'greedy'` or `'optimal'`, default: `'greedy'`)
184
- - `temperature` (optional): LLM temperature parameter
185
- - `maxTokens` (optional): Maximum tokens to generate
186
- - `compressionConfig` (optional): Per-role compression settings
187
- - `maxHistoryMessages` (optional): Limit conversation history length
188
-
189
- **Response (CompleteResponse) includes:**
190
- - `decompressed_response`: Final decompressed LLM response
191
- - `routing_info`: Details about model selection:
192
- - `selected_model`: Model chosen by system
193
- - `selected_provider`: Provider chosen by system
194
- - `model_hle`: HLE score of selected model
195
- - `effective_hle`: Effective HLE after applying admin ceilings (min of desired/tag/global)
196
- - `hle_source`: `'request'`, `'tag'`, `'global'`, or `'none'`
197
- - `hle_clamped`: `true` if admin ceiling lowered your `desiredHle`
198
- - `compression_stats`: Token savings statistics
199
- - `llm_stats`: Token usage from the LLM
200
- - `warnings`: Array of any warnings (including HLE ceiling notifications)
201
-
202
- ##### `compress(prompt, model, algorithm, tags)`
236
+ **Request Parameters (`CompleteV2Request`):**
237
+
238
+ | Parameter | Type | Default | Description |
239
+ |-----------|------|---------|-------------|
240
+ | `messages` | `Message[]` | required | Conversation history with `role` and `content` |
241
+ | `llm_provider` | `'openai' \| 'anthropic' \| 'google' \| 'deepseek' \| 'moonshot'` | — | Optional provider constraint. Omit for cross-provider optimization |
242
+ | `desired_hle` | `number` | — | Quality preference (0-40, where 40 is SOTA). Must not exceed admin ceilings |
243
+ | `compress` | `boolean` | `true` | Whether to compress messages |
244
+ | `compress_output` | `boolean` | `false` | Whether to request compressed output from LLM |
245
+ | `algorithm` | `'greedy' \| 'optimal'` | `'greedy'` | Compression algorithm |
246
+ | `compression_config` | `object` | — | Per-role compression settings (see below) |
247
+ | `temperature` | `number` | | LLM temperature parameter |
248
+ | `max_tokens` | `number` | — | Maximum tokens to generate |
249
+ | `tags` | `Record<string, string>` | — | Tags for cost attribution and tag-level HLE ceilings |
250
+ | `max_history_messages` | `number` | — | Limit conversation history length |
251
+
252
+ **`compression_config` options:**
253
+
254
+ ```typescript
255
+ {
256
+ compress_system?: boolean; // default: false
257
+ compress_user?: boolean; // default: true
258
+ compress_assistant?: boolean; // default: false
259
+ compress_only_last_n_user?: number | null; // default: 1
260
+ }
261
+ ```
262
+
263
+ **Response (`CompleteResponse`):**
264
+
265
+ ```typescript
266
+ {
267
+ decompressed_response: string; // Final decompressed LLM response
268
+ compression_stats: {
269
+ original_size_chars: number;
270
+ compressed_size_chars: number;
271
+ original_tokens: number;
272
+ compressed_tokens: number;
273
+ compression_ratio: number;
274
+ token_savings: number;
275
+ token_savings_percent: number;
276
+ processing_time_ms?: number;
277
+ };
278
+ llm_stats: {
279
+ prompt_tokens: number;
280
+ completion_tokens: number;
281
+ total_tokens: number;
282
+ };
283
+ routing_info?: {
284
+ selected_model: string; // Model chosen by system
285
+ selected_provider: string; // Provider chosen by system
286
+ selected_model_id: string;
287
+ model_hle: number; // HLE score of selected model
288
+ model_price_per_million: number;
289
+ requested_hle: number | null;
290
+ effective_hle: number | null; // Effective HLE after admin ceilings
291
+ hle_source: 'request' | 'tag' | 'global' | 'none';
292
+ hle_clamped: boolean; // true if admin ceiling lowered your desired_hle
293
+ };
294
+ warnings?: string[];
295
+
296
+ // Convenience aliases
297
+ text?: string; // Alias for decompressed_response
298
+ tokens_saved?: number; // Alias for compression_stats.token_savings
299
+ tokens_used?: number; // Alias for llm_stats.total_tokens
300
+ compression_ratio?: number; // Alias for compression_stats.compression_ratio
301
+ }
302
+ ```
303
+
304
+ ##### `compress(prompt, model?, algorithm?, tags?): Promise<CompressResponse>`
203
305
 
204
306
  Compression-only (POST `/api/v1/compress`).
205
307
 
206
- ##### `decompress(llmFormat)`
308
+ **Parameters:**
309
+ - `prompt` (string, required): Text to compress
310
+ - `model` (string, optional): Model for tokenization. Default: `'gpt-4'`
311
+ - `algorithm` (`'greedy' | 'optimal'`, optional): Compression algorithm. Default: `'greedy'`
312
+ - `tags` (`Record<string, string>`, optional): Tags for attribution
313
+
314
+ **Response (`CompressResponse`):**
315
+
316
+ ```typescript
317
+ {
318
+ compressed: string;
319
+ dictionary: Record<string, string>;
320
+ llm_format: string;
321
+ compression_ratio: number;
322
+ original_size: number;
323
+ compressed_size: number;
324
+ processing_time_ms: number;
325
+ algorithm: string;
326
+ }
327
+ ```
328
+
329
+ ##### `decompress(llmFormat): Promise<DecompressResponse>`
207
330
 
208
331
  Decompress an LLM-formatted compressed prompt (POST `/api/v1/decompress`).
209
332
 
210
- ##### `healthCheck()`
333
+ **Parameters:**
334
+ - `llmFormat` (string, required): The `llm_format` string from a compress response
335
+
336
+ **Response (`DecompressResponse`):**
337
+
338
+ ```typescript
339
+ {
340
+ decompressed: string;
341
+ processing_time_ms: number;
342
+ }
343
+ ```
344
+
345
+ ##### `healthCheck(): Promise<HealthCheckResponse>`
211
346
 
212
347
  Check API health status (GET `/health`).
213
348
 
349
+ **Response:**
350
+
351
+ ```typescript
352
+ {
353
+ status: string;
354
+ version?: string;
355
+ }
356
+ ```
357
+
358
+ ### `LightReach` Class
359
+
360
+ Convenience wrapper with camelCase parameters.
361
+
362
+ #### Constructor
363
+
364
+ ```typescript
365
+ new LightReach(options?: {
366
+ apiKey?: string;
367
+ apiUrl?: string;
368
+ defaultModel?: string; // Default: 'gpt-4'
369
+ defaultProvider?: 'openai' | 'anthropic' | 'google'; // Default: 'openai'
370
+ useOptimal?: boolean; // Default: false (use greedy)
371
+ })
372
+ ```
373
+
374
+ #### Methods
375
+
376
+ ##### `complete(options: CompleteOptions): Promise<CompleteResponse>`
377
+
378
+ ```typescript
379
+ interface CompleteOptions {
380
+ messages: Message[];
381
+ model?: string;
382
+ provider?: 'openai' | 'anthropic' | 'google';
383
+ compress?: boolean;
384
+ compressionConfig?: {
385
+ compressSystem?: boolean;
386
+ compressUser?: boolean;
387
+ compressAssistant?: boolean;
388
+ compressOnlyLastNUser?: number | null;
389
+ };
390
+ compressOutput?: boolean;
391
+ useOptimal?: boolean;
392
+ temperature?: number;
393
+ maxTokens?: number;
394
+ tags?: Record<string, string>;
395
+ maxHistoryMessages?: number;
396
+ }
397
+ ```
398
+
399
+ ##### `compress(text, options?): Promise<CompressResponse>`
400
+
401
+ ```typescript
402
+ await client.compress(text, {
403
+ model?: string;
404
+ algorithm?: 'greedy' | 'optimal';
405
+ tags?: Record<string, string>;
406
+ });
407
+ ```
408
+
409
+ ### Message Types
410
+
411
+ ```typescript
412
+ type MessageRole = 'system' | 'developer' | 'user' | 'assistant';
413
+
414
+ interface Message {
415
+ role: MessageRole;
416
+ content: string;
417
+ }
418
+ ```
419
+
214
420
  ### Environment Variables
215
421
 
216
- - `PCOMPRESLR_API_KEY` (or `LIGHTREACH_API_KEY`): Your LightReach API key.
217
- - `PCOMPRESLR_API_URL`: Override the API base URL (advanced/testing).
422
+ | Variable | Description |
423
+ |----------|-------------|
424
+ | `PCOMPRESLR_API_KEY` | Your LightReach API key (primary) |
425
+ | `LIGHTREACH_API_KEY` | Your LightReach API key (alternative) |
426
+ | `PCOMPRESLR_API_URL` | Override the API base URL (advanced/testing) |
218
427
 
219
428
  ### Exceptions
220
429
 
221
- - `APIKeyError`: Raised when API key is invalid or missing
222
- - `RateLimitError`: Raised when rate limit is exceeded
223
- - `APIRequestError`: Raised for general API errors (including routing failures)
224
- - `PcompresslrAPIError`: Base exception class
430
+ | Exception | Description |
431
+ |-----------|-------------|
432
+ | `PcompresslrAPIError` | Base exception class |
433
+ | `APIKeyError` | Invalid or missing API key |
434
+ | `RateLimitError` | Rate limit exceeded |
435
+ | `APIRequestError` | General API errors (including routing failures) |
436
+
437
+ ```typescript
438
+ import { APIKeyError, RateLimitError, APIRequestError } from 'compress-lightreach';
439
+
440
+ try {
441
+ const result = await client.complete({ messages: [...] });
442
+ } catch (error) {
443
+ if (error instanceof APIKeyError) {
444
+ console.error('Invalid API key');
445
+ } else if (error instanceof RateLimitError) {
446
+ console.error('Rate limited, please retry later');
447
+ } else if (error instanceof APIRequestError) {
448
+ console.error('API error:', error.message);
449
+ }
450
+ }
451
+ ```
225
452
 
226
453
  ## How It Works
227
454
 
@@ -237,7 +464,7 @@ The library:
237
464
 
238
465
  ## Examples
239
466
 
240
- ### Example 1: Using Complete Method (Recommended)
467
+ ### Example 1: Complete with Compression
241
468
 
242
469
  ```typescript
243
470
  import { PcompresslrAPIClient } from 'compress-lightreach';
@@ -250,10 +477,9 @@ Write a story about a dog. The dog is very friendly.
250
477
  Write a story about a bird. The bird is very friendly.
251
478
  `;
252
479
 
253
- // One call handles compression, LLM request, and decompression
254
480
  const result = await client.complete({
255
481
  messages: [{ role: "user", content: prompt }],
256
- desiredHle: 30,
482
+ desired_hle: 30,
257
483
  });
258
484
 
259
485
  console.log(result.decompressed_response);
@@ -262,22 +488,46 @@ console.log(`Token savings: ${result.compression_stats.token_savings} tokens`);
262
488
  console.log(`Compression ratio: ${(result.compression_stats.compression_ratio * 100).toFixed(2)}%`);
263
489
  ```
264
490
 
265
- ### Example 2: Complete with Output Compression
491
+ ### Example 2: Output Compression
266
492
 
267
493
  ```typescript
268
494
  import { PcompresslrAPIClient } from 'compress-lightreach';
269
495
 
270
496
  const client = new PcompresslrAPIClient("your-lightreach-api-key");
271
497
 
272
- // Complete with output compression - response is automatically decompressed
273
498
  const result = await client.complete({
274
499
  messages: [{ role: "user", content: "Generate a long report with repeated sections..." }],
275
- desiredHle: 35,
276
- compressOutput: true
500
+ desired_hle: 35,
501
+ compress_output: true,
277
502
  });
503
+
278
504
  console.log(result.decompressed_response);
279
505
  ```
280
506
 
507
+ ### Example 3: Multi-turn Conversation
508
+
509
+ ```typescript
510
+ import { PcompresslrAPIClient } from 'compress-lightreach';
511
+
512
+ const client = new PcompresslrAPIClient("your-lightreach-api-key");
513
+
514
+ const result = await client.complete({
515
+ messages: [
516
+ { role: "system", content: "You are a helpful coding assistant." },
517
+ { role: "user", content: "How do I read a file in Python?" },
518
+ { role: "assistant", content: "You can use open() with a context manager..." },
519
+ { role: "user", content: "How about writing to a file?" },
520
+ ],
521
+ desired_hle: 30,
522
+ compression_config: {
523
+ compress_system: false,
524
+ compress_user: true,
525
+ compress_assistant: false,
526
+ compress_only_last_n_user: 2, // Only compress last 2 user messages
527
+ },
528
+ });
529
+ ```
530
+
281
531
  ## Getting an API Key
282
532
 
283
533
  To use Compress Light Reach, you need an API key from [compress.lightreach.io](https://compress.lightreach.io).
@@ -289,7 +539,7 @@ To use Compress Light Reach, you need an API key from [compress.lightreach.io](h
289
539
 
290
540
  ## Security & Privacy
291
541
 
292
- **BYOK model:** Provider keys (OpenAI/Anthropic/Google) are managed in the dashboard and **never passed through this SDK**. The SDK only uses your LightReach API key for authentication with the service.
542
+ **BYOK model:** Provider keys (OpenAI/Anthropic/Google/etc.) are managed in the dashboard and **never passed through this SDK**. The SDK only uses your LightReach API key for authentication with the service.
293
543
 
294
544
  ## Requirements
295
545
 
@@ -298,7 +548,7 @@ To use Compress Light Reach, you need an API key from [compress.lightreach.io](h
298
548
 
299
549
  ## License
300
550
 
301
- MIT License - see [LICENSE](../LICENSE) file for details.
551
+ MIT License - see [LICENSE](./LICENSE) file for details.
302
552
 
303
553
  ## Support
304
554
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compress-lightreach",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "AI cost management SDK with intelligent model routing, prompt compression, and real-time token tracking",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",