@lockllm/sdk 1.0.1 → 1.2.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +223 -5
  2. package/README.md +272 -40
  3. package/dist/client.d.ts +1 -1
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/errors.d.ts +56 -1
  6. package/dist/errors.d.ts.map +1 -1
  7. package/dist/errors.js +132 -2
  8. package/dist/errors.js.map +1 -1
  9. package/dist/errors.mjs +127 -1
  10. package/dist/index.d.ts +6 -5
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +10 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.mjs +3 -2
  15. package/dist/scan.d.ts +20 -5
  16. package/dist/scan.d.ts.map +1 -1
  17. package/dist/scan.js +59 -5
  18. package/dist/scan.js.map +1 -1
  19. package/dist/scan.mjs +59 -5
  20. package/dist/types/common.d.ts +116 -0
  21. package/dist/types/common.d.ts.map +1 -1
  22. package/dist/types/errors.d.ts +39 -0
  23. package/dist/types/errors.d.ts.map +1 -1
  24. package/dist/types/scan.d.ts +118 -3
  25. package/dist/types/scan.d.ts.map +1 -1
  26. package/dist/utils/proxy-headers.d.ts +24 -0
  27. package/dist/utils/proxy-headers.d.ts.map +1 -0
  28. package/dist/utils/proxy-headers.js +234 -0
  29. package/dist/utils/proxy-headers.js.map +1 -0
  30. package/dist/utils/proxy-headers.mjs +229 -0
  31. package/dist/utils.d.ts +24 -0
  32. package/dist/utils.d.ts.map +1 -1
  33. package/dist/utils.js +28 -0
  34. package/dist/utils.js.map +1 -1
  35. package/dist/utils.mjs +27 -0
  36. package/dist/wrappers/anthropic-wrapper.d.ts +10 -1
  37. package/dist/wrappers/anthropic-wrapper.d.ts.map +1 -1
  38. package/dist/wrappers/anthropic-wrapper.js +17 -2
  39. package/dist/wrappers/anthropic-wrapper.js.map +1 -1
  40. package/dist/wrappers/anthropic-wrapper.mjs +17 -2
  41. package/dist/wrappers/generic-wrapper.d.ts +5 -0
  42. package/dist/wrappers/generic-wrapper.d.ts.map +1 -1
  43. package/dist/wrappers/generic-wrapper.js +12 -1
  44. package/dist/wrappers/generic-wrapper.js.map +1 -1
  45. package/dist/wrappers/generic-wrapper.mjs +12 -1
  46. package/dist/wrappers/openai-wrapper.d.ts +10 -1
  47. package/dist/wrappers/openai-wrapper.d.ts.map +1 -1
  48. package/dist/wrappers/openai-wrapper.js +17 -2
  49. package/dist/wrappers/openai-wrapper.js.map +1 -1
  50. package/dist/wrappers/openai-wrapper.mjs +17 -2
  51. package/package.json +2 -2
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  **All-in-One AI Security for LLM Applications**
12
12
 
13
- *Keep control of your AI. Detect prompt injection, jailbreaks, and adversarial attacks in real-time across 15+ providers with zero code changes.*
13
+ *Keep control of your AI. Detect prompt injection, jailbreaks, PII leakage, and adversarial attacks in real-time across 17+ providers with zero code changes.*
14
14
 
