API Reference
Complete reference for all three Brevit SDK implementations. All methods have equivalent signatures across JavaScript, Python, and .NET.
BrevitClient
The main client class. Accepts a BrevitConfig and optional custom optimizers. All optimization methods return a compressed string.
Constructor
new BrevitClient()→BrevitClientnew BrevitClient(config?: BrevitConfig, options?: { textOptimizer?, imageOptimizer? })Creates a new BrevitClient instance. All parameters are optional — no-arg constructor uses sensible defaults.
Parameters
config?BrevitConfigConfiguration object. Defaults to new BrevitConfig().options.textOptimizer?FunctionCustom text optimizer function. Overrides the built-in TextRank.options.imageOptimizer?FunctionCustom image optimizer function. Overrides the OCR stub.Core Methods
brevity()→Promise<string>brevity(data: any, intent?: string): Promise<string>Auto mode. Analyzes the data structure and selects the optimal compression strategy automatically. Recommended entry point for most use cases.
Parameters
dataanyJSON string, object, array, text string, or ArrayBuffer/Uint8Array.intent?stringOptional hint about the goal (e.g. 'summarize for customer support').optimize()→Promise<string>optimize(data: any, ratioOrIntent?: number | string, intent?: string): Promise<string>Explicit optimization. Routes by input type — JSON/objects go through the JSON pipeline, strings through TextRank. Supports optional ratio for text compression.
Parameters
dataanyJSON string, object, text string, or binary image data.ratioOrIntent?number | stringIf number (0–1): ratio for TextRank sentence selection. If string: intent hint.intent?stringIntent hint (use when also passing ratio as 2nd arg).compressText()→Promise<string>compressText(text: string): Promise<string>Explicit TextRank AUTO mode. With autoThresholdMultiplier=0 (default), all sentences pass — lossless compression. Uses graph-based sentence scoring to preserve information order.
Parameters
textstringAny plain-text string.optimizeText()→Promise<string>optimizeText(text: string, ratio: number): Promise<string>Explicit TextRank RATIO mode. Keeps only the top N% of sentences ranked by TextRank graph score. Deterministic — same input always produces same output.
Parameters
textstringAny plain-text string.rationumberFraction of sentences to keep (0.0–1.0). 0.5 = keep top 50%.registerStrategy()→voidregisterStrategy(name: string, analyzer: Function, optimizer: Function): voidRegister a custom optimization strategy. The analyzer scores how well the strategy fits the input (0–100), and the optimizer performs the transformation.
Parameters
namestringUnique strategy identifier.analyzer(data: any) => { score: number; reason: string }Returns a score 0–100 indicating fit quality.optimizer(data: any) => Promise<string>Performs the optimization, returns compressed string.BrevitConfig
Configuration options for the BrevitClient. All fields are optional with sensible defaults.
| Field | Type | Default | Description |
|---|---|---|---|
jsonMode | JsonOptimizationMode | Flatten | How to optimize JSON structures. |
textMode | TextOptimizationMode | Clean | How to handle long text strings. |
imageMode | ImageOptimizationMode | Ocr | Image optimization mode. |
enableAbbreviations | boolean | true | Auto-abbreviate repeated key prefixes. |
abbreviationThreshold | number | 2 | Min repeats before an alias is created. |
longTextThreshold | number | 500 | Chars before text optimization triggers. |
jsonPathsToKeep | string[] | [] | Paths to keep in Filter mode. |
Enums
JsonOptimizationMode.FlattenDot-notation flattening + tabular arrays. Default.
.ToYamlConvert to YAML format.
.FilterKeep only specified paths.
.NoneNo JSON optimization.
TextOptimizationMode.CleanClean whitespace and normalize. Default.
.SummarizeFastFast extractive summary.
.SummarizeHighQualityHigher quality summarization.
.NoneNo text optimization.
ImageOptimizationMode.OcrExtract text via OCR. Default.
.MetadataExtract image metadata only.
.NoneNo image optimization.
Language Equivalents
All methods have direct equivalents in Python and .NET with idiomatic naming conventions.
| JavaScript | Python | .NET / C# |
|---|---|---|
brevity(data) | brevity(data) | BrevityAsync(data) |
optimize(data) | optimize(data) | OptimizeAsync(data) |
compressText(text) | compress_text(text) | CompressTextAsync(text) |
optimizeText(text, ratio) | optimize_text(text, ratio) | OptimizeTextAsync(text, ratio) |
registerStrategy(name, fn, fn) | register_strategy(name, fn, fn) | RegisterStrategy(name, fn, fn) |
new BrevitConfig({ enableAbbreviations }) | BrevitConfig(enable_abbreviations=True) | new BrevitConfig { EnableAbbreviations = true } |