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.6.tar.gz (3.3 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.6-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: adlib_client-0.1.6.tar.gz
  • Upload date:
  • Size: 3.3 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.6.tar.gz
Algorithm Hash digest
SHA256 b20535cc67de078a9315937a521c4d541d3eeb4fa9c9831116947126e9e934e4
MD5 1ef431a5b3fc664645a67b21127aaeb5
BLAKE2b-256 4f6221ccdefa499ee8344222ce6d037269a558900987d0979f6834df7d17b010

See more details on using hashes here.

File details

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

File metadata

  • Download URL: adlib_client-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 3.7 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 df9740a0a72db02dfcec557aea9d06fd7f9c8c156aa7ddf069c0603f0d912682
MD5 3ba55c71a6ea2b707deff341ec1f3611
BLAKE2b-256 54bb9cee7fd693653cd804e0ca3b896ba305883c296d6ab468694e794ce1668d

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