Skip to main content

Python Package for Monetizing your LLM using AdLib

Project description

adlib-client

A Python wrapper for monetizing LLM output with AdLib.

Install

Install from PyPI:

pip install adlib-client

Required API keys

AdLib requires two keys:

ADLIB_API_KEY=your_adlib_api_key_here
ADLIB_CHATBOT_PUBLIC_KEY=your_chatbot_public_key_here

You can provide them using environment variables or directly when creating AdLib():

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.

Basic usage

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)

adlib.adify() sends text to AdLib and returns the final transformed output.

Use AdLib as a decorator

from adlib_client import AdLib

adlib = AdLib()

@adlib.adify
def generate_answer(prompt: str) -> str:
    return f"Answer for: {prompt}"

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

The decorator wraps your function and automatically adifies its returned text.

Raw response access

When you need ad metadata, use adify_full():

response = adlib.adify_full("My LLM answer text")
print(response)
  • adify_full() returns the full JSON payload.
  • adify() returns only the adified string.

The response format is:

{
    "adified": "...the output with an ad included...",
    "ad": {
        "url": "url of the ad",
        "description": "description of the ad"
    }
}

If no ad is inserted, ad is an empty object. Your app should check response["ad"] before rendering ad-specific UI.

Use the ad metadata to build stronger interfaces: banners, cards, buttons, or other visual treatments—rather than relying only on the raw adified text.

What to expect

  • AdLib() only initializes successfully with both keys.
  • Missing keys cause an immediate exception.
  • Failed HTTP requests raise a requests exception via response.raise_for_status().
  • adify() returns the final output string.
  • adify_full() returns the dict with ad metadata.

When adlib.adify() succeeds:

  • If an ad was inserted, the returned output includes the ad content.
  • If no ad was inserted, the returned output is still valid text and response["ad"] will be empty.

Notes

  • adlib.adify() only inserts ads when the text is appropriate.
  • You can render the ad metadata separately from the main response text for cleaner UI.

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

adlib_client-0.1.2.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

adlib_client-0.1.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for adlib_client-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e8139c45a4f2291e3e9dbb4620375edd18ff9ee24b48339dadb2d1f7339555c4
MD5 d019f8f396da68f000a621c70a16ec8d
BLAKE2b-256 d8cbd4984d89f69f96cdf50a63fc3bab5f191e98636fd76b82323b7f3155e90d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for adlib_client-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 94946cf0d801297d92d027cda39b0c900e7fc93535dc7502e8b806d68b61502b
MD5 141f12a2fad75e1538ecbb0d37ee8762
BLAKE2b-256 72400baf882ce18c6942c52e2b1e4ecc06c8a72947c5e8386bef35a7a1570f49

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