Skip to main content

Official Python SDK for TokenBee LLM inference gateway and observability.

Project description

TokenBee Python SDK

Official Python SDK for TokenBee - The Intelligent LLM Inference Gateway with Observability, Compression, and Privacy.

Features

  • Unified API: Access multiple LLM providers (OpenAI, Anthropic, Google, Mistral, etc.) through a single interface.
  • Intelligent Compression: Reduce token usage and latency with context-aware compression.
  • Privacy Guard: Automatic PII masking and privacy-preserving inference.
  • Built-in Observability: Automatic tracking of latency, costs, and token usage.

Links

Installation

pip install tokenbee-sdk

Quick Start

from tokenbee import TokenBee, TokenBeeModel, CompressionRate

# Initialize the client with your TokenBee API key 
# AND your LLM provider key (Bring Your Own Key - BYOK)
client = TokenBee(
    api_key="your_tokenbee_api_key",
    llm_key="your_llm_provider_key", # e.g. OpenAI or Anthropic key
    compression="auto",
    rate=CompressionRate.MEDIUM
)

# Send a request
response = client.send(
    model=TokenBeeModel.OPENAI_GPT_4O,
    input={
        "messages": [
            {"role": "user", "content": "Explain quantum entanglement in simple terms."}
        ]
    }
)

print(response["choices"][0]["message"]["content"])

Bring Your Own Key (BYOK)

TokenBee is a stateless gateway. We do not store your LLM provider API keys in our database. You pass your provider key (OpenAI, Anthropic, etc.) through the SDK's llm_key parameter. The SDK sends this in the X-LLM-Key header, allowing the TokenBee proxy to forward requests to the provider on your behalf while you maintain full control over your billing and security.

Advanced Usage

Compression Control

You can specify the compression rate and method per request. TokenBee uses an intelligent semantic engine to reduce token usage while preserving meaning.

response = client.send(
    model=TokenBeeModel.ANTHROPIC_CLAUDE_3_5_SONNET,
    input={
        "messages": [...],
        "compression": "auto",      # "auto" (default), "on", or "off"
        "rate": CompressionRate.HIGH, # MEDIUM (0.5), HIGH (0.33), etc.
        "privacy": True
    }
)
  • compression: Set to "auto" to let TokenBee decide when to compress, or "off" to bypass the compression engine entirely for high-precision tasks.
  • rate: Controls the aggressiveness of compression. HIGH aims for ~67% token reduction.
  • sessionId: (Optional) String ID to group multiple requests into a single replayable session in the dashboard.
  • userId: (Optional) String ID to track usage and costs per unique end-user.
  • privacy: (Optional) Set to True to disable payload logging and session replays for this request. Metadata (latency, tokens) will still be recorded for observability.

Supported Models

The SDK provides a TokenBeeModel enum with popular models:

  • TokenBeeModel.OPENAI_GPT_4O
  • TokenBeeModel.ANTHROPIC_CLAUDE_3_5_SONNET
  • TokenBeeModel.GEMINI_2_0_FLASH
  • ... and many others.

License

MIT

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

tokenbee_sdk-1.2.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

tokenbee_sdk-1.2.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file tokenbee_sdk-1.2.3.tar.gz.

File metadata

  • Download URL: tokenbee_sdk-1.2.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for tokenbee_sdk-1.2.3.tar.gz
Algorithm Hash digest
SHA256 cd1186c547572568c5bcf85d236c1949c337abd19f0a6d487534b4902a15b469
MD5 398ee2d11e98633bc6ba1385c1ccb3d9
BLAKE2b-256 de614cc54df27c271832940c34c03d5bea65eaf6b2f96094bbc801af26b18e23

See more details on using hashes here.

File details

Details for the file tokenbee_sdk-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: tokenbee_sdk-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for tokenbee_sdk-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aa92a877ad0b13882c4815f0f3385be7826be973ef86cfff0126533e9e19c22b
MD5 36b61ed0e3d7d80e2b4d779cc22fe4cb
BLAKE2b-256 3ef9446b79c30322fffb5f788ff876831d0361d9ca8f3a489ff536d3c7eb25cd

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