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:
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:
ADLIB_API_KEY=your_adlib_api_key_here ADLIB_CHATBOT_PUBLIC_KEY=your_chatbot_public_key_here
Option B — pass keys directly
from adlib_client import AdLib adlib = AdLib( adlib_api_key="your_adlib_api_key_here", adlib_chatbot_api_key="your_chatbot_public_key_here", )
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).
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.
Decorator Usage
Wrap any function that returns a string and adify will automatically
process its return value — no changes to your existing logic needed.
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?"))
adify_full()
When you need access to ad metadata — to render a banner, card, or button alongside
the main text — use adify_full() instead.
response = adlib.adify_full("My LLM answer text") # response["adified"] → the transformed output string # response["ad"] → ad metadata (may be an empty dict) if response["ad"]: render_ad_card(response["ad"]) print(response["adified"])
Response Format
adify_full() returns a dict matching this shape:
{
"adified": "...the output with an ad included...",
"ad": {
"url": "url of the ad",
"description": "description of the ad"
}
}
When no ad is inserted, ad is an empty object {}.
| Field | Type | Description |
|---|---|---|
adified |
string | The transformed output (always present) |
ad.url |
string | Destination URL of the ad |
ad.description |
string | Ad copy / description text |
response["ad"] to build richer interfaces: banners, cards, or call-to-action buttons —
rather than relying solely on the inline adified text.
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() |