Skip to main content

Universal AI token & cost compressor — works with any API or local model

Project description

HighRize 🗜️

Universal AI token & cost compressor — works with any LLM API or locally hosted model.
Supports text, images, video, audio, and documents. Zero mandatory dependencies.

pip install highrize

Why

Every token costs money. Long prompts, high-res images, raw audio — they all bloat your bills.
highrize sits between your code and the AI API, compresses everything automatically, and tells you exactly how much you saved.


Quick start

from highrize import HighRize

tp = HighRize(model="gpt-4o", provider="openai")

result = tp.compress("Please note that I would like to ask you kindly to summarize " * 20)
print(result)
# CompressionResult(text: 740 → 160 tokens, 78.4% saved)

print(tp.report.summary())

Drop-in client wrapper (recommended)

No changes to your existing code — just wrap your client:

# OpenAI
from openai import OpenAI
from highrize import CompressedClient

client = CompressedClient(OpenAI(), model="gpt-4o")
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Your long prompt here..."}]
)
print(client.tp.report.summary())
# Anthropic
from anthropic import Anthropic
from highrize import CompressedClient

client = CompressedClient(Anthropic(), provider="anthropic", model="claude-3-5-sonnet")
response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[{"role": "user", "content": "..."}]
)
# Ollama (or any OpenAI-compatible local model)
from openai import OpenAI
from highrize import CompressedClient

ollama = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
client = CompressedClient(ollama, model="llama3.2")

Compress by modality

Text

from highrize.compressors import TextCompressor

tc = TextCompressor(
    remove_fillers=True,   # strip "please note that", "as an AI", etc.
    deduplicate=True,      # remove repeated sentences
    max_examples=3,        # keep at most 3 few-shot examples
)
result = tc.compress("Your prompt...")
print(result.compressed)
print(f"Saved {result.savings_pct}%")

Images (vision APIs)

from highrize.compressors import ImageCompressor

ic = ImageCompressor(
    max_size=(1024, 1024),  # resize to max dimensions
    quality=75,              # JPEG quality
    provider="openai",       # for token cost estimation
    low_detail=True,         # OpenAI low-detail mode (85 tokens flat)
)
result = ic.compress("photo.jpg")         # file path
result = ic.compress("data:image/...")    # base64 string
result = ic.compress(pil_image)           # PIL Image object
result = ic.compress(raw_bytes)           # bytes

print(result.compressed)  # base64 string ready for API

Video

from highrize.compressors import VideoCompressor

vc = VideoCompressor(
    max_frames=10,       # extract at most 10 frames
    frame_size=(768, 768),
    scene_change=True,   # pick frames where scene changes (smarter sampling)
)
result = vc.compress("video.mp4")
frames = result.compressed  # list of base64 image strings

Audio

from highrize.compressors import AudioCompressor

ac = AudioCompressor(
    backend="whisper_local",  # "whisper_local" | "whisper_api" | "faster_whisper"
    model_size="base",        # tiny / base / small / medium / large
    remove_silence=True,      # strip silent segments before transcription
    compress_transcript=True, # run TextCompressor on transcript
)
result = ac.compress("recording.mp3")
print(result.compressed)  # transcript text, ready to put in your prompt

Documents (PDF, HTML, DOCX)

from highrize.compressors import DocumentCompressor

dc = DocumentCompressor(
    token_budget=2000,           # max tokens to return
    query="What is the pricing?", # relevance ranking query (optional)
)
result = dc.compress("contract.pdf")
result = dc.compress("page.html")
result = dc.compress("report.docx")
print(result.compressed)  # most relevant chunks within budget

Multi-modal messages

tp = HighRize(model="gpt-4o")
messages = [
    {"role": "system", "content": "You are a helpful assistant. Please note that..."},
    {"role": "user", "content": [
        {"type": "text", "text": "What's in this image?"},
        {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,..."}}
    ]}
]

compressed, report = tp.compress_messages(messages)
print(report.summary())

Savings report

tp = HighRize(model="gpt-4o")

# ... make many compress() calls ...

print(tp.report.summary())
# HighRize session summary
#   Requests     : 42
#   Tokens       : 128,400 → 31,200
#   Saved        : 97,200 tokens (75.7%)
#   Cost saved   : $0.4860 USD

Install extras

pip install highrize                          # text only (zero deps)
pip install "highrize[image]"                 # + image compression (Pillow)
pip install "highrize[video]"                 # + video (OpenCV + Pillow)
pip install "highrize[audio]"                 # + audio (Whisper + pydub)
pip install "highrize[audio-fast]"            # + faster-whisper (CPU-fast)
pip install "highrize[document]"              # + PDF/HTML/DOCX
pip install "highrize[all]"                   # everything

Supported providers & models

Provider Client provider=
OpenAI openai.OpenAI "openai"
Anthropic anthropic.Anthropic "anthropic"
Google Gemini google.generativeai "gemini"
Ollama OpenAI compat "openai"
LM Studio OpenAI compat "openai"
Any OpenAI-compat openai.OpenAI(base_url=...) "openai"

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

highrize-0.1.0-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

Details for the file highrize-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: highrize-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for highrize-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ce7c3a0e442c244bbddfa60bf465710c26922e906d8cc09f05ab0dd5e9bd882
MD5 a46d08f7e5037f9d8ba6368008b20717
BLAKE2b-256 a5e0a567f13217859699e2e2758512712eed3b12442279e011856b290f996318

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page