Ad Injection
The Ad Injection endpoint is the core of the Adstract API. It accepts a user
prompt and request context, then returns an enhanced prompt with ad instructions
embedded. This is the direct HTTP equivalent of the SDK's request_ad method.
Endpoint
POST https://api.adstract.ai/api/ad-injection/start/
Authentication
All requests must include your API key in the X-Adstract-API-Key header.
See Authentication for full details.
Minimal request
The minimum viable request includes prompt and request_context:
For the complete payload shape, including request_configuration and
optional_context, see Enhancement Request Body.
- JavaScript
- Python
- cURL
const response = await fetch("https://api.adstract.ai/api/ad-injection/start/", {
method: "POST",
headers: {
"X-Adstract-API-Key": "your-api-key",
"Content-Type": "application/json",
},
body: JSON.stringify({
prompt: "What are some good ways to advertise with AI?",
request_context: {
session_id: "session_001",
user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
user_ip: "203.0.113.24",
},
}),
});
import httpx
response = httpx.post(
"https://api.adstract.ai/api/ad-injection/start/",
headers={
"X-Adstract-API-Key": "your-api-key",
"Content-Type": "application/json",
},
json={
"prompt": "What are some good ways to advertise with AI?",
"request_context": {
"session_id": "session_001",
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
"user_ip": "203.0.113.24",
},
},
)
curl https://api.adstract.ai/api/ad-injection/start/ \
-H "X-Adstract-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"prompt": "What are some good ways to advertise with AI?",
"request_context": {
"session_id": "session_001",
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
"user_ip": "203.0.113.24"
}
}'
Full request
- JavaScript
- Python
- cURL
const response = await fetch("https://api.adstract.ai/api/ad-injection/start/", {
method: "POST",
headers: {
"X-Adstract-API-Key": "your-api-key",
"Content-Type": "application/json",
},
body: JSON.stringify({
prompt: "What are some good ways to advertise with AI?",
request_context: {
session_id: "session_001",
user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
user_ip: "203.0.113.24",
},
request_configuration: {
wrapping_type: "xml",
},
optional_context: {
country: "US",
region: "California",
city: "San Francisco",
asn: 15169,
age: 21,
gender: "female",
},
}),
});
import httpx
response = httpx.post(
"https://api.adstract.ai/api/ad-injection/start/",
headers={
"X-Adstract-API-Key": "your-api-key",
"Content-Type": "application/json",
},
json={
"prompt": "What are some good ways to advertise with AI?",
"request_context": {
"session_id": "session_001",
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
"user_ip": "203.0.113.24",
},
"request_configuration": {
"wrapping_type": "xml",
},
"optional_context": {
"country": "US",
"region": "California",
"city": "San Francisco",
"asn": 15169,
"age": 21,
"gender": "female",
},
},
)
curl https://api.adstract.ai/api/ad-injection/start/ \
-H "X-Adstract-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"prompt": "What are some good ways to advertise with AI?",
"request_context": {
"session_id": "session_001",
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
"user_ip": "203.0.113.24"
},
"request_configuration": {
"wrapping_type": "xml"
},
"optional_context": {
"country": "US",
"region": "California",
"city": "San Francisco",
"asn": 15169,
"age": 21,
"gender": "female"
}
}'
Response
The response body has the same shape for all successful status codes. Check success to
determine whether enhanced_prompt is populated.
{
"ad_request_id": "55c59ce2-a31f-4ce4-95b3-f930fd9cd564",
"ad_response_id": "55c59ce2-a31f-4ce4-95b3-f930fd9cd564",
"status": "ok",
"success": true,
"execution_time_ms": 1987.964153289795,
"enhanced_prompt": "You are an AI assistant that integrates advertisements...",
"product_name": "Adstract – LLM Advertising"
}
enhanced_prompt and product_name are null when success is false.
See Enhancement Response Body for
the full field reference.
See Enhancement Status Codes for a full breakdown of every code.
Integration flow
- Send the user's prompt to this endpoint.
- Check the HTTP status code.
- On
200: passenhanced_promptto your LLM. - On
201or202: pass the original prompt to your LLM unchanged. - After your LLM responds, call the acknowledgment endpoint to close the ad cycle.
Next steps
- Enhancement Request Body — full field reference for the request payload.
- Enhancement Response Body — full field reference for the response payload.
- Ad Acknowledgment — closing the ad cycle after your LLM responds.
- Enhancement Status Codes — detailed breakdown of every HTTP status code returned by this endpoint.
- Authentication — API key setup and header details.