Documentation
LightReach is an intelligent LLM cost optimization platform. Route requests to the cheapest model that meets your quality requirements, compress prompts to save tokens, keep long conversations within context windows via artifacts + compaction, and track every dollar.
Overview
LightReach helps you reduce LLM costs without sacrificing quality. The platform works by:
Intelligent Routing
Automatically routes requests to the cheapest model that meets your quality threshold, using HLE (Humanity's Last Exam) scores as the benchmark.
Prompt Compression
Lossless compression reduces token count while preserving semantic meaning. Typical savings of 20-40% on input tokens.
Cost Attribution
Tag requests by team, feature, environment, or integration. Get deterministic receipts and forecasts with zero guesswork.
Context Management
When conversations get too large for a model’s context window, LightReach externalizes oversized tool/file outputs intoartifacts (lossless) and can compact history (lossy) to keep the request within budget.
Quick Start
Installation
No SDK required. LightReach uses standard HTTP with your existing tools.
1. Create an account
Sign up at compress.lightreach.io/signup to get started with the Free tier.
2. Generate an API key
Navigate to Dashboard → API Keys and create a new key. Your key will look like:
lr_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx3. Run through Compress Cloud
Your workspace can run approved models through Compress Cloud without setting up a model-provider account. Token usage and cost are recorded for every request. Provider keys are an optional advanced setting.
First Request
Make a request to the /v2/complete endpoint. Compress Cloud selects an approved available model that meets your quality requirements and records the token usage.
import requests
response = requests.post(
"https://compress.lightreach.io/api/v2/complete",
headers={
"Authorization": "Bearer lr_your_api_key_here",
"Content-Type": "application/json"
},
json={
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain quantum computing briefly."}
],
"desired_hle": 25, # Quality threshold (current SOTA is ~40%)
"compress": True, # Enable prompt compression
"tags": {"team": "engineering", "environment": "production", "project": "onboarding"}
}
)
data = response.json()
print("Response:", data["choices"][0]["message"]["content"])
print("Model used:", data.get("model_used"))
print("Provider used:", data.get("provider_used"))
print("Estimated cost: quot; + str(round(float(data.get("cost_estimate") or 0.0), 6)))Cursor
A drop-in OpenAI base URL
Cursor speaks OpenAI. LightReach exposes a strict OpenAI-compatible API (including streaming SSE), so you can connect Cursor by setting a Base URL + API key - no extension, no SDK, no workflow changes.
lr_…) - not an OpenAI/Anthropic/Google provider key.https://api.compress.lightreach.io/v1/cursorGET /models and POST /chat/completions under that base.integration=cursor, so spend splits cleanly between Cursor and API/SDK.tool_calls in OpenAI shape. Cursor executes tools locally in the IDE - we do not run Cursor tools server-side.fetch_artifact).Connect Cursor
LightReach exposes a strict OpenAI-compatible API so Cursor can use it as a drop-in base URL. Cursor traffic is automatically attributed as integration=cursor.
1. Generate a LightReach API key
In the dashboard, create an API key. You’ll paste it into Cursor as your “OpenAI API key”.
2. Set Cursor base URL
In Cursor settings (Models → OpenAI-compatible), set the Base URL to:
https://api.compress.lightreach.io/v1/cursor3. Choose the model
Cursor will discover available models via GET /models. Use model id:
lightreachIf you see “model not found”, re-check this exact id and ensure your Base URL ends with /v1/cursor.
4. Verify it’s working
Open a new chat in Cursor and ask a simple question. In the LightReach dashboard, you should see the request attributed with integration=cursor within a few seconds.
Compress Cloud is ready after you create a LightReach API key. Provider keys are optional for a specific provider account or billing arrangement.
Quality policy
Cursor does not pick quality. Admins set a fixed HLE ceiling for Cursor traffic in Dashboard → Settings → Tags → System tags → click the Cursor card. This configures the integration=cursor policy and lets you control cost without asking developers to tune per-user model settings.
desired_hle. LightReach applies your workspace's integration policy for Cursor and routes to the best available Compress Cloud model that satisfies it.Troubleshooting
lr_…) and not a provider key./v1/cursor. Requests should appear within ~10 seconds.https://api.compress.lightreach.io/v1/cursor (or your self-hosted origin) and the model id is lightreach.OPENAI_COMPAT_CURSOR_BUFFERED_STREAM=1.Claude Code
An Anthropic-compatible endpoint
Claude Code speaks the Anthropic Messages API. LightReach exposes a fully compatible endpoint (including streaming SSE and tool calling), so you can route Claude Code through LightReach with two environment variables - no wrapper, no proxy, no workflow changes.
ANTHROPIC_AUTH_TOKEN should be a LightReach key (lr_…) - not an Anthropic API key.export ANTHROPIC_BASE_URL=https://api.compress.lightreach.io/v1/claude
export ANTHROPIC_AUTH_TOKEN=lr_your_key_hereGET /v1/models and POST /v1/messages under that base.integration=claude, so spend splits cleanly between Claude Code, Cursor, and API/SDK.Connect Claude Code
LightReach exposes an Anthropic-compatible Messages API so Claude Code can use it as a drop-in base URL. Claude Code traffic is automatically attributed as integration=claude.
1. Generate a LightReach API key
In the dashboard, create an API key. You'll use it as your ANTHROPIC_AUTH_TOKEN.
2. Set environment variables
Before running claude, export these in your terminal:
export ANTHROPIC_BASE_URL=https://api.compress.lightreach.io/v1/claude
export ANTHROPIC_AUTH_TOKEN=lr_your_key_hereYou can add these to your shell profile (~/.zshrc or ~/.bashrc) to make them permanent.
3. Launch Claude Code
Run claude as usual. When prompted to select a model, choose lightreach - or use:
claude --model lightreach4. Verify it's working
Ask Claude Code a simple question. In the LightReach dashboard, you should see the request attributed with integration=claude within a few seconds.
Compress Cloud is ready after you create a LightReach API key. Provider keys are optional for a specific provider account or billing arrangement.
Quality policy
Claude Code does not pick quality. Admins set a fixed HLE ceiling for Claude Code traffic in Dashboard → Settings → Tags → System tags → click the Claude Code card. This configures the integration=claude policy and lets you control cost without asking developers to change their workflow.
desired_hle. LightReach applies your workspace's integration policy for Claude Code and routes to the best available Compress Cloud model that satisfies it.Troubleshooting
ANTHROPIC_AUTH_TOKEN is a LightReach key (lr_…) and not an Anthropic API key.claude --model lightreach or select lightreach from the model picker. Ensure ANTHROPIC_BASE_URL ends with /v1/claude.claude. Run echo $ANTHROPIC_BASE_URL to confirm.CLAUDE_CODE_SUBAGENT_MODEL=lightreach and CLAUDE_CODE_EDIT_MODEL=lightreach.API Reference
Base URL: https://compress.lightreach.io/api
Authentication
Authenticate with a LightReach API key (lr_…). Most clients use an Authorization Bearer header. We also accept X-API-Key for server-to-server usage.
Authorization: Bearer lr_your_api_key_here
X-API-Key: lr_your_api_key_hereOpenAI-compatible API
Use these endpoints when you want strict OpenAI client compatibility (Cursor, OpenAI SDKs, or any tool that speaks/v1/chat/completions).
This is the right choice for IDE products (Cursor, Claude Code, Windsurf) because they generally integrate by setting an OpenAI-style Base URL and letting the IDE run tools locally on the developer machine.
https://api.compress.lightreach.io/v1/cursorGET /models, POST /chat/completionshttps://api.compress.lightreach.io/v1 (no forced integration tag)GET /models, POST /chat/completionsExample
curl -sS https://api.compress.lightreach.io/v1/cursor/chat/completions \
-H "Authorization: Bearer lr_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"model": "lightreach",
"messages": [{"role":"user","content":"Write a concise commit message for a refactor."}],
"stream": true
}'/v1) runs with prompt compression disabled and does not request compressed output. The Cursor surface (/v1/cursor) enables input compression and applies your workspace’s compaction defaults when needed (without message externalization into artifacts). If you want compression stats + token savings receipts, use POST /api/v2/complete./v2/complete
Send a chat completion request with automatic model routing, optional compression, and full cost tracking.
Use this endpoint from your codebase (HTTP / Python / Node) when you want OpenAI-style response fields plus LightReach-native metadata (compression stats, routing transparency, and cost receipts). For IDE products like Cursor/Claude Code/Windsurf, use the OpenAI-compatible endpoints instead.
Request Body
Array of message objects with role ("system", "user", "assistant") and content (string).
Desired HLE floor (0 to 100) for this request (minimum acceptable quality). Lower values allow cheaper models; higher values require more capable (and expensive) models. Workspace/tag/integration policy can clamp your requested floor down for cost control. If omitted, uses your workspace defaults.
Constrain routing to a specific provider (for example: "openai", "anthropic", "google", "xai", "fireworks", "novita", "baseten", "nebius", "deepseek", "mistral"). Omit for cross-provider optimization.
Enable prompt compression. Default: true
Lossy compaction preset when your request would exceed the model’s context window. Options: "off", "balanced" (default), "aggressive". Tool/file outputs may still be externalized losslessly into artifacts.
Sampling temperature (0-2). Default: provider default.
Maximum tokens in the response.
Key-value pairs for cost attribution. Example: {"team": "ml", "feature": "chatbot"}
Opt-in tool calling. Default: false. When true, LightReach forwards yourtools / tool_choice to the upstream provider so the model can emittool_calls in the response.
Optional tool definitions in OpenAI function-tool schema (only used when enable_tools=true).
Optional tool selection policy (only used when enable_tools=true).
Truncate the provided messages to at most this many messages (default: 50). Helpful when sending long histories.
tool_calls. For server-to-server API usage (non-Cursor), we also support a single-step server-side tool execution path that returns tool_results. We do not run a multi-step agent loop that repeatedly calls the model until completion.Response
{
"id": "chatcmpl-1741400000000",
"object": "chat.completion",
"created": 1741400000,
"model": "gpt-4o-mini",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "Quantum computing uses quantum mechanics..."},
"finish_reason": "stop"
}
],
"usage": {"prompt_tokens": 320, "completion_tokens": 120, "total_tokens": 440},
"content": "Quantum computing uses quantum mechanics...",
"compression_stats": {
"compression_enabled": true,
"original_tokens": 450,
"compressed_tokens": 320,
"token_savings": 130,
"compression_ratio": 0.711,
"token_accounting_note": "token_savings is input-side only (original - compressed). Output tokens are reported separately in llm_stats."
},
"llm_stats": {
"provider": "openai",
"model": "gpt-4o-mini",
"input_tokens": 320,
"output_tokens": 120,
"total_tokens": 440,
"finish_reason": "stop"
},
"warnings": [],
"model_used": "gpt-4o-mini",
"provider_used": "openai",
"cost_estimate": 0.00042,
"routing_info": {
"selected_model": "gpt-4o-mini",
"selected_provider": "openai",
"requested_hle": 25,
"effective_hle": 25,
"hle_source": "request",
"hle_clamped": false
},
"tool_calls": null,
"lightreach": {
"latency_ms": 812
}
}Error Handling
The API uses standard HTTP status codes. Errors return a JSON body with a detail field.
| Code | Meaning |
|---|---|
| 400 | Invalid request (missing fields, bad format) |
| 401 | Invalid or missing API key |
| 403 | Feature not available on your plan |
| 429 | Rate limit or spend limit exceeded |
| 502 | Upstream provider error |
Features
Intelligent Routing
The routing system automatically selects the most cost-effective model that meets your quality requirements. It uses HLE (Humanity's Last Exam) scores as a standardized benchmark for model capability.
What is HLE?
Humanity's Last Exam is a benchmark of 2,500 expert-level questions across 100+ subjects, designed to measure frontier AI capabilities. Current state-of-the-art models score around 40%. A desired_hle of 25 is a common starting point for “capable enough” models at low cost.
Universe-constrained selection
Routes to approved models available through Compress Cloud. Optional provider keys can extend the available model set for a specific account.
HLE cascading
Your requested quality floor can be clamped by workspace policy. Effective HLE is min(desired_hle, tag_ceiling, integration/global_ceiling) (when those ceilings are configured).
Provider constraint
Optionally constrain to a single provider if you need consistent behavior or have provider-specific requirements.
Prompt Compression
The greedy compression algorithm identifies and replaces repeated patterns with shorter references. Compression is lossless. The LLM receives instructions to expand the references, preserving full semantic meaning.
Typical token reduction on verbose prompts
Processing time for 10KB of text
Compression works best on prompts with repeated content, such as system prompts with examples, RAG contexts with similar documents, or multi-turn conversations with repeated context.
Context windows & compaction
Long-running chats and tool outputs can exceed a model’s context window. LightReach separates this into two mechanisms:
compaction_policy.Artifacts + capsules (lossless)
Oversized tool/file outputs are stored as artifacts and replaced in-context by small, deterministic capsules that include an excerpt and a handle. Models can retrieve bounded previews via fetch_artifact.
Compaction (lossy)
If the request is still over budget, LightReach can compact history by preserving system/developer prefixes, the latest user request, a pinned summary, and an explicit retrieval index of artifact handles. Policies let you trade strictness vs aggressiveness.
balanced unless you’re building a strict integration that must never change message structure (off), or you routinely run very long tool-heavy sessions (aggressive).Cost Attribution
Every request is tracked with deterministic cost calculation based on real-time pricing data. Use tags to attribute costs to teams, features, environments, or integrations.
# Tag requests for attribution
response = requests.post(
"https://compress.lightreach.io/api/v2/complete",
headers={"Authorization": "Bearer " + api_key},
json={
"messages": [...],
"tags": {
"team": "ml-platform",
"feature": "recommendations",
"env": "production",
"experiment": "v2-ranking"
}
}
)
# View costs grouped by tags in the dashboardPlans & Limits
Compress Cloud executes approved models for your workspace and meters requests by tokens. Customer provider keys remain an optional advanced setting. Contact us for current usage terms while token pricing is being finalized.
| Plan | Price | Included Usage | Team Size |
|---|---|---|---|
| Free | $0/mo | Up to $20/mo routed | 1 teammate |
| Pro | $49/mo | Up to $1,000/mo routed | 10 teammates |
| Scale | $149/mo | Up to $5,000/mo routed | 50 teammates |
| Enterprise | Custom | Unlimited | Unlimited |
Pro and Scale plans include conversation logging (opt-in), budgets with hard caps, and advanced analytics. Enterprise adds on-premise deployment, SSO, and custom SLAs. View full plan comparison →
Security
Encryption
All traffic uses HTTPS/TLS. Optional customer provider API keys are encrypted at rest using Fernet (symmetric authenticated encryption) backed by API_KEY_ENCRYPTION_KEY. Passwords use bcrypt with 12 rounds.
Data retention
By default, LightReach stores request metadata and a short prompt preview for analytics. Full conversation logging is opt-in on paid plans, with configurable retention (Pro: 30 days; Scale/Enterprise: 30/60/90 days). Request-level analytics retention is tiered (Free: 14 days; paid: 365 days).
Access control
JWT-based authentication with automatic refresh. Role-based access for teams (Owner, Admin, Member, Viewer). Tag-scoped visibility for fine-grained data access.
Compliance
GDPR and CCPA compliant. Data export and full account deletion available on request.