AdRequestContext
AdRequestContext is the request-level input object used when calling
the Adstract client. It defines the runtime context Adstract needs to build
a valid ad-enhancement request.
Class purpose
This class exists to carry request metadata that is required per call:
- conversation/session context;
- client identity context from the request origin; and
- network metadata used for analysis and reporting.
Class shape
- Python
from adstractai.models import AdRequestContext
config = AdRequestContext(
session_id="session-abc",
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.10",
)
Required fields
-
session_id- Type:
str - Purpose: Identifies the request session/conversation context.
- Why it matters:
- Adstract uses this value to resolve conversation tracking context for the request.
- Type:
-
user_agent- Type:
str - Purpose: Carries client application/browser identity information.
- Why it matters:
- Used to derive request metadata such as device/browser characteristics.
- Type:
-
user_ip- Type:
str - Purpose: Carries the client IP address.
- Why it matters:
- Used as part of metadata and reporting context in request processing.
- Type:
All three fields are required for a valid context object.
Validation behavior
AdRequestContextenforces a strict schema.- Unknown/extra fields are rejected.
- Missing required fields produce validation errors.
Usage with Adstract client
- Python
from adstractai import Adstract
from adstractai.models import AdRequestContext
client = Adstract(api_key="your-api-key")
config = AdRequestContext(
session_id="session-abc",
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.10",
)
result = client.request_ad(
prompt="How can I improve retention in my app?",
context=config,
)
Next steps
- Continue to Initialize Your Integration to begin execution with a configured client.
- Continue to Adstract Client for client-level runtime behavior.
- Continue to OptionalContext for optional ad targeting fields.
- Continue to EnhancementResult for output handling.
- Continue to Exception for validation and runtime error behavior.