Skip to main content

Ad network that delivers ads to the LLM's response

Project description

Adstract AI Python SDK

Python Python Python

Ad network SDK that enhances LLM prompts with integrated advertisements.

Official Documentation

Full documentation is available at: https://adstract-ai.github.io/adstract-documentation/

Install

pip install adstractai

Quickstart

from adstractai import Adstract
from adstractai.models import AdRequestConfiguration

client = Adstract(api_key="adpk_live_123")

result = client.request_ad_or_default(
    prompt="How do I improve analytics in my LLM app?",
    config=AdRequestConfiguration(
        session_id="sess-1",
        user_agent=(
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
            "(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
        ),
        x_forwarded_for="192.168.1.1",
    ),
)

# Enhanced prompt with integrated ads or original prompt on failure
print(result.prompt) 

client.close()

Authentication

Pass an API key when initializing the client or set ADSTRACT_API_KEY.

export ADSTRACT_API_KEY="adpk_live_123"
from adstractai import Adstract

client = Adstract()

Required Parameters

All ad enhancement methods require both user_agent, x_forwarded_for, and a session_id. Missing any required value will return an EnhancementResult with success=False and a MissingParameterError in error.

from adstractai import Adstract
from adstractai.errors import MissingParameterError
from adstractai.models import AdRequestConfiguration

client = Adstract(api_key="adpk_live_123")

result = client.request_ad_or_default(
    prompt="Test prompt",
    config=AdRequestConfiguration(
        session_id="sess-1",
        user_agent="",  # Empty user_agent
        x_forwarded_for="192.168.1.1",
    ),
)

if isinstance(result.error, MissingParameterError):
    print(f"Error: {result.error}")

Available Methods

  • request_ad_or_default() - Returns enhanced prompt or original prompt on failure
  • request_ad_or_default_async() - Async version with fallback behavior

Async usage

import asyncio

from adstractai import Adstract
from adstractai.models import AdRequestConfiguration


async def main() -> None:
    client = Adstract(api_key="adpk_live_123")

    result = await client.request_ad_or_default_async(
        prompt="Need performance tips",
        config=AdRequestConfiguration(
            session_id="sess-99",
            user_agent=(
                "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
                "(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
            ),
            x_forwarded_for="192.0.2.1",
        ),
    )

    print(result.prompt)
    await client.aclose()


asyncio.run(main())

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

adstractai-0.3.0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

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

adstractai-0.3.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file adstractai-0.3.0.tar.gz.

File metadata

  • Download URL: adstractai-0.3.0.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for adstractai-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c5c3e618ee5df832ff6d2c87ea91adfa36dd0b2866fdeec0b43b165db8c975a2
MD5 205522c2b96b333ff634f16b6fd35e3c
BLAKE2b-256 7d752b75f29bc36ac61ebc12b08757f6e1f8f69bdf64e272ab2b007d2a00005b

See more details on using hashes here.

Provenance

The following attestation bundles were made for adstractai-0.3.0.tar.gz:

Publisher: publish.yml on Adstract-AI/adstract-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file adstractai-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: adstractai-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for adstractai-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1759c2676981d4db07ceb5672de5ece50ae9b2fe97f17e9512f7f2c93bd219f
MD5 d56a22061a64fb3b46b07b27ed25f936
BLAKE2b-256 a4b7e3144a95f411bd1347ac93cbdbfde68a8b6a31eae2089c3811c33b4ccf83

See more details on using hashes here.

Provenance

The following attestation bundles were made for adstractai-0.3.0-py3-none-any.whl:

Publisher: publish.yml on Adstract-AI/adstract-library

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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