Collect Data on Demand
Live queries request fresh source-platform data. They do not replace search: use search for indexed data and use a live query only to trigger new collection. Whale dispatches the request to a capable collector and ingests data asynchronously; it never proxies directly to a third-party platform or promises synchronous completion.
Prerequisites
Applications with no access-policy history inherit the platform default, which enables live queries for every platform. Once Whale saves an explicit application policy, that policy must allow the target platforms and set rate_limit_policy.live_query_enabled=true. Each target platform also needs an active collector registered for live_query and its required capabilities.
V1 supports content, account, user, channel, and video; availability depends on platform, collector capabilities and grants. A request accepts 1-5 platforms, up to 100 items per platform, and a deadline of up to 900 seconds. To read already-collected user profiles or content, use User APIs without creating a new task.
Create A Query
Idempotency-Key is required and must be stable. Reuse it for network retries so Whale returns the original query instead of creating duplicate tasks. Reusing a key with different parameters (kind, query, URL, external ID, platforms, language, region, item count, or conditions) returns 409 idempotency_key_conflict; use a new key for a new request.
live_response="$(curl -sS --fail-with-body -X POST "$WHALE_BASE_URL/v1/live-queries" \
-H "Authorization: Bearer $WHALE_API_KEY" \
-H "Idempotency-Key: product-search-20260909-001" \
-H "Content-Type: application/json" \
-d '{
"resource_kind":"video",
"query":"AI agent",
"source_platforms":["youtube","weibo"],
"language":"en",
"max_items":20,
"deadline_seconds":300
}')"
printf '%s' "$live_response" | jq .
LIVE_QUERY_ID="$(printf '%s' "$live_response" | jq -er '.live_query.id')"| Field | Required | Description |
|---|---|---|
resource_kind | Yes | content, account, user, channel, or video; not all platforms support every kind. |
query / url / external_id | One | Keyword, target URL, or source ID. |
source_platforms | Yes | One to five target platforms. |
language / region | No | Narrow the request when supported. |
max_items | No | Per-platform maximum, 1-100; default 20. |
deadline_seconds | No | Wait limit, 10-900; default 300. |
conditions | No | Collection conditions, at most 10; see below. |
published_from / published_to | No | Collect only content published in this window, RFC 3339; it reaches back at most 7 days and cannot end in the future. With one edge given, the other is filled in (the start becomes 7 days before the end, the end becomes now). |
A publish-time window needs a collector for the platform that supports time ranges; otherwise creation returns 400 live_query_invalid and the message names the missing time_range capability. Content a collector returns outside the window is left out of the results endpoint.
Where collected content is stored is managed by the platform, so dataset_id is not needed. A value sent by older clients is still honored, but the field is being retired, so remove it; a platform not yet available returns 409 platform_dataset_route_missing.
max_items is a ceiling, not a guaranteed count. Most content platforms count content documents; some discovery platforms return aggregate objects. In particular, google_trends returns one trend-series document for a query, and that document contains many time points (for example, about 90 points for a 90-day window). max_items does not mean 20 articles or posts for Google Trends. Read the content/version payload and inspect collection_coverage.entity_unit=trend_series, point_count, and the trend points in platform_payload.
X Query Parameters
Use source_platforms: ["x"].
Select one target per request:
| Target | resource_kind | Example parameters |
|---|---|---|
| Latest posts by keyword | content | "query":"OpenAI", "language":"en" |
| Individual post | content | "url":"https://x.com/OpenAI/status/TWEET_ID" or "external_id":"TWEET_ID" |
| Original posts by account | account | "query":"OpenAI" or "url":"https://x.com/OpenAI" |
| List timeline | channel | "url":"https://x.com/i/lists/LIST_ID" or "external_id":"LIST_ID" |
Replace TWEET_ID and LIST_ID with real IDs. Account lookup accepts a username
or profile URL, not a numeric user ID. The current X executor does not support
video queries or location conditions; do not interpret those failures as empty
search results. X posts have no titles: use the body, and never fabricate titles.
Example keyword request:
curl -sS --fail-with-body -X POST "$WHALE_BASE_URL/v1/live-queries" \
-H "Authorization: Bearer $WHALE_API_KEY" \
-H "Idempotency-Key: x-openai-20261119-001" \
-H "Content-Type: application/json" \
-d '{"source_platforms":["x"],"resource_kind":"content","query":"OpenAI","language":"en","max_items":20,"deadline_seconds":300}'Then poll and read results as described below. Read access to X alone is not
enough: live collection also needs its feature flag, a capable collector and
available quota. Whale application quotas and the collector’s shared upstream
account limits and daily collection budget are independent. max_items is a
ceiling, not a guaranteed result count.
Google Trends Aggregate Results
When source_platforms contains ["google_trends"], the result unit is a trend series (trend_series), not a web page, article, or post. For example, querying OpenAI returns one document such as OpenAI — interest over time; the payload contains a relative search-interest time series where values are 0-100, not search counts.
Common fields:
| Field | Meaning |
|---|---|
runs[].result.collection_coverage.entity_unit | trend_series, meaning the run returned an aggregate series |
runs[].result.collection_coverage.point_count | Number of time points in the series |
platform_payload.record.response_extensions.keyword_trends.points | Timestamps, values, and partial flags for each point |
platform_payload.record.response_extensions.keyword_trends.measurement | Metric semantics, usually relative_interest_index_0_100 |
If you need related topics or related queries, those should be integrated as an additional collector capability and result type. Do not interpret max_items=20 as a requirement for Google Trends to return 20 documents.
Collection Conditions
conditions describe what to collect with the ingest fact types (fact_type), for example nearby results within a radius, a price range, or a minimum rating:
"conditions": [
{"fact_type":"location","name":"geo","op":"within","value":{"lat":1.29027,"lng":103.851959,"radius_m":5000}},
{"fact_type":"rating","name":"rating","op":"gte","value":4},
{"fact_type":"price","name":"price","op":"between","value":[10,100],"unit":"USD"}
]fact_type | op | value |
|---|---|---|
location | within | {lat, lng, radius_m}: latitude -90 to 90, longitude -180 to 180, radius an integer from 1 to 50000 meters |
price, salary, rating, inventory | gte, lte, between | A number; between takes [min, max] |
Other types (such as category, brand, tag) | eq, in | A single-line string of 1-300 characters; in takes a list of 1-50 strings |
Each fact_type and name pair may appear once; invalid conditions return 400 live_query_invalid. The query keeps the conditions and returns them as live_query.conditions when polled; language and region are kept and returned the same way.
Only collectors that declare the matching capability (such as condition:location) claim a task with that condition. When no online collector for a target platform declares it, creation fails instead of ignoring the condition.
A new request returns 202; an idempotent replay returns 200.
Poll And Read Results
curl -sS --fail-with-body "$WHALE_BASE_URL/v1/live-queries/$LIVE_QUERY_ID" \
-H "Authorization: Bearer $WHALE_API_KEY"Poll from a two-second interval with exponential backoff and never poll one query concurrently. Statuses are pending, collecting, partial, succeeded, failed, and canceled. Each runs[] item represents one platform and contains task status, last_error, and result.
Use the live-query result endpoint to read authorized documents. It applies the application’s field permissions, platform entitlements, and usage audit again:
curl -sS "$WHALE_BASE_URL/v1/live-queries/$LIVE_QUERY_ID/results?limit=20" \
-H "Authorization: Bearer $WHALE_API_KEY"The endpoint supports cursor and limit (1-100). It returns
409 live_query_results_not_ready while the query is pending or collecting.
Once ready, the response contains items, limit, and an optional opaque next_cursor;
the cursor can only be used with the same live query. runs[].result.document_ids remains
available for per-platform reconciliation and troubleshooting. Documents may become searchable
before the task ends. Transcripts, metrics, and analysis can arrive after primary content.
Credits, Limits, And Errors
Live queries reserve credits per platform run, using max_items as the reserved quantity.
When a run succeeds or partially succeeds, Whale settles against the number of returned
document_ids and automatically refunds unused units. Failed, canceled, and dispatch-failed
runs receive a full refund. Reusing the same Idempotency-Key from the same application does not
create another query or reserve credits again.
The access policy can configure the following live-query limits:
{
"live_query_enabled": true,
"live_query_daily_limit": 1000,
"live_query_max_items": 100,
"live_query_max_concurrency": 2
}live_query_daily_limit counts reserved item units, live_query_max_items limits each
platform run, and live_query_max_concurrency limits active queries for an application.
When organization and application policies both apply, the stricter scope and lower limit win.
curl -sS --fail-with-body -X POST "$WHALE_BASE_URL/v1/live-queries/$LIVE_QUERY_ID/cancel" \
-H "Authorization: Bearer $WHALE_API_KEY"Pending work is canceled immediately; running collectors receive a cancel signal. Already ingested documents remain. Creation uses the application’s real-time policy. 429 rate_limit_exceeded includes Retry-After: 1; lower concurrency before retrying. Scope denial returns 403, insufficient credits returns 402, invalid input returns 400 live_query_invalid, and requests outside the current application return 404 live_query_not_found.
Credit usage and refunds are visible in the application’s portal usage and credit ledger. See OpenAPI for the complete contract.