15
15
  [Quick Start](#quick-start) · [Documentation](https://www.lockllm.com/docs) · [Examples](#examples) · [Benchmarks](https://www.lockllm.com) · [API Reference](#api-reference)
16
16
 
@@ -26,9 +26,9 @@ LockLLM is a state-of-the-art AI security ecosystem that detects prompt injectio
26
26
 
27
27
  - **Real-Time Security Scanning** - Analyze every LLM request before execution with minimal latency (<250ms)
28
28
  - **Advanced ML Detection** - Models trained on real-world attack patterns for prompt injection and jailbreaks
29
- - **15+ Provider Support** - Universal coverage across OpenAI, Anthropic, Azure, Bedrock, Gemini, and more
29
+ - **17+ Provider Support** - Universal coverage across OpenAI, Anthropic, Azure, Bedrock, Gemini, and more
30
30
  - **Drop-in Integration** - Replace existing SDKs with zero code changes - just change one line
31
- - **Completely Free** - BYOK (Bring Your Own Key) model with unlimited usage and no rate limits
31
+ - **Free Unlimited Scanning** - BYOK (Bring Your Own Key) model with free unlimited scanning
32
32
  - **Privacy by Default** - Your data is never stored, only scanned in-memory and discarded
33
33
 
34
34
  ## Why LockLLM
@@ -73,27 +73,54 @@ LockLLM provides production-ready AI security that integrates seamlessly into yo
73
73
  | **Evasion & Obfuscation Detection** | Catch sophisticated obfuscation including Unicode abuse, zero-width characters, and encoding-based attacks |
74
74
  | **Multi-Layer Context Analysis** | Analyze prompts across multiple context windows to detect attacks spanning conversation turns |
75
75
  | **Token-Level Threat Scoring** | Granular threat assessment identifying which specific parts of input contain malicious patterns |
76
- | **15+ Provider Support** | OpenAI, Anthropic, Gemini, Azure, Bedrock, Groq, DeepSeek, and more |
76
+ | **17+ Provider Support** | OpenAI, Anthropic, Gemini, Azure, Bedrock, Groq, DeepSeek, and more |
77
77
  | **Drop-in Integration** | Replace `new OpenAI()` with `createOpenAI()` - no other changes needed |
78
78
  | **TypeScript Native** | Full type safety with comprehensive type definitions and IDE support |
79
79
  | **Streaming Compatible** | Works seamlessly with streaming responses from any provider |
80
80
  | **Configurable Sensitivity** | Adjust detection thresholds (low/medium/high) per use case |
81
- | **Custom Endpoints** | Support for self-hosted models, Azure resources, and private clouds |
81
+ | **Custom Endpoints** | Configure custom URLs for any provider (self-hosted, Azure, private clouds) |
82
+ | **Custom Content Policies** | Define your own content rules in the dashboard and enforce them automatically across all providers |
83
+ | **AI Abuse Detection** | Detect bot-generated content, repetition attacks, and resource exhaustion from your end-users |
84
+ | **Intelligent Routing** | Automatically select the optimal model for each request based on task type and complexity to save costs |
85
+ | **PII Detection & Redaction** | Detect and automatically redact emails, phone numbers, SSNs, credit cards, and other personal information before they reach AI providers |
86
+ | **Response Caching** | Cache identical LLM responses to reduce costs and latency on repeated queries |
82
87
  | **Enterprise Privacy** | Provider keys encrypted at rest, prompts never stored |
83
88
  | **Production Ready** | Battle-tested with automatic retries, timeouts, and error handling |
84
89
 
85
90
  ## Installation
86
91
 
92
+ Choose your preferred package manager:
87
93
  ```bash
88
- # Install the SDK
94
+ # npm
89
95
  npm install @lockllm/sdk
90
96
 
91
- # For wrapper functions, install relevant peer dependencies
92
- npm install openai # For OpenAI, Groq, DeepSeek, Mistral, etc.
93
- npm install @anthropic-ai/sdk # For Anthropic Claude
94
- npm install cohere-ai # For Cohere (optional)
97
+ # pnpm (faster, saves disk space)
98
+ pnpm add @lockllm/sdk
99
+
100
+ # yarn
101
+ yarn add @lockllm/sdk
102
+ ```
103
+
104
+ ### Peer Dependencies
105
+
106
+ For wrapper functions, install the relevant provider SDKs:
107
+
108
+ ```bash
109
+ # npm
110
+ npm install openai @anthropic-ai/sdk cohere-ai
111
+
112
+ # pnpm
113
+ pnpm add openai @anthropic-ai/sdk cohere-ai
114
+
115
+ # yarn
116
+ yarn add openai @anthropic-ai/sdk cohere-ai
95
117
  ```
96
118
 
119
+ **Provider breakdown:**
120
+ - `openai` - For OpenAI, Groq, DeepSeek, Mistral, etc.
121
+ - `@anthropic-ai/sdk` - For Anthropic Claude
122
+ - `cohere-ai` - For Cohere (optional)
123
+
97
124
  **Note:** Peer dependencies are optional and only required if you use the wrapper functions for those providers.
98
125
 
99
126
  ## Quick Start
@@ -222,7 +249,7 @@ Compare detection accuracy and performance metrics at [lockllm.com/benchmarks](h
222
249
  | **Real-Time Protection** | ✅ <250ms latency | ✅ Built-in | ✅ Yes | ❌ Too slow |
223
250
  | **Setup Time** | 5 minutes | Included | Days to weeks | N/A |
224
251
  | **Maintenance** | None | None | Constant updates | Constant |
225
- | **Multi-Provider Support** | ✅ 15+ providers | Single provider | Custom per provider | N/A |
252
+ | **Multi-Provider Support** | ✅ 17+ providers | Single provider | Custom per provider | N/A |
226
253
  | **False Positives** | Low (~2-5%) | N/A | High (15-30%) | N/A |
227
254
  | **Cost** | Free (BYOK) | Free | Dev time + infrastructure | $$$ |
228
255
  | **Attack Coverage** | Comprehensive | Content policy only | Pattern-based only | Manual |
@@ -378,6 +405,10 @@ const highResult = await lockllm.scan({
378
405
  import {
379
406
  LockLLMError,
380
407
  PromptInjectionError,
408
+ PolicyViolationError,
409
+ AbuseDetectedError,
410
+ PIIDetectedError,
411
+ InsufficientCreditsError,
381
412
  AuthenticationError,
382
413
  RateLimitError,
383
414
  UpstreamError
@@ -395,13 +426,24 @@ try {
395
426
  console.log("Injection confidence:", error.scanResult.injection);
396
427
  console.log("Request ID:", error.requestId);
397
428
 
398
- // Log to security monitoring system
399
- await logSecurityIncident({
400
- type: 'prompt_injection',
401
- confidence: error.scanResult.injection,
402
- requestId: error.requestId,
403
- timestamp: new Date()
404
- });
429
+ } else if (error instanceof PolicyViolationError) {
430
+ // Custom policy violation detected
431
+ console.log("Policy violation:", error.violated_policies);
432
+
433
+ } else if (error instanceof AbuseDetectedError) {
434
+ // AI abuse detected (bot content, repetition, etc.)
435
+ console.log("Abuse detected:", error.abuse_details.abuse_types);
436
+ console.log("Confidence:", error.abuse_details.confidence);
437
+
438
+ } else if (error instanceof PIIDetectedError) {
439
+ // Personal information detected (when piiAction is 'block')
440
+ console.log("PII found:", error.pii_details.entity_types);
441
+ console.log("Entity count:", error.pii_details.entity_count);
442
+
443
+ } else if (error instanceof InsufficientCreditsError) {
444
+ // Not enough credits
445
+ console.log("Balance:", error.current_balance);
446
+ console.log("Cost:", error.estimated_cost);
405
447
 
406
448
  } else if (error instanceof AuthenticationError) {
407
449
  console.log("Invalid LockLLM API key");
@@ -422,7 +464,7 @@ try {
422
464
 
423
465
  ## Supported Providers
424
466
 
425
- LockLLM supports 17 AI providers with three flexible integration methods:
467
+ LockLLM supports 17+ AI providers with three flexible integration methods:
426
468
 
427
469
  ### Provider List
428
470
 
@@ -449,13 +491,16 @@ LockLLM supports 17 AI providers with three flexible integration methods:
449
491
  ### Custom Endpoints
450
492
 
451
493
  All providers support custom endpoint URLs for:
452
- - Self-hosted LLM deployments
453
- - Alternative API gateways
494
+ - Self-hosted LLM deployments (OpenAI-compatible APIs)
495
+ - Alternative API gateways and reverse proxies
454
496
  - Custom Azure OpenAI resources
455
- - Private cloud deployments
497
+ - Private cloud or air-gapped deployments
456
498
  - Development and staging environments
457
499
 
458
- Configure custom endpoints in the [LockLLM dashboard](https://www.lockllm.com/dashboard) when adding provider API keys.
500
+ **How it works:**
501
+ Configure custom endpoints in the [LockLLM dashboard](https://www.lockllm.com/dashboard) when adding any provider API key. The SDK wrappers automatically use your custom endpoint instead of the default.
502
+
503
+ **Example:** Use the OpenAI wrapper with your self-hosted Llama model by configuring a custom endpoint URL.
459
504
 
460
505
  ## How It Works
461
506
 
@@ -476,7 +521,7 @@ LockLLM uses a secure BYOK (Bring Your Own Key) model - you maintain control of
476
521
 
477
522
  - Use this single key in your SDK configuration
478
523
  - Authenticates requests to the LockLLM security gateway
479
- - Works across all 15+ providers with one key
524
+ - Works across all 17+ providers with one key
480
525
  - **This is the only key that goes in your code**
481
526
 
482
527
  ### Request Flow
@@ -510,7 +555,7 @@ LockLLM Security Gateway
510
555
  3. **Error Response** - Detailed error returned with threat classification and confidence scores
511
556
  4. **Logging** - Incident automatically logged in [dashboard](https://www.lockllm.com/dashboard) for review and monitoring
512
557
 
513
- ### Security & Privacy
558
+ ### Privacy & Security
514
559
 
515
560
  LockLLM is built with privacy and security as core principles. Your data stays yours.
516
561
 
@@ -562,7 +607,7 @@ interface LockLLMConfig {
562
607
  Scan a prompt for security threats before sending to an LLM.
563
608
 
564
609
  ```typescript
565
- await lockllm.scan(request: ScanRequest): Promise<ScanResponse>
610
+ await lockllm.scan(request: ScanRequest, options?: ScanOptions): Promise<ScanResponse>
566
611
  ```
567
612
 
568
613
  **Request Parameters:**
@@ -571,6 +616,15 @@ await lockllm.scan(request: ScanRequest): Promise<ScanResponse>
571
616
  interface ScanRequest {
572
617
  input: string; // Required: Text to scan
573
618
  sensitivity?: 'low' | 'medium' | 'high'; // Optional: Detection level (default: 'medium')
619
+ mode?: 'normal' | 'policy_only' | 'combined'; // Optional: Scan mode (default: 'combined')
620
+ chunk?: boolean; // Optional: Force chunking for long texts
621
+ }
622
+
623
+ interface ScanOptions {
624
+ scanAction?: 'block' | 'allow_with_warning'; // Core injection behavior
625
+ policyAction?: 'block' | 'allow_with_warning'; // Custom policy behavior
626
+ abuseAction?: 'block' | 'allow_with_warning'; // Abuse detection (opt-in)
627
+ piiAction?: 'strip' | 'block' | 'allow_with_warning'; // PII detection (opt-in)
574
628
  }
575
629
  ```
576
630
 
@@ -580,8 +634,9 @@ interface ScanRequest {
580
634
  interface ScanResponse {
581
635
  safe: boolean; // Whether input is safe (true) or malicious (false)
582
636
  label: 0 | 1; // Classification: 0=safe, 1=malicious
583
- confidence: number; // Confidence score (0-1)
584
- injection: number; // Injection risk score (0-1, higher=more risky)
637
+ confidence?: number; // Core injection confidence score (0-1)
638
+ injection?: number; // Injection risk score (0-1, higher=more risky)
639
+ policy_confidence?: number; // Policy check confidence (in combined/policy_only mode)
585
640
  sensitivity: Sensitivity; // Sensitivity level used for scan
586
641
  request_id: string; // Unique request identifier
587
642
 
@@ -590,11 +645,29 @@ interface ScanResponse {
590
645
  input_chars: number; // Number of characters processed
591
646
  };
592
647
 
593
- debug?: { // Only available with Pro plan
648
+ debug?: {
594
649
  duration_ms: number; // Total processing time
595
650
  inference_ms: number; // ML inference time
596
651
  mode: 'single' | 'chunked';
597
652
  };
653
+
654
+ // Present when using policy_only or combined mode with allow_with_warning
655
+ policy_warnings?: PolicyViolation[];
656
+ // Present when core injection detected with allow_with_warning
657
+ scan_warning?: ScanWarning;
658
+ // Present when abuse detection is enabled and abuse found
659
+ abuse_warnings?: AbuseWarning;
660
+ // Present when intelligent routing is enabled
661
+ routing?: { task_type: string; complexity: number; selected_model?: string; };
662
+ // Present when PII detection is enabled
663
+ pii_result?: PIIResult;
664
+ }
665
+
666
+ interface PIIResult {
667
+ detected: boolean; // Whether PII was detected
668
+ entity_types: string[]; // Types of PII entities found (e.g., 'email', 'phone_number')
669
+ entity_count: number; // Number of PII entities found
670
+ redacted_input?: string; // Redacted text (only present when piiAction is 'strip')
598
671
  }
599
672
  ```
600
673
 
@@ -615,6 +688,17 @@ createGroq(config: GenericClientConfig): OpenAI
615
688
  interface GenericClientConfig {
616
689
  apiKey: string; // Required: Your LockLLM API key
617
690
  baseURL?: string; // Optional: Override proxy URL
691
+ proxyOptions?: { // Optional: Security and routing configuration
692
+ scanMode?: 'normal' | 'policy_only' | 'combined';
693
+ scanAction?: 'block' | 'allow_with_warning';
694
+ policyAction?: 'block' | 'allow_with_warning';
695
+ abuseAction?: 'block' | 'allow_with_warning' | null;
696
+ piiAction?: 'strip' | 'block' | 'allow_with_warning' | null;
697
+ routeAction?: 'disabled' | 'auto' | 'custom';
698
+ sensitivity?: 'low' | 'medium' | 'high';
699
+ cacheResponse?: boolean;
700
+ cacheTTL?: number;
701
+ };
618
702
  [key: string]: any; // Optional: Provider-specific options
619
703
  }
620
704
  ```
@@ -631,6 +715,16 @@ const url = getProxyURL('openai');
631
715
  // Returns: 'https://api.lockllm.com/v1/proxy/openai'
632
716
  ```
633
717
 
718
+ **Get universal proxy URL (non-BYOK, 200+ models):**
719
+
720
+ ```typescript
721
+ function getUniversalProxyURL(): string
722
+
723
+ // Example
724
+ const url = getUniversalProxyURL();
725
+ // Returns: 'https://api.lockllm.com/v1/proxy/chat/completions'
726
+ ```
727
+
634
728
  **Get all proxy URLs:**
635
729
 
636
730
  ```typescript
@@ -642,6 +736,36 @@ console.log(urls.openai); // 'https://api.lockllm.com/v1/proxy/openai'
642
736
  console.log(urls.anthropic); // 'https://api.lockllm.com/v1/proxy/anthropic'
643
737
  ```
644
738
 
739
+ **Build LockLLM proxy headers:**
740
+
741
+ ```typescript
742
+ import { buildLockLLMHeaders } from '@lockllm/sdk';
743
+
744
+ const headers = buildLockLLMHeaders({
745
+ scanMode: 'combined',
746
+ scanAction: 'block',
747
+ policyAction: 'allow_with_warning',
748
+ abuseAction: 'block',
749
+ piiAction: 'strip',
750
+ routeAction: 'auto'
751
+ });
752
+ // Returns: { 'x-lockllm-scan-mode': 'combined', 'x-lockllm-pii-action': 'strip', ... }
753
+ ```
754
+
755
+ **Parse proxy response metadata:**
756
+
757
+ ```typescript
758
+ import { parseProxyMetadata } from '@lockllm/sdk';
759
+
760
+ // Parse response headers from any proxy request
761
+ const metadata = parseProxyMetadata(response.headers);
762
+ console.log(metadata.safe); // true/false
763
+ console.log(metadata.scan_mode); // 'combined'
764
+ console.log(metadata.cache_status); // 'HIT' or 'MISS'
765
+ console.log(metadata.routing); // { task_type, complexity, selected_model, ... }
766
+ console.log(metadata.pii_detected); // { detected, entity_types, entity_count, action }
767
+ ```
768
+
645
769
  ## Error Types
646
770
 
647
771
  LockLLM provides typed errors for comprehensive error handling:
@@ -653,6 +777,10 @@ LockLLMError (base)
653
777
  ├── AuthenticationError (401)
654
778
  ├── RateLimitError (429)
655
779
  ├── PromptInjectionError (400)
780
+ ├── PolicyViolationError (403)
781
+ ├── AbuseDetectedError (400)
782
+ ├── PIIDetectedError (403)
783
+ ├── InsufficientCreditsError (402)
656
784
  ├── UpstreamError (502)
657
785
  ├── ConfigurationError (400)
658
786
  └── NetworkError (0)
@@ -676,6 +804,39 @@ class RateLimitError extends LockLLMError {
676
804
  retryAfter?: number; // Milliseconds until retry allowed
677
805
  }
678
806
 
807
+ class PolicyViolationError extends LockLLMError {
808
+ violated_policies: Array<{
809
+ policy_name: string;
810
+ violated_categories: Array<{ name: string }>;
811
+ violation_details?: string;
812
+ }>;
813
+ }
814
+
815
+ class AbuseDetectedError extends LockLLMError {
816
+ abuse_details: {
817
+ confidence: number;
818
+ abuse_types: string[];
819
+ indicators: {
820
+ bot_score: number;
821
+ repetition_score: number;
822
+ resource_score: number;
823
+ pattern_score: number;
824
+ };
825
+ };
826
+ }
827
+
828
+ class PIIDetectedError extends LockLLMError {
829
+ pii_details: {
830
+ entity_types: string[]; // PII types found (e.g., 'email', 'phone_number')
831
+ entity_count: number; // Number of PII entities detected
832
+ };
833
+ }
834
+
835
+ class InsufficientCreditsError extends LockLLMError {
836
+ current_balance: number; // Current credit balance
837
+ estimated_cost: number; // Estimated cost of the request
838
+ }
839
+
679
840
  class UpstreamError extends LockLLMError {
680
841
  provider?: string; // Provider name
681
842
  upstreamStatus?: number; // Provider's status code
@@ -707,13 +868,22 @@ LockLLM adds minimal latency while providing comprehensive security protection.
707
868
 
708
869
  ## Rate Limits
709
870
 
710
- LockLLM provides generous rate limits for all users, with the Free tier supporting most production use cases.
871
+ LockLLM uses a 10-tier progressive system based on monthly usage. Higher tiers unlock faster rate limits and free monthly credits.
872
+
873
+ | Tier | Max RPM | Monthly Spending Requirement |
874
+ |------|---------|----------------------------|
875
+ | **Tier 1** (Free) | 30 RPM | $0 |
876
+ | **Tier 2** | 50 RPM | $10/month |
877
+ | **Tier 3** | 100 RPM | $50/month |
878
+ | **Tier 4** | 200 RPM | $100/month |
879
+ | **Tier 5** | 500 RPM | $250/month |
880
+ | **Tier 6** | 1,000 RPM | $500/month |
881
+ | **Tier 7** | 2,000 RPM | $1,000/month |
882
+ | **Tier 8** | 5,000 RPM | $3,000/month |
883
+ | **Tier 9** | 10,000 RPM | $5,000/month |
884
+ | **Tier 10** | 20,000 RPM | $10,000/month |
711
885
 
712
- | Tier | Requests per Minute | Best For |
713
- |------|---------------------|----------|
714
- | **Free** | 1,000 RPM | Most applications, startups, side projects |
715
- | **Pro** | 10,000 RPM | High-traffic applications, enterprise pilots |
716
- | **Enterprise** | Custom | Large-scale deployments, custom SLAs |
886
+ See [pricing](https://www.lockllm.com/pricing) for full tier details and free monthly credits.
717
887
 
718
888
  **Smart Rate Limit Handling:**
719
889
 
@@ -751,6 +921,68 @@ const lockllm = new LockLLM({
751
921
  });
752
922
  ```
753
923
 
924
+ ### Advanced Scan Options
925
+
926
+ Control scan behavior with mode, sensitivity, and action headers:
927
+
928
+ ```typescript
929
+ // Scan API with advanced options
930
+ const result = await lockllm.scan(
931
+ {
932
+ input: userPrompt,
933
+ sensitivity: 'high', // 'low' | 'medium' | 'high'
934
+ mode: 'combined', // 'normal' | 'policy_only' | 'combined'
935
+ chunk: true // Force chunking for long texts
936
+ },
937
+ {
938
+ scanAction: 'block', // Block core injection attacks
939
+ policyAction: 'allow_with_warning', // Allow but warn on policy violations
940
+ abuseAction: 'block', // Enable abuse detection (opt-in)
941
+ piiAction: 'strip' // Redact PII from input (opt-in)
942
+ }
943
+ );
944
+
945
+ // Proxy mode with advanced options
946
+ const openai = createOpenAI({
947
+ apiKey: process.env.LOCKLLM_API_KEY,
948
+ proxyOptions: {
949
+ scanMode: 'combined', // Check both core + policies
950
+ scanAction: 'block', // Block injection attacks
951
+ policyAction: 'block', // Block policy violations
952
+ abuseAction: 'allow_with_warning', // Detect abuse, don't block
953
+ piiAction: 'strip', // Automatically redact PII
954
+ routeAction: 'auto' // Enable intelligent routing
955
+ }
956
+ });
957
+ ```
958
+
959
+ **Scan Modes:**
960
+ - `normal` - Core security threats only (injection, jailbreaks, etc.)
961
+ - `policy_only` - Custom policies only (skip core security)
962
+ - `combined` (default) - Both core security AND custom policies
963
+
964
+ **Sensitivity Levels:**
965
+ - `low` - Fewer false positives, may miss sophisticated attacks
966
+ - `medium` (default) - Balanced approach, recommended
967
+ - `high` - Maximum protection, may have more false positives
968
+
969
+ **Action Headers:**
970
+ - `scanAction` - Controls core injection detection: `'block'` | `'allow_with_warning'`
971
+ - `policyAction` - Controls custom policy violations: `'block'` | `'allow_with_warning'`
972
+ - `abuseAction` - Controls abuse detection (opt-in): `'block'` | `'allow_with_warning'` | `null`
973
+ - `piiAction` - Controls PII detection (opt-in): `'strip'` | `'block'` | `'allow_with_warning'` | `null`
974
+ - `routeAction` - Controls intelligent routing: `'disabled'` | `'auto'` | `'custom'`
975
+
976
+ **Default Behavior (no headers):**
977
+ - Scan Mode: `combined` (check both core + policies)
978
+ - Scan Action: `allow_with_warning` (detect but don't block)
979
+ - Policy Action: `allow_with_warning` (detect but don't block)
980
+ - Abuse Action: `null` (disabled, opt-in only)
981
+ - PII Action: `null` (disabled, opt-in only)
982
+ - Route Action: `disabled` (no routing)
983
+
984
+ See [examples/advanced-options.ts](examples/advanced-options.ts) for complete examples.
985
+
754
986
  ## Best Practices
755
987
 
756
988
  ### Security
@@ -841,17 +1073,17 @@ For non-JavaScript environments, use the REST API directly:
841
1073
 
842
1074
  **Scan Endpoint:**
843
1075
  ```bash
844
- curl -X POST https://api.lockllm.com/scan \
845
- -H "x-api-key: YOUR_LOCKLLM_API_KEY" \
1076
+ curl -X POST https://api.lockllm.com/v1/scan \
1077
+ -H "Authorization: Bearer YOUR_LOCKLLM_API_KEY" \
846
1078
  -H "Content-Type: application/json" \
847
- -d '{"prompt": "Your text to scan", "sensitivity": "medium"}'
1079
+ -d '{"input": "Your text to scan", "sensitivity": "medium"}'
848
1080
  ```
849
1081
 
850
1082
  **Proxy Endpoints:**
851
1083
  ```bash
852
1084
  # OpenAI-compatible proxy
853
1085
  curl -X POST https://api.lockllm.com/v1/proxy/openai/chat/completions \
854
- -H "x-api-key: YOUR_LOCKLLM_API_KEY" \
1086
+ -H "Authorization: Bearer YOUR_LOCKLLM_API_KEY" \
855
1087
  -H "Content-Type: application/json" \
856
1088
  -d '{"model": "gpt-4", "messages": [{"role": "user", "content": "Hello"}]}'
857
1089
  ```
@@ -876,7 +1108,7 @@ import {
876
1108
 
877
1109
  // Type inference works automatically
878
1110
  const config: LockLLMConfig = {
879
- apiKey: 'llm_...',
1111
+ apiKey: '...',
880
1112
  timeout: 30000
881
1113
  };
882
1114
 
package/dist/client.d.ts CHANGED
@@ -30,7 +30,7 @@ export declare class LockLLM {
30
30
  * });
31
31
  * ```
32
32
  */
33
- get scan(): (request: import(".").ScanRequest, options?: import("./types/common").RequestOptions) => Promise<import(".").ScanResponse>;
33
+ get scan(): (request: import(".").ScanRequest, options?: import(".").ScanOptions) => Promise<import(".").ScanResponse>;
34
34
  /**
35
35
  * Get the current configuration
36
36
  */
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAMpD,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IACjD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAExC;;;;;;;;;;;OAWG;gBACS,MAAM,EAAE,aAAa;IA4BjC;;;;;;;;;;OAUG;IACH,IAAI,IAAI,+HAEP;IAED;;OAEG;IACH,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;CAG/C"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAMpD,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IACjD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAExC;;;;;;;;;;;OAWG;gBACS,MAAM,EAAE,aAAa;IA4BjC;;;;;;;;;;OAUG;IACH,IAAI,IAAI,+GAEP;IAED;;OAEG;IACH,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;CAG/C"}
package/dist/errors.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Custom error classes for LockLLM SDK
3
3
  */
4
- import type { ScanResult, LockLLMErrorData, PromptInjectionErrorData } from './types/errors';
4
+ import type { ScanResult, LockLLMErrorData, PromptInjectionErrorData, PolicyViolationErrorData, AbuseDetectedErrorData, InsufficientCreditsErrorData, PIIDetectedErrorData } from './types/errors';
5
5
  /**
6
6
  * Base error class for all LockLLM errors
7
7
  */
@@ -46,6 +46,61 @@ export declare class UpstreamError extends LockLLMError {
46
46
  export declare class ConfigurationError extends LockLLMError {
47
47
  constructor(message: string);
48
48
  }
49
+ /**
50
+ * Error thrown when custom policy violations are detected
51
+ */
52
+ export declare class PolicyViolationError extends LockLLMError {
53
+ readonly violated_policies: Array<{
54
+ policy_name: string;
55
+ violated_categories: Array<{
56
+ name: string;
57
+ }>;
58
+ violation_details?: string;
59
+ }>;
60
+ constructor(data: PolicyViolationErrorData);
61
+ }
62
+ /**
63
+ * Error thrown when AI abuse is detected
64
+ */
65
+ export declare class AbuseDetectedError extends LockLLMError {
66
+ readonly abuse_details: {
67
+ confidence: number;
68
+ abuse_types: string[];
69
+ indicators: {
70
+ bot_score: number;
71
+ repetition_score: number;
72
+ resource_score: number;
73
+ pattern_score: number;
74
+ };
75
+ recommendation?: string;
76
+ details?: {
77
+ recommendation?: string;
78
+ bot_indicators?: string[];
79
+ repetition_indicators?: string[];
80
+ resource_indicators?: string[];
81
+ pattern_indicators?: string[];
82
+ };
83
+ };
84
+ constructor(data: AbuseDetectedErrorData);
85
+ }
86
+ /**
87
+ * Error thrown when PII (personal information) is detected and action is block
88
+ */
89
+ export declare class PIIDetectedError extends LockLLMError {
90
+ readonly pii_details: {
91
+ entity_types: string[];
92
+ entity_count: number;
93
+ };
94
+ constructor(data: PIIDetectedErrorData);
95
+ }
96
+ /**
97
+ * Error thrown when user has insufficient credits
98
+ */
99
+ export declare class InsufficientCreditsError extends LockLLMError {
100
+ readonly current_balance: number;
101
+ readonly estimated_cost: number;
102
+ constructor(data: InsufficientCreditsErrorData);
103
+ }
49
104
  /**
50
105
  * Error thrown when network request fails
51
106
  */
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE7F;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAgB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChC,SAAgB,SAAS,CAAC,EAAE,MAAM,CAAC;gBAEvB,IAAI,EAAE,gBAAgB;CA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