Ad network that delivers ads to the LLM's response
Project description
Adstract AI Python SDK
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 failurerequest_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
607f4885c7404a80f369fa9f2bda22ef71ffd0ae29533c76642df3b8ff1d1ac9
|
|
| MD5 |
a1dd63caa93e8d324276f12c98fd2b06
|
|
| BLAKE2b-256 |
371e23d22bb37c473a3aa2ef7e4a6ebf1457dd8ba8c932e7f23357f211e65e80
|
Provenance
The following attestation bundles were made for adstractai-0.3.1.tar.gz:
Publisher:
publish.yml on Adstract-AI/adstract-library
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adstractai-0.3.1.tar.gz -
Subject digest:
607f4885c7404a80f369fa9f2bda22ef71ffd0ae29533c76642df3b8ff1d1ac9 - Sigstore transparency entry: 975910830
- Sigstore integration time:
-
Permalink:
Adstract-AI/adstract-library@5262551b2b13e628b9a16d36397fd1dae19f0972 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/Adstract-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5262551b2b13e628b9a16d36397fd1dae19f0972 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
171ba79afdd4c46a223ccd43398e73f817315b3d83482963a4abbe68529c7ba6
|
|
| MD5 |
10484964ecb788e2656e90691f1127cc
|
|
| BLAKE2b-256 |
3a4ee4335fa1b9cd055c48a419f6139b76b4a959d02ce387b0f43f2426e69b28
|
Provenance
The following attestation bundles were made for adstractai-0.3.1-py3-none-any.whl:
Publisher:
publish.yml on Adstract-AI/adstract-library
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adstractai-0.3.1-py3-none-any.whl -
Subject digest:
171ba79afdd4c46a223ccd43398e73f817315b3d83482963a4abbe68529c7ba6 - Sigstore transparency entry: 975910832
- Sigstore integration time:
-
Permalink:
Adstract-AI/adstract-library@5262551b2b13e628b9a16d36397fd1dae19f0972 -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/Adstract-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5262551b2b13e628b9a16d36397fd1dae19f0972 -
Trigger Event:
push
-
Statement type: