Skip to content

Buddy-Henderson/sift-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@sift-core/node

SiftPrompt Node.js SDK: The ultra-lightweight prompt optimization matrix compiler. Strip syntactic noise, conversational fluff, and redundancy from your LLM prompts to save up to 40%+ on your token bills without sacrificing semantic accuracy.

NPM Version License: MIT


Features

  • Intelligent Compression: Automatically targets conversational filler, over-engineered phrasing, and corporate boilerplate.
  • Fail-Safe Circuit Breaker: Zero-dependency, defensive engineering. If your network or the gateway drops, the SDK automatically fails open under 50ms, returning your raw prompt so your server processes never crash.
  • Multi-Mode Support: Choose between balanced, aggressive, and exact optimization matrices.
  • Deterministic Local Guardrails: Instantly catches empty strings or dead whitespace locally without wasting API network credits.
  • Dual Distribution Bundle: Shipped with native support for both modern ES Modules (import) and legacy CommonJS (require) systems out of the box.

Installation

Install the official package from the npm registry:

npm install @siftprompt/node

Environment Configuration

Never hardcode your API credentials into your application files.

Instead, create a .env.local or .env file at the root of your project directory and declare your credentials securely:

SIFT_RAPIDAPI_KEY=your_secret_rapidapi_key_here

Ensure your .gitignore file contains .env* rules to prevent pushing production keys to public repositories.


Quick Start

Modern JavaScript / TypeScript (ES Modules)

Using an environment runner or a loading layer like dotenv to initialize variables securely.

JavaScript

import { SiftCompiler } from '@sift-core/node';
import dotenv from 'dotenv';

dotenv.config({ path: './.env.local' });

// Initialize the compiler dynamically from your environment
const sift = new SiftCompiler({
  apiKey: process.env.SIFT_RAPIDAPI_KEY
});

// A conversational prompt heavy with fluff
const verbosePrompt =
  "Hey there AI, I hope you are having an absolutely wonderful day today! " +
  "I am working on a small personal project and I was really wondering if you could " +
  "do me a huge favor. Can you please act as a world-class, expert senior copywriter " +
  "for me right now? Please look over the text very carefully. Thank you so much!";

// Execute the async compression pass
const result = await sift.minify(verbosePrompt, "aggressive");

console.log(
  `Optimization Rate: ${result.metrics.percentage_saved}% tokens saved`
);

console.log("--------------------------------------------------");

console.log(
  `Minified Output:\n"${result.optimized_text}"`
);

Legacy Node.js (CommonJS)

JavaScript

const { SiftCompiler } = require('@sift-core/node');

// Load environment variables via require('dotenv').config() if needed

const sift = new SiftCompiler({
  apiKey: process.env.SIFT_RAPIDAPI_KEY
});

// Use within an async function context...

Optimization Profiles

Profile Behavior Ideal Target
balanced Standard pruning Multi-turn conversational contexts
aggressive High-density stripping Verbose corporate boilerplate, pleasantries, and fluff
exact Literal matching Structured code blocks, JSON schemas, structural variables

Enterprise Resilience (Fail-Open)

This SDK is engineered defensively for mission-critical pipelines, backend APIs, and autonomous AI microservices.

It encapsulates network dispatches inside strict short-circuit timeouts.

If the underlying API layer undergoes throttling (429), structural validation denials (403), or total network blackouts (such as DNS failures), the wrapper catches the anomaly cleanly and returns your original uncompressed text sequence seamlessly with an explicit:

{
  "percentage_saved": 0
}

metric object.

Your runtime environment will never throw an unhandled exception or crash.

About

Official TypeScript/Node.js SDK for SiftPrompt. Programmatically interface with the SiftCompiler compression engine to minify text payloads, calculate token metrics, and route secure, high-performance compilation dispatches through the RapidAPI gateway.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors