Skip to main content

Official Python SDK for Trunkate AI

Project description

Trunkate AI Python SDK

The official Trunkate AI Python SDK provides synchronous bindings for Python 3.9+. It utilizes httpx internally for lightning-fast networking.

Installation

pip install trunkate-ai

Setup & Configuration

The SDK automatically reads the TRUNKATE_API_KEY from your environment.

import os
from trunkate_ai import Trunkate

# Initializes using os.environ.get("TRUNKATE_API_KEY")
client = Trunkate()

# Alternatively, pass it explicitly:
# client = Trunkate(api_key="tk_live_...")

Usage

# 1. Define your long prompt
prompt = "Your very long context..."

# 2. Optimize the prompt for a specific task
optimized = client.optimize(
    text=prompt,
    task="Summarize this document",
    budget=500,
    model="gpt-4o"
)

print(f"Reduced token count by {optimized.stats.reduction_percent}%")

Parameters

Parameter Type Required Description
text str Yes The raw, unoptimized prompt.
task str No Instructions on what the LLM should do with the prompt.
budget int No Target maximum token count (default: varies by model).
model str No The target LLM (default: gpt-4o).

Project details


Download files

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

Source Distribution

trunkate_ai-0.2.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

trunkate_ai-0.2.0-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file trunkate_ai-0.2.0.tar.gz.

File metadata

  • Download URL: trunkate_ai-0.2.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for trunkate_ai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ede098a6ff56b2144e918681cacd7063e762d54136ce5d27700dd1af6d49a3ce
MD5 f0d23548f2f005714603096475efef04
BLAKE2b-256 1155a44ff775269002d0addabbed53c98c869def82e5114899ec30e4c5a42a87

See more details on using hashes here.

File details

Details for the file trunkate_ai-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: trunkate_ai-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 2.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for trunkate_ai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52290b34dfdca6830b9adcef1217b6dc55f6a7fc4abcd50c872854881cd38722
MD5 f9afb2acedeacf85a372c391de5e255a
BLAKE2b-256 cc2feb7872dd4a27bcc3c255b543d61d8f06fbe4ac02b743899cc957185eff4f

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 Pingdom Monitoring Sentry Error logging StatusPage Status page