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.1.tar.gz (16.5 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.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: adstractai-0.3.1.tar.gz
  • Upload date:
  • Size: 16.5 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.1.tar.gz
Algorithm Hash digest
SHA256 607f4885c7404a80f369fa9f2bda22ef71ffd0ae29533c76642df3b8ff1d1ac9
MD5 a1dd63caa93e8d324276f12c98fd2b06
BLAKE2b-256 371e23d22bb37c473a3aa2ef7e4a6ebf1457dd8ba8c932e7f23357f211e65e80

See more details on using hashes here.

Provenance

The following attestation bundles were made for adstractai-0.3.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: adstractai-0.3.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 171ba79afdd4c46a223ccd43398e73f817315b3d83482963a4abbe68529c7ba6
MD5 10484964ecb788e2656e90691f1127cc
BLAKE2b-256 3a4ee4335fa1b9cd055c48a419f6139b76b4a959d02ce387b0f43f2426e69b28

See more details on using hashes here.

Provenance

The following attestation bundles were made for adstractai-0.3.1-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