Skip to main content

tokencrush-langchain (Python)

LangChain-compatible Python client for TokenCrush prompt optimization API.

  • TokenCrushClient: thin HTTP client for POST /v1/crush
  • RunnableTokenCrush: a Runnable that accepts a prompt and returns the optimization result

Install

pip install tokencrush-langchain

Usage

from tokencrush_langchain import TokenCrushClient, RunnableTokenCrush

client = TokenCrushClient(api_key="YOUR_API_KEY")
res = client.crush({"prompt": "Summarize the following document ..."})
print(res.optimized_prompt)

crush = RunnableTokenCrush(api_key="YOUR_API_KEY")
result = crush.invoke("Rewrite this prompt to be concise while preserving meaning ...")
print(result.optimized_prompt)

API Contract

POST /v1/crush with JSON body { "prompt": string } and Authorization: Bearer <api key>.

Successful response shape:

{
  "optimized_prompt": "Optimized version of your prompt",
  "input_tokens": 10,
  "output_tokens": 6,
  "percentage_reduction": 40
}

Notes:

  • Only prompts with more than 20 tokens are optimized.
  • If similarity is below 80%, the original prompt is returned.
  • API may temporarily disable optimization for keys with poor performance.

Options

  • base_url: override API base (default https://api.tokencrush.ai)
  • fallback_to_input (Runnable): if API fails, return original prompt with 0% reduction

License

MIT

Metadata

Release files for tokencrush-langchain 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tokencrush-langchain 0.1.0
File Size Uploaded
tokencrush_langchain-0.1.0.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tokencrush-langchain 0.1.0
File Interpreter ABI Platform
tokencrush_langchain-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.5 kB

Release files / tokencrush_langchain-0.1.0.tar.gz

Download URL tokencrush_langchain-0.1.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d48dfe825a7beff212e0117e0d50463f1f6ddc75ba9b973484b30ef9c2050a13
BLAKE2b-256 checksum
How to use checksums
a63b88b3a0339bbe85fb533724c28c7ef64f0491b938ec67680f421a2b2494bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / tokencrush_langchain-0.1.0-py3-none-any.whl

Download URL tokencrush_langchain-0.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
779a3d8ee837a479b0a1fd99b29fe197c7f047624e85c843cb50946c1d88cad3
BLAKE2b-256 checksum
How to use checksums
2f0a2b16ac15b77e8563c241cce9709fa11fb41dc60c817a3e63d988230e6dc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page