Prune SDK
Drop-in OpenAI / Anthropic clients for the Prune AI proxy - lower bills on every call, vaulted API keys, and a receipt on every response. Cache helps on repeats.
What's new in 0.3.0
- 6 new providers -
Groq,Mistral,Deepseek,Xai,Together, andCohereclients, routed through Prune the same way as the existing ones.Coherereturnsanthropic.types.Message(the backend normalizes Cohere's native Chat v2 shape to Anthropic-Messages); the rest returnChatCompletion. - Version bump - package version is now
0.3.0.
What's new in 0.2.0
- Receipt verification -
prune.verifyexposesverify_receipt(receipt, public_key_url)to validate Ed25519-signed receipts returned by the proxy. Use it in audit pipelines or CI to prove savings are real. cryptographydependency - Ed25519 verification is powered by thecryptographypackage (added to install dependencies).
# Before
from anthropic import Anthropic
# After
from prune import Anthropic
Supported providers
| Provider | Status |
|---|---|
| Anthropic (Claude) | Live via proxy |
| OpenAI (GPT) | Live via proxy |
| Google Gemini | Live via proxy |
| AWS Bedrock | Live via proxy |
| Ollama (local/self-hosted) | Live via proxy |
| OpenRouter | Live via proxy |
| Groq | Live via proxy |
| Mistral | Live via proxy |
| DeepSeek | Live via proxy |
| xAI (Grok) | Live via proxy |
| Together AI | Live via proxy |
| Cohere | Live via proxy |
Links
- Website: https://www.withprune.com
- Docs: https://www.withprune.com/docs
- API: https://api.withprune.com
Installation
pip install prune-sdk
For local backend development:
export PRUNE_BASE_URL="http://127.0.0.1:8000"
Install from source (contributors):
pip install -e "./prune-sdk[dev]"
Quick start
Anthropic (Claude)
from prune import Anthropic
client = Anthropic(
api_key="sk-ant-your-key",
prune_api_key="prune_your_key",
)
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, Claude!"}],
)
print(message.content[0].text)
print(client.last_prune_metadata) # cache hit, tokens saved, etc.
OpenAI (GPT)
from prune import OpenAI
client = OpenAI(
api_key="sk-your-openai-key",
prune_api_key="prune_your_key",
)
completion = client.chat.completions.create(
model="gpt-4o-mini",
max_tokens=256,
messages=[{"role": "user", "content": "Hello!"}],
)
print(completion.choices[0].message.content)
Async
from prune import AsyncAnthropic
client = AsyncAnthropic(
api_key="sk-ant-...",
prune_api_key="prune_...",
)
message = await client.messages.create(
model="claude-3-5-haiku-20241022",
max_tokens=100,
messages=[{"role": "user", "content": "Hi"}],
)
Configuration
Environment variables:
export PRUNE_API_KEY="prune_your_key"
export PRUNE_BASE_URL="https://api.withprune.com" # or http://127.0.0.1:8000 for local backend
export PRUNE_FALLBACK="true" # fallback to direct API if proxy fails
Programmatic:
import prune
prune.configure(api_key="prune_your_key", base_url="https://api.withprune.com")
client = prune.Anthropic(api_key="sk-ant-...")
Workload packs & dashboard settings
Optimization mode (Recommended / Max / Off) and your default workload pack are saved in the dashboard and applied on every proxy request - no SDK changes required.
Optional: override or hint workload per app via headers:
import prune
prune.configure(
api_key="prune_your_key",
prune_workload="structured_planning", # X-Prune-Workload
prune_template_id="focus_breakdown_v1", # X-Prune-Template-Id
)
client = prune.OpenAI(
api_key="sk-...",
prune_workload="support_chat", # client default; per-call prune_workload= wins
)
client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello"}],
prune_workload="rag", # per-request override
)
Valid pack ids: structured_planning, structured_extraction, support_chat, agent_step, rag, batch, creative (see prune.WORKLOAD_PACKS).
Per-request kwargs: prune_session_id, prune_end_user_id, prune_org_id, prune_run_id, prune_workload, prune_template_id.
Behavior
| Feature | Details |
|---|---|
| Proxy routing | Anthropic → /v1/proxy/anthropic/messages · OpenAI → /v1/proxy/openai/chat/completions · Gemini, Bedrock, Ollama, OpenRouter, Groq, Mistral, DeepSeek, xAI, Together → /v1/proxy/<provider>/chat/completions · Cohere → /v1/proxy/cohere/chat |
| Quality | Cache miss = same payload to the provider as without Prune. Cache hit = identical prior response. |
| Savings | Exact + semantic cache; Claude system prompt caching. See docs/SAVINGS_MODEL.md. |
| Response type | Real anthropic.types.Message / ChatCompletion objects |
| Streaming | OpenAI: routed through Prune SSE (caps/receipts apply). Anthropic: still bypasses Prune - use non-stream or OpenAI client until parity. |
| Fallback | On proxy outage (5xx / network), calls Anthropic/OpenAI directly |
| Disable Prune | Anthropic(..., enable_prune=False) |
| Prompt Pass | HTTP header X-Prune-Optimize: light or compact (optional; default off) |
Direct HTTP (no SDK)
If you only need to test the proxy, skip the SDK and POST to the backend:
curl -X POST http://127.0.0.1:8000/v1/proxy/anthropic/messages ^
-H "X-Prune-Key: prune_your_key" ^
-H "Content-Type: application/json" ^
-d "{\"model\":\"claude-sonnet-4-20250514\",\"max_tokens\":64,\"messages\":[{\"role\":\"user\",\"content\":\"Hello\"}],\"user_api_key\":\"sk-ant-...\"}"
import httpx
resp = httpx.post(
"http://127.0.0.1:8000/v1/proxy/anthropic/messages",
headers={"X-Prune-Key": "prune_your_key"},
json={
"model": "claude-sonnet-4-20250514",
"max_tokens": 64,
"messages": [{"role": "user", "content": "Hello"}],
"user_api_key": "sk-ant-...",
},
timeout=60,
)
print(resp.json())
Development
cd prune-sdk
pip install -e ".[dev]"
pytest tests/ -q
pytest tests/ -m integration # needs ANTHROPIC_API_KEY + PRUNE_API_KEY
License
MIT
Metadata
Release files for prune-sdk 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| prune_sdk-0.3.1.tar.gz | 27.2 kB | Without provenance | Details for prune_sdk-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| prune_sdk-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for prune_sdk-0.3.1-py3-none-any.whl |
Total release size: 62.1 kB
Release files / prune_sdk-0.3.1.tar.gz
| Download URL | prune_sdk-0.3.1.tar.gz |
|---|---|
| Size | 27.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d45a7b317c76d083a626e4ab2da76a1c1786721306cf09275f90eeee1feb554b
|
|
BLAKE2b-256 checksum How to use checksums |
99378a5a9e46caac3027ab2f7bd4e36d22d711c1f768bc159d0f49dbbf1efd22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.9
|
Release files / prune_sdk-0.3.1-py3-none-any.whl
| Download URL | prune_sdk-0.3.1-py3-none-any.whl |
|---|---|
| Size | 34.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3575e3232ae0d8712ea64a531628767a974ee87bb7a3fdc86961b0c0afe4d0f0
|
|
BLAKE2b-256 checksum How to use checksums |
1462bb0b86ac398788161a3c6dc80e4a56ecdfd2e327382dece5e85ff94247a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.9
|
Security for prune-sdk 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.