Collect prompt answers and poll a run
Start a collection for saved prompts, then check its progress and read the result.
Prepare the request
Set AEO_API_BASE_URL to https://api.aeoapi.dev and load AEO_API_KEY from your secret store. You need a brand ID, at least one saved prompt for that brand, and access to that brand. The key needs account:read to list sources, collections:write to start the run, and collections:read to poll it. Starting a collection also requires an editor, owner, or service role. The polling example uses Python 3 to read JSON.
If you need a brand and prompts, use the brand setup request to create them together.
List the sources available to your account with GET /v2/account and view=sources.
curl --fail-with-body --get "$AEO_API_BASE_URL/v2/account" \
-H "Authorization: Bearer $AEO_API_KEY" \
--data-urlencode "view=sources"Save a JSON object as collection.json with these fields:
workflowset tocollect.brand_idand the saved question IDs in theprompt_idsarray.marketwithcountryandlanguage. Use the market you want to measure.sourceswith at least one supportedplatformandmodepair.max_unitsset to the most credits you authorize for this request.- Optional
answer_mode. Use standard for the normal answer or new to request a new answer. The default isstandard.
See the v2 OpenAPI contract for the request schema. Collection can consume credits.
Collect for business locations
Add locations to your brand using the brand create or brand update operation. For a collection, pass one or more unique UUIDs in location_ids, or set all_locations: true to use every location on the brand.
Local results include answers from tools that support the selected location. To allow country-level answers when a tool cannot target the location, set allow_country_level: true. Report country-level answers separately. See how to compare locations.
A managed estimate requires an approved prompt set for the brand. Use a key with prompts:write to approve the set with PATCH /v2/prompts. Pass brand_id in the query and send an Idempotency-Key header. If you estimate for a website, pass the same saved domain as website in the approval query and estimate body.
Replace the example IDs and versions with the saved prompt IDs and their current versions. For a first approval, omit previous_revision.
{
"action": "set",
"prompts": [
{"prompt_id": "00000000-0000-4000-8000-000000000004", "version": 1},
{"prompt_id": "00000000-0000-4000-8000-000000000005", "version": 2}
]
}To update an approved set, use a key with prompts:read to call GET /v2/prompts?view=sets with the same brand_id and website if you set one. Send the returned data.prompt_set_revision as previous_revision in the approval body with the full list of prompts you want to approve.
Send POST /v2/runs with workflow: "managed", estimate: true, brand_id, market, and an Idempotency-Key header. Set MANAGED_ESTIMATE_KEY to a new key for this estimate. Replace the example brand ID, website, and the two location IDs with your saved values for Chicago and Boston. The example sets answer_mode to new. If you omit it, the API uses standard.
curl --fail-with-body "$AEO_API_BASE_URL/v2/runs" \
-H "Authorization: Bearer $AEO_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $MANAGED_ESTIMATE_KEY" \
--data-binary @- <<'JSON'
{
"workflow": "managed",
"estimate": true,
"brand_id": "00000000-0000-4000-8000-000000000001",
"website": "example.com",
"market": {"country": "US", "language": "en"},
"location_ids": [
"00000000-0000-4000-8000-000000000002",
"00000000-0000-4000-8000-000000000003"
],
"sources": [
{"platform": "google", "mode": "ai_overview"},
{"platform": "google", "mode": "ai_mode"}
],
"answer_mode": "new"
}
JSONRead data.eligible_engines for the sources eligible in every selected location. Use data.location_totals to see the prompt count, estimated and maximum credits, and eligible sources for each location. If a source cannot target Boston, data.excluded_sources names the source and Boston's location_id with reason location_not_supported. The source is left out of the whole combined run.
Start the run only if data.eligible_engines contains at least one source. If it is empty, request a new estimate with sources and locations that work together. If you change the sources or locations, generate a new MANAGED_ESTIMATE_KEY for the Idempotency-Key header. Sending a changed request with the same key returns HTTP 409.
Check data.expires_at before starting. If the estimate has expired, request a new one with a new MANAGED_ESTIMATE_KEY, even if the inputs are the same. Sending the same request with the original key can return the expired estimate. Starting with an expired estimate returns HTTP 409. If the start returns HTTP 409 and says the estimate expired, request a new estimate with a new key and use its new fingerprint, even if the original expires_at has not passed.
Send POST /v2/runs with a new Idempotency-Key and the body below. Use the same brand ID and replace the placeholders with data.estimate_fingerprint and data.prompt_set_revision from the estimate. The run uses the answer mode and locations from the estimate. If you use curl, add --dump-header managed-start.headers to save the response headers for the polling example.
{
"workflow": "managed",
"brand_id": "00000000-0000-4000-8000-000000000001",
"estimate_fingerprint": "<estimate_fingerprint>",
"prompt_set_revision": "<prompt_set_revision>"
}When the start returns HTTP 202, send an authenticated GET to the path in the Location response header on the same API origin. Read data.status for the run status and data.progress.by_location for expected and completed steps and the counts by source for each location. See the managed run polling example.
Find questions to track
Use POST /v2/prompts with action=build, the brand ID, location_id, and local_intent: true to suggest questions for a saved location. For web-based suggestions, use action=generate with method=web. Review the suggestions before saving the questions you want to track.
Start a collection
Use POST /v2/runs with workflow=collect. Set COLLECTION_REQUEST_KEY to a new value for this collection. When you retry, send the same key and request body. On success, use the response in accepted.json. If curl reports an HTTP error, check the response before polling.
curl --fail-with-body "$AEO_API_BASE_URL/v2/runs" \
-H "Authorization: Bearer $AEO_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $COLLECTION_REQUEST_KEY" \
--data-binary @collection.json \
--output accepted.jsonPoll the run
Poll a managed run
Use the Location header saved in managed-start.headers. The command sends your key in the Authorization header and prints the response with data.status and, for runs with selected locations, data.progress.by_location.
(
POLL_PATH=$(awk 'tolower($1) == "location:" { sub(/\r$/, "", $2); print $2 }' managed-start.headers)
case "$POLL_PATH" in
/v2/runs/managed:*) ;;
*) printf 'Missing or unexpected managed run path\n' >&2; exit 1 ;;
esac
curl --fail-with-body --get "$AEO_API_BASE_URL$POLL_PATH" \
-H "Authorization: Bearer $AEO_API_KEY"
)Wait between requests. Stop polling when data.status is completed, partial, failed, cancelled, or rejected. If data.report_url is present and is not null, send an authenticated GET to that path on the same API origin to read the report. Use a key with analytics:read and access to the brand. A key without it can poll the run but gets HTTP 403 on the report.
Poll a collection
Read data.poll_url from the accepted response and follow it with GET /v2/runs/{run_id}. If you build the URL yourself, use the returned data.id, including its job: prefix. The start and poll responses return the same ID in data.id and data.v2_run_id. Send your key only to the same API origin. This command saves the latest status.
(
POLL_URL=$(python3 -c 'import json, sys; print(json.load(sys.stdin)["data"]["poll_url"])' < accepted.json)
case "$POLL_URL" in
/v2/runs/*) POLL_URL="$AEO_API_BASE_URL$POLL_URL" ;;
"$AEO_API_BASE_URL"/v2/runs/*) ;;
*) printf 'Unexpected poll URL\n' >&2; exit 1 ;;
esac
curl --fail-with-body "$POLL_URL" \
-H "Authorization: Bearer $AEO_API_KEY" \
--output collection-status.json
)Wait between requests. Keep polling until data.state is completed, partial, failed, or cancelled.
Read the collection result
Read the saved GET /v2/runs/{run_id} response to check the outcome.
python3 -c 'import json, sys; run = json.load(sys.stdin)["data"]; print(json.dumps({"state": run["state"], "result": run["result"], "error": run["error"]}, indent=2))' < collection-status.jsonWhen the state is completed, read data.result for the accepted and failed counts and the observation IDs. If the state is partial, keep the incomplete result separate from completed collections. If the state is failed or cancelled, inspect data.error when present before retrying.