Skip to main content

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, and Cohere clients, routed through Prune the same way as the existing ones. Cohere returns anthropic.types.Message (the backend normalizes Cohere's native Chat v2 shape to Anthropic-Messages); the rest return ChatCompletion.
  • Version bump - package version is now 0.3.0.

What's new in 0.2.0

  • Receipt verification - prune.verify exposes verify_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.
  • cryptography dependency - Ed25519 verification is powered by the cryptography package (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

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

Download files

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

Source Distribution

prune_sdk-0.3.0.tar.gz (26.8 kB view details)

Uploaded Source

Built Distribution

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

prune_sdk-0.3.0-py3-none-any.whl (34.6 kB view details)

Uploaded Python 3

File details

Details for the file prune_sdk-0.3.0.tar.gz.

File metadata

  • Download URL: prune_sdk-0.3.0.tar.gz
  • Upload date:
  • Size: 26.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.9

File hashes

Hashes for prune_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 88d289610b7e885b06726d0cdf1281ba386432635f4ea43859d965b1c99a6b36
MD5 ecc89c23dee0a8b1d3d2b59a2f13ab00
BLAKE2b-256 1ec92e437a64318f825a36871286494e612efd4b2382859696ce74cafef4369d

See more details on using hashes here.

File details

Details for the file prune_sdk-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: prune_sdk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 34.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.9

File hashes

Hashes for prune_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0cde81c3f82885cee6bac11d28222534a6091c05614d8f617d788706979539c
MD5 9d8c49f20c2a57620be1e11b648fb064
BLAKE2b-256 b30d4fa3d636b8a49fe7fb39c89cd7f817df9ddacb1e6eab319044801b96481c

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.1

2 files

This release

0.3.0 This release

2 files

0.1.1

2 files

0.1.0

2 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