Live Queries
A live query asks MarsYoo to collect a fresh batch from platforms right now. By the end of this page you can create one, wait for it to finish and read the results.
For data that’s already stored, use keyword search instead. To read existing user profiles, use browse.
The whole process is asynchronous:
Before you start
- Your application’s access must include live queries and the target platforms. Check the application’s “Access limits” page in the console.
- Live queries use credits; see credits and limits.
Create a query
Collect English videos about “AI agent” from YouTube and Weibo, up to 20 per platform:
LIVE_QUERY_ID=$(curl -sS "$WHALE_BASE_URL/v1/live-queries" \
-H "Authorization: Bearer $WHALE_API_KEY" \
-H "Idempotency-Key: product-search-20260909-001" \
-H "Content-Type: application/json" \
--data '{
"resource_kind": "video",
"query": "AI agent",
"source_platforms": ["youtube", "weibo"],
"language": "en",
"max_items": 20,
"deadline_seconds": 300
}' | jq -er '.live_query.id')You get 202 and the query ID:
{
"live_query": {"id": "lq_01K4...", "status": "pending", "resource_kind": "video"},
"runs": [{"source_platform": "youtube", "collection_task_id": "ctask_01K4...", "status": "pending"}]
}202 only means accepted; collection isn’t done yet.
| Parameter | Required | Meaning |
|---|---|---|
resource_kind | Yes | What to collect: content, account, user, channel or video. Not every platform supports every kind |
query, url, external_id | At least one | A keyword, a target link or an ID on the platform |
source_platforms | Yes | 1 to 5 platforms |
max_items | No | Up to how many per platform, 1 to 100, default 20 |
deadline_seconds | No | Collection deadline, 10 to 900 seconds, default 300 |
language, region | No | Narrow the scope where the platform supports it |
published_from, published_to | No | Only content published in this window; see collect by publish time |
conditions | No | Location, price, rating and other conditions; see collection conditions |
max_items is a ceiling, not a guarantee.
Idempotency-Key
Every create request needs an Idempotency-Key header:
- After a network timeout, retry with the same value. You get the original query back, with no duplicate query and no double charge. Replays return
200. - For a new query, use a new value. The same value with different parameters returns
409 idempotency_key_conflict.
Wait for it to finish
curl -sS "$WHALE_BASE_URL/v1/live-queries/$LIVE_QUERY_ID" \
-H "Authorization: Bearer $WHALE_API_KEY"Returns the overall status and one entry per platform in runs[]. Each run has its own status, last_error and result.
Statuses: pending, collecting, partial, succeeded, failed, canceled.
To decide whether it’s finished, check every platform run:
- While any run is
pendingorcollecting, keep waiting, even if the overall status ispartial. - Once all finish,
succeededmeans all succeeded andpartialmeans some did. - Check
last_errorfor each failed run. A failure isn’t the same as “no matching content”. - A run can succeed without reaching
max_itemsby the deadline.
Start polling at 2 seconds and back off. Don’t poll the same query concurrently.
The deadline live_query.deadline_at counts from creation; queuing and retries don’t extend it.
Read the results
When everything has finished:
curl -sS "$WHALE_BASE_URL/v1/live-queries/$LIVE_QUERY_ID/results?limit=20" \
-H "Authorization: Bearer $WHALE_API_KEY"- Returns
itemsand an optionalnext_cursor. When there’s anext_cursor, pass it to read the next page;limitis 1 to 100. - Before completion you get
409 live_query_results_not_ready. Keep waiting on the same query; don’t create a new one. - Results are filtered by the application’s field access.
- Subtitles, metrics and analysis results may arrive after the body.
Read the version collected at the time
For newly completed queries, each run’s result.document_versions lists the documents and versions written by this query:
"document_versions": [{"document_id": "doc_...", "version_id": "ver_..."}]version_binding in the results endpoint:
| Value | Meaning |
|---|---|
pinned | Body, parts and facts come from the version collected by this query. Title and metadata are the document’s latest |
legacy_current | Older queries didn’t record versions, so only current content is available |
For the exact body as collected, pass the versions to read several versions at once, or use GET /v1/documents/{id}/content?version_id=ver_....
Cancel a query
curl -sS -X POST "$WHALE_BASE_URL/v1/live-queries/$LIVE_QUERY_ID/cancel" \
-H "Authorization: Bearer $WHALE_API_KEY"Runs that haven’t started are canceled immediately; running ones are asked to stop, so keep checking the final status. Documents already stored aren’t deleted.
Collect by publish time
Use published_from and published_to (RFC 3339) to collect only content published in a window:
- No earlier than 7 days ago and not later than now.
- If you pass only one, the other is filled in: the start becomes 7 days before the end, and the end becomes now.
- If the platform can’t filter by publish time, you get
400 live_query_invalid.
Collection conditions
conditions describe what to collect, such as within 5 km, rated 4 or higher, or priced between 10 and 100 USD:
"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}; radius is an integer from 1 to 50000 (meters) |
price, salary, rating, inventory | gte, lte, between | A number; between takes [min, max] |
Others, such as category, brand, tag | eq, in | Text of 1 to 300 characters; in takes 1 to 50 texts |
- Up to 10 conditions. Each
fact_typeplusnamecan appear only once. - If a platform doesn’t support a condition, creation fails instead of silently ignoring it.
- Conditions are saved with the query and returned in
live_query.conditionswhen you poll.
Platform notes
X
Set source_platforms to ["x"] and pick one kind of target per query:
| Target | resource_kind | Parameters |
|---|---|---|
| Latest posts for a search | content | "query": "OpenAI", "language": "en" |
| One post | content | "url": "https://x.com/OpenAI/status/TWEET_ID" or "external_id": "TWEET_ID" |
| An account’s original posts | account | "query": "OpenAI" or "url": "https://x.com/OpenAI" |
| A list timeline | channel | "url": "https://x.com/i/lists/LIST_ID" or "external_id": "LIST_ID" |
- Use the username or profile link for accounts; numeric IDs aren’t supported.
- Video queries and location conditions aren’t supported. Such failures don’t mean there was no matching content.
- Posts have no title; show the body instead.
- Being able to read X data doesn’t mean X live queries are enabled for you.
Google Trends
With source_platforms set to ["google_trends"], one query returns one document: a search-interest curve. max_items doesn’t mean 20 documents.
For example, OpenAI returns OpenAI — interest over time, with relative interest (0 to 100, not search counts) at each point. 90 days gives about 90 points.
| Field | Meaning |
|---|---|
runs[].result.collection_coverage.entity_unit | Always trend_series |
runs[].result.collection_coverage.point_count | Number of points |
platform_payload.record.response_extensions.keyword_trends.points | Time, value and partial flag for each point |
platform_payload.record.response_extensions.keyword_trends.measurement | The measure, usually relative_interest_index_0_100 |
Related topics and related queries aren’t guaranteed.
Credits and limits
How you’re charged:
- At creation, credits are reserved per platform based on
max_items. - On success or partial success, you’re charged for the documents actually returned; the rest is refunded.
- On failure, cancellation or failed dispatch, everything is refunded.
Requests are rejected when credits are insufficient. Details are in the console’s application usage and credit history.
Your application’s access can set these limits:
| Setting | Meaning |
|---|---|
live_query_enabled | Whether live queries are enabled |
live_query_daily_limit | Items that can be reserved per day |
live_query_max_items | Items per platform per query |
live_query_max_concurrency | Queries in progress at once |
When both organization and application set a limit, the stricter one applies.
When something fails
- A platform not yet open returns
409 platform_dataset_route_missing. - Don’t send
dataset_id; storage is managed by the platform. - Rate limiting returns
429withRetry-After: 1; lower concurrency and retry.
Other errors: Error codes. All parameters: API reference.
You can also try it in the Playground by switching to Live. This creates a real query and uses credits.