Skip to main content

Quick Start

Fastest path to a working encode → decode round-trip.

1. Install & set secrets

pip install kaizen-client
export KAIZEN_API_KEY="kaizen_xxx"

2. Initialize the client

import os
from kaizen_client import KaizenClient, KaizenClientConfig

# Explicit configuration for reliable environment loading
config = KaizenClientConfig(
    api_key=os.getenv("KAIZEN_API_KEY"),
    base_url=os.getenv("KAIZEN_BASE_URL", "https://api.getkaizen.io/"),
    timeout=float(os.getenv("KAIZEN_TIMEOUT", "30"))
)
client = KaizenClient(config)

3. Call the API

import asyncio
import os
from kaizen_client import KaizenClient, KaizenClientConfig

async def main():
    config = KaizenClientConfig(
        api_key=os.getenv("KAIZEN_API_KEY"),
        base_url=os.getenv("KAIZEN_BASE_URL", "https://api.getkaizen.io/"),
        timeout=float(os.getenv("KAIZEN_TIMEOUT", "30"))
    )
    
    async with KaizenClient(config) as client:
        encoded = await client.prompts_encode({
            "prompt": {"messages": [{"role": "user", "content": "Compress me"}]},
            "token_models": ["gpt-4o-mini"]
        })
        decoded = await client.prompts_decode({"ktof": encoded["result"]})
        print("Reduction:", encoded["stats"]["reduction_ratio"])
        print("Decoded:", decoded["result"]["messages"][0]["content"])

asyncio.run(main())
You now have a compressed prompt, a decoded response, and the savings printed to stdout—all in under a minute.