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

Uploaded Python 3

File details

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

File metadata

  • Download URL: adlib_client-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 9d40b13964ad73d88d2a17b45bbf8016b7fe1bc8a3d5223cfcd4d3207f90265c
MD5 56fc781f19e1b401b2d16ce168939f4d
BLAKE2b-256 adb8c5109b6ed61132dc0b727d8a5e439bae25b766232fe9497fba3fe86764f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: adlib_client-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 08d7de28fad3955206ee74ac7ea62a9214c543ba6a8cf7eae4bb5c1b000a09dd
MD5 60b5070e67c0e4b98d8950625256ed10
BLAKE2b-256 ccca4a82a9c0a018110ad56e9aca4ffe80e82396f0ced29eb0c6f5de54a39e8e

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