Skip to main content

Internal Python SDK for injecting AI-native ads

Project description

@clad-ai/python

Table of Contents

Overview

Clad provides a lightweight Python SDK for secure, low-latency native ad injection in LLM workflows. It gives developers clear choices for how much memory and state they wish to handle locally or outsource to Clad’s backend.

⚠️ This SDK is proprietary and intended for authorized Clad Labs clients only. Use or redistribution without permission is strictly prohibited.

Installation

pip install clad-ai-python

Instantiating CladClient

Before calling any method, create an instance of CladClient with an API key we will provide you and (optionally) your own Redis client for production scalability.

import redis.asyncio as aioredis
from clad_ai_python import CladClient

# Example: connect to your Redis instance
r = aioredis.from_url("redis://localhost:6379/0")

clad = CladClient(
  api_key="PROVIDED_CLAD_API_KEY",
  threshold=5,          # Optional: how many messages before calling API (default: 3)
  redis_client=r        # Optional: only needed for get_processed_input_with_redis
)

Parameters:

  • api_key: str — API key provided by Clad. Contact support@clad.ai to get yours.
  • threshold: int — Optional. Number of messages before triggering an API call. Defaults to 3.
  • redis_client: Redis client — Optional. Pass your Redis client if using

Core Concepts

Three modes of operation:
Each mode offers a different balance of speed, memory footprint, and infrastructure requirements. These trade-offs let you choose the best fit for your scale, cost, and reliability needs.

  • get_processed_input: is fast but uses your server’s RAM (still lightweight)

  • get_processed_input_fully_managed: uses no local memory but adds slight network latency to every message

  • get_processed_input_with_redis: offloads state to a dedicated store for high performance and consistent scaling across servers. Fast and low memory, ideal for production but requires additional setup

Exports

get_processed_input

In this mode, the SDK uses an in-process TTL cache to track each user’s message count and context directly in your server’s RAM. This provides ultra-low latency (microseconds for reads/writes) and minimizes API calls by handling counting locally until a threshold is reached. It’s simple to set up with no extra infrastructure required. This consumes server RAM linearly with the number of active users.

Example:

clad = CladClient(api_key="YOUR_API_KEY")

response = await clad.get_processed_input(
    user_input="I'm looking for shoes",
    user_id="uuid4-from-frontend",
    discrete="true"
)

print(response["prompt"])  # Final prompt with or without ad

Parameters:

  • user_input: str — Chat message
  • user_id: str — UUID from frontend
  • discrete: str — "true" or "false"

Returns:

{
  "prompt": str,
  "promptType": "clean" | "injected",
  "link": str,
  "discrete": "true" | "false",
  "adType": str,
  "image_url": Optional[str]
}

get_processed_input_fully_managed

In this mode, the SDK does not store any counters or context locally. Instead, every message from the user is sent to Clad’s backend API, which fully manages the counting, context, and injection logic server-side. This approach requires zero memory on your servers and no extra infrastructure. However, it adds slight network latency to every user message since each one must reach the API. This mode is ideal if you want Clad to handle everything automatically with no local state.

Example:

clad = CladClient(api_key="YOUR_API_KEY")

response = await clad.get_processed_input_fully_managed(
  user_input="Looking for cafes",
  user_id="uuid4-from-frontend",
  discrete="false",
  threshold=5
)

Parameters:

  • Same as above, plus optional threshold: int

Returns: Same shape as above.


get_processed_input_with_redis

Use this for production — your backend stores state in your Redis instance for maximum control + scalability. In this mode, the SDK connects to a Redis instance that you deploy and manage (e.g., Redis Cloud, AWS ElastiCache). Per-user counters and context are stored efficiently in Redis RAM instead of your server RAM, enabling low-latency reads/writes (~1 ms) while sharing state consistently across multiple backend servers. This option is the most robust and production-ready choice for large user bases, offering fast performance with centralized state management and minimal local memory use.

Example:

import redis.asyncio as aioredis

r = aioredis.from_url("redis://localhost:6379/0")
clad = CladClient(api_key="YOUR_API_KEY", redis_client=r)

response = await clad.get_processed_input_with_redis(
  user_input="Book a hotel",
  user_id="uuid4-from-frontend",
  discrete="false"
)

Parameters: Same as get_processed_input.


Generating a user_id

👉 Use the Clad React SDK to create a UUID and pass it to your backend calls.

Example:

import { getOrCreateUserId } from '@clad-ai/react';

const userId = getOrCreateUserId(); // stores in localStorage

Then pass userId to your Python server route and use it for Clad calls.


Support

For help, email us at support@clad.ai

Copyright (c) 2025 Clad Labs

This software is proprietary and confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited without express written permission from Clad Labs.

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

clad_ai_python-0.1.2.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

clad_ai_python-0.1.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file clad_ai_python-0.1.2.tar.gz.

File metadata

  • Download URL: clad_ai_python-0.1.2.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for clad_ai_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4a4596cbcd37217140dd24085286a8c296e2d9563c7aaaecc1ab3a9528f55c3b
MD5 5937df087ca86d1a3b09f0382a8a4119
BLAKE2b-256 5e9db097abc226a468bcdb06613d4976836f1f96316d072b2263f875cd24ffb6

See more details on using hashes here.

File details

Details for the file clad_ai_python-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: clad_ai_python-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for clad_ai_python-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 77334d815d38d1ec6d83f2b22e877701c1c3641afe2a41304924735f7cd4aa82
MD5 51ab3a24369f37da3562a4a9957f580f
BLAKE2b-256 23a08f7c77619d1215421f6a58a28228678ad71db2e807c74e1be73e990cd5dc

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