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)
  filteredKeywords= ['starbucks', 'gambling', 'crypto', 'adult', 'politics', 'violence']    # Optional. keywords to filter out specific ads from being displayed.
  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.
  • filteredKeywords: list — Optional. keywords to filter out specific ads from being displayed.
  • 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.4.tar.gz (7.6 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.4-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clad_ai_python-0.1.4.tar.gz
  • Upload date:
  • Size: 7.6 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.4.tar.gz
Algorithm Hash digest
SHA256 b2beee8be84a53772d37b4ed41afd29526e37d27f070bb922e4aeb0f1e188387
MD5 0c0a3b8110d4b948f458dc5e1efda940
BLAKE2b-256 8b63b70dc7dacae293ed19692fea0aa16715a6cec3ee5555bd12668dbe4689c1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: clad_ai_python-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 6.3 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d6574a5b60ff6cc0f46cc5b1c901ea95229de75d26d4d9a9626ccc103775b18b
MD5 1fb0ceeeafd1cb172d8a5954112395b3
BLAKE2b-256 252dca37224d592ec69a8c650f299d632a226b3f8c428f2a44edbba4fc5fcbd3

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