Observed since 20 Oct, 19:54 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Ad network that delivers ads to the LLM's response
Adstract integrates ad-enhanced prompts into LLM applications and provides the acknowledgment flow required to close the ad cycle after the final model response is produced.
Full documentation is available at Adstract Documentation.
pip install adstractai
Pass an API key when initializing the client, or set the ADSTRACT_API_KEY
environment variable.
export ADSTRACT_API_KEY="adpk_live_123"
from adstractai import Adstract
client = Adstract()
from adstractai import Adstract, AdRequestContext
client = Adstract(api_key="adpk_live_123")
result = client.request_ad(
prompt="How do I improve analytics in my LLM app?",
context=AdRequestContext(
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"
),
user_ip="203.0.113.24",
),
)
prompt_for_model = result.prompt
llm_response = "Your final LLM response here"
ack = client.acknowledge(
enhancement_result=result,
llm_response=llm_response,
)
if ack is not None:
print(ack.ad_ack_id)
print(ack.status)
print(ack.success)
client.close()
The SDK integration flow has two main steps:
request_ad() or request_ad_async() to get an EnhancementResult.acknowledge() or
acknowledge_async() to close the ad cycle.EnhancementResult.prompt always gives you the prompt your application should
use next:
request_ad() and request_ad_async() require an AdRequestContext with:
session_iduser_agentuser_ipfrom adstractai.models import AdRequestContext
context = AdRequestContext(
session_id="sess-1",
user_agent="Mozilla/5.0 (X11; Linux x86_64)",
user_ip="203.0.113.24",
)
Missing required values raise MissingParameterError, or are captured in
EnhancementResult.error when raise_exception=False.
Pass OptionalContext to include optional targeting signals.
from adstractai import Adstract, AdRequestContext, OptionalContext
client = Adstract(api_key="adpk_live_123")
result = client.request_ad(
prompt="How do I improve analytics in my LLM app?",
context=AdRequestContext(
session_id="sess-1",
user_agent="Mozilla/5.0 (X11; Linux x86_64)",
user_ip="203.0.113.24",
),
optional_context=OptionalContext(
country="US",
region="California",
city="San Francisco",
asn=15169,
age=30,
gender="female",
),
)
Validation rules:
| Field | Rule |
|---|---|
age | Integer between 0 and 120 |
gender | One of "male", "female", "other" |
country | ISO 3166-1 alpha-2 code such as "US" |
request_ad() and request_ad_async() return EnhancementResult.
Important fields:
prompt: the prompt your application should pass to the modelsession_id: the request session identifierad_response: parsed backend response when availablesuccess: whether ad enhancement succeedederror: captured failure when raise_exception=Falseif result.success:
prompt_for_model = result.prompt
else:
print(result.error)
prompt_for_model = result.prompt
acknowledge() and acknowledge_async() return AdAckResponse on successful
acknowledgment.
AdAckResponse includes:
ad_ack_idstatussuccesssuccess means the acknowledgment itself completed successfully:
status="ok" -> success=Truestatus="no_ad_used" -> success=Truestatus="recoverable_error" -> success=FalseIf enhancement_result.success is False, acknowledgment is skipped and the
method returns None.
By default, SDK methods raise on failure.
request_ad(..., raise_exception=True)acknowledge(..., raise_exception=True)Set raise_exception=False if you want a fallback-first integration flow.
from adstractai.errors import (
AdEnhancementError,
AuthenticationError,
DuplicateAdRequestError,
NoFillError,
PromptRejectedError,
)
result = client.request_ad(
prompt="My prompt",
context=context,
raise_exception=False,
)
if result.success:
print(result.prompt)
elif isinstance(result.error, PromptRejectedError):
print("Prompt not suitable for ad injection")
elif isinstance(result.error, NoFillError):
print("No ad inventory available")
elif isinstance(result.error, DuplicateAdRequestError):
print("This message already has an ad request")
elif isinstance(result.error, AuthenticationError):
print("Authentication failed")
elif isinstance(result.error, AdEnhancementError):
print(result.error)
from adstractai.errors import (
AdResponseNotFoundError,
AuthenticationError,
DuplicateAcknowledgmentError,
UnsuccessfulAdResponseError,
)
try:
ack = client.acknowledge(
enhancement_result=result,
llm_response="Final response",
)
except AuthenticationError:
print("Authentication failed")
except AdResponseNotFoundError:
print("The ad response was not found")
except UnsuccessfulAdResponseError:
print("The ad response was not created by a successful enhancement")
except DuplicateAcknowledgmentError:
print("This response was already acknowledged")
Control how ads are wrapped in the enhanced prompt. The default is "xml".
client = Adstract(api_key="adpk_live_123", wrapping_type="markdown")
Supported values:
"xml""plain""markdown"import asyncio
from adstractai import Adstract, AdRequestContext
async def main() -> None:
client = Adstract(api_key="adpk_live_123")
result = await client.request_ad_async(
prompt="Need performance tips",
context=AdRequestContext(
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"
),
user_ip="192.0.2.1",
),
)
llm_response = "Your final LLM response here"
ack = await client.acknowledge_async(
enhancement_result=result,
llm_response=llm_response,
)
if ack is not None:
print(ack.ad_ack_id)
await client.aclose()
asyncio.run(main())
| Method | Description |
|---|---|
request_ad() | Request ad enhancement synchronously |
request_ad_async() | Request ad enhancement asynchronously |
acknowledge() | Report the final LLM response and return AdAckResponse |
acknowledge_async() | Async acknowledgment flow returning AdAckResponse |
close() | Close the owned sync HTTP client |
aclose() | Close the owned async HTTP client |
This SDK is distributed under the Adstract SDK Proprietary License. See LICENSE.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 1.0.1 | 17 Mar 2026 | 7 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 20 Oct, 19:54 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:c5e7dc8faa143172a413eb674e3d636fae6d8a1de86f29ce0b00c3f4361e2bc5