LangChain Runnable client for TokenCrush prompt optimization API (/v1/crush)
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tokencrush_langchain-0.1.0.tar.gz.
File metadata
- Download URL: tokencrush_langchain-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d48dfe825a7beff212e0117e0d50463f1f6ddc75ba9b973484b30ef9c2050a13
|
|
| MD5 |
0079a30956e0bc7efc5ccd03822540eb
|
|
| BLAKE2b-256 |
a63b88b3a0339bbe85fb533724c28c7ef64f0491b938ec67680f421a2b2494bd
|
File details
Details for the file tokencrush_langchain-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tokencrush_langchain-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
779a3d8ee837a479b0a1fd99b29fe197c7f047624e85c843cb50946c1d88cad3
|
|
| MD5 |
450fa3a92c234a6d9d7663fcdfef0600
|
|
| BLAKE2b-256 |
2f0a2b16ac15b77e8563c241cce9709fa11fb41dc60c817a3e63d988230e6dc1
|