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.

# 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

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
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 Bypasses Prune; uses official SDK directly
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.1.1.tar.gz (17.6 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.1.1-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for prune_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e50ecd42e74ee3288b36519426581281c0f6ba74c6e8185fa6bbc4e75e595e5a
MD5 266e58ec39c4fa8f4caa4be94fb8d67a
BLAKE2b-256 41c79c358882b63c502cf0ab4088f9689b2362a3ec529cfcd8f9ddc6520713e0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for prune_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 901a15ce1ae80abaa68ec3904b273225904bea06e9eb4bb41dbc89447eaee10e
MD5 b54fb1e685538d1a6a6e046f23ad38ea
BLAKE2b-256 929526a7b114d81ee013c67c649dd0bd0b22dec0bf1c715d4fa733d5db690c14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page