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.1.tar.gz (27.2 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.1-py3-none-any.whl (34.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: prune_sdk-0.3.1.tar.gz
  • Upload date:
  • Size: 27.2 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.1.tar.gz
Algorithm Hash digest
SHA256 d45a7b317c76d083a626e4ab2da76a1c1786721306cf09275f90eeee1feb554b
MD5 72fdb9d25617f6e584c98e65310fb13c
BLAKE2b-256 99378a5a9e46caac3027ab2f7bd4e36d22d711c1f768bc159d0f49dbbf1efd22

See more details on using hashes here.

File details

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

File metadata

  • Download URL: prune_sdk-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 34.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3575e3232ae0d8712ea64a531628767a974ee87bb7a3fdc86961b0c0afe4d0f0
MD5 a240750d8585e7aaacfd26f5927890b0
BLAKE2b-256 1462bb0b86ac398788161a3c6dc80e4a56ecdfd2e327382dece5e85ff94247a2

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 files

0.3.0

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