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.0.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.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: adlib_client-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 89632ce33010db2323707428383be9b4ba96b07fd4c23a19108b570680787cb2
MD5 3a4a910fe7338775b6e45be4cd0b505f
BLAKE2b-256 0b6397062ed07f7250e580b0cccb05a04d4358b32ef52f05878cef58807a7ac1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: adlib_client-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3827334de63cb59969ffc0ee7631b5cb991406845c4c2a89082f69293a47fb4
MD5 cc2ac066d4b58e7a0cae7fc075f650ba
BLAKE2b-256 fff43f8727935f03489430be2022b48ae3a0a23144807531b9c881f7041c9559

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