Skip to main content

Authentication

Kaizen uses a single bearer token for every SDK and HTTP request.

API key setup

  • Email [email protected] to receive a production key.
  • Store it in your secret manager or .env; never commit keys to source control.

Environment variables

export KAIZEN_API_KEY="kaizen_xxx"
export KAIZEN_BASE_URL="https://api.getkaizen.io/"   # optional override
export KAIZEN_TIMEOUT="30"                           # optional float seconds
Each provider wrapper also requires its vendor key:
  • OpenAI → OPENAI_API_KEY
  • Anthropic → ANTHROPIC_API_KEY
  • Gemini → GOOGLE_API_KEY

Programmatic configuration

from kaizen_client import KaizenClient, KaizenClientConfig

config = KaizenClientConfig(
    api_key="kaizen_xxx",
    base_url="https://api.getkaizen.io/",
    timeout=30,
    default_headers={"X-Request-ID": "docs-demo"}
)
client = KaizenClient(config)

Successful authentication check

import asyncio
import os
from kaizen_client import KaizenClient, KaizenClientConfig

async def main():
    # Ensure environment variables are loaded properly
    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:
        response = await client.prompts_encode({
            "prompt": {"messages": [{"role": "user", "content": "Test authentication"}]},
            "token_models": ["gpt-4o-mini"]
        })
        print("Authentication successful! Reduction:", response["stats"]["reduction_ratio"])

asyncio.run(main())
You should see a successful response with compression stats when the API key is valid.

Common mistakes

  • Missing env vars – the examples throw RuntimeError if KAIZEN_API_KEY or vendor keys are absent.
  • Wrong base URL – keep KAIZEN_BASE_URL unset unless Kaizen provisioned a dedicated host.
  • Expired keys – rotate secrets regularly; requests with revoked keys return 401 and raise KaizenAPIError.
  • Leaking keys in logs – rely on env vars or secret managers instead of embedding strings in code.