Documentation
Python adlib-client

Python SDK

Monetize your LLM output in a single function call. adlib-client wraps the AdLib API so you can drop ad delivery into any Python application without managing HTTP yourself.


Installation

Install the latest release from PyPI:

bash
pip install adlib-client

API Keys

AdLib requires two keys. Obtain them from your Developer Console.

Variable Description
ADLIB_API_KEY Your secret AdLib API key
ADLIB_CHATBOT_PUBLIC_KEY Public key for the chatbot delivering ads

Option A — environment variables

Set the keys in your shell or .env file and AdLib() picks them up automatically:

env
ADLIB_API_KEY=your_adlib_api_key_here
ADLIB_CHATBOT_PUBLIC_KEY=your_chatbot_public_key_here

Option B — pass keys directly

python
from adlib_client import AdLib

adlib = AdLib(
    adlib_api_key="your_adlib_api_key_here",
    adlib_chatbot_api_key="your_chatbot_public_key_here",
)
If either key is missing, AdLib() raises an exception immediately. Both keys are required.

Quick Start

Call adlib.adify() with your LLM's output. It returns the transformed string with an ad naturally woven in (when appropriate).

python
from adlib_client import AdLib

adlib = AdLib()

llm_output = "Here is the answer from your model."
adified_output = adlib.adify(llm_output)

print(adified_output)
adify() only inserts an ad when the text content is appropriate — your output is always returned, with or without an ad. Streaming is handled automatically under the hood, so there's nothing extra to configure.

Decorator Usage

Wrap any function that returns a string and adify will automatically process its return value — no changes to your existing logic needed.

python
from adlib_client import AdLib

adlib = AdLib()

# Decorate any function that returns a string
@adlib.adify
def generate_answer(prompt: str) -> str:
    return f"Answer for: {prompt}"

print(generate_answer("What is the weather?"))

Model Examples

Here's how to drop AdLib into a complete app for the most popular LLM providers. Each example is a working chatbot — copy, add your keys, and run.

python
from openai import OpenAI
from adlib_client import AdLib

client = OpenAI()          # uses OPENAI_API_KEY env var
adlib  = AdLib()           # uses ADLIB_API_KEY + ADLIB_CHATBOT_PUBLIC_KEY

def chat(user_message: str):
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": user_message}],
    )

    llm_output = response.choices[0].message.content
    print(adlib.adify(llm_output))

chat("What are some good sci-fi books?")

Errors

The SDK raises standard Python exceptions — no custom error hierarchy to learn.

Situation Exception raised
Missing API key(s) on init Exception — immediate, before any request
HTTP error from the AdLib API requests.HTTPError — via response.raise_for_status()