Download Markdown

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:

Bash
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:

JSON
{
  "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.

ParameterRequiredMeaning
resource_kindYesWhat to collect: content, account, user, channel or video. Not every platform supports every kind
query, url, external_idAt least oneA keyword, a target link or an ID on the platform
source_platformsYes1 to 5 platforms
max_itemsNoUp to how many per platform, 1 to 100, default 20
deadline_secondsNoCollection deadline, 10 to 900 seconds, default 300
language, regionNoNarrow the scope where the platform supports it
published_from, published_toNoOnly content published in this window; see collect by publish time
conditionsNoLocation, 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

Bash
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 pending or collecting, keep waiting, even if the overall status is partial.
  • Once all finish, succeeded means all succeeded and partial means some did.
  • Check last_error for each failed run. A failure isn’t the same as “no matching content”.
  • A run can succeed without reaching max_items by 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:

Bash
curl -sS "$WHALE_BASE_URL/v1/live-queries/$LIVE_QUERY_ID/results?limit=20" \
  -H "Authorization: Bearer $WHALE_API_KEY"
  • Returns items and an optional next_cursor. When there’s a next_cursor, pass it to read the next page; limit is 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:

JSON
"document_versions": [{"document_id": "doc_...", "version_id": "ver_..."}]

version_binding in the results endpoint:

ValueMeaning
pinnedBody, parts and facts come from the version collected by this query. Title and metadata are the document’s latest
legacy_currentOlder 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

Bash
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:

JSON
"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_typeopvalue
locationwithin{lat, lng, radius_m}; radius is an integer from 1 to 50000 (meters)
price, salary, rating, inventorygte, lte, betweenA number; between takes [min, max]
Others, such as category, brand, tageq, inText of 1 to 300 characters; in takes 1 to 50 texts
  • Up to 10 conditions. Each fact_type plus name can 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.conditions when you poll.

Platform notes

X

Set source_platforms to ["x"] and pick one kind of target per query:

Targetresource_kindParameters
Latest posts for a searchcontent"query": "OpenAI", "language": "en"
One postcontent"url": "https://x.com/OpenAI/status/TWEET_ID" or "external_id": "TWEET_ID"
An account’s original postsaccount"query": "OpenAI" or "url": "https://x.com/OpenAI"
A list timelinechannel"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.

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.

FieldMeaning
runs[].result.collection_coverage.entity_unitAlways trend_series
runs[].result.collection_coverage.point_countNumber of points
platform_payload.record.response_extensions.keyword_trends.pointsTime, value and partial flag for each point
platform_payload.record.response_extensions.keyword_trends.measurementThe measure, usually relative_interest_index_0_100

Related topics and related queries aren’t guaranteed.

Credits and limits

How you’re charged:

  1. At creation, credits are reserved per platform based on max_items.
  2. On success or partial success, you’re charged for the documents actually returned; the rest is refunded.
  3. 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:

SettingMeaning
live_query_enabledWhether live queries are enabled
live_query_daily_limitItems that can be reserved per day
live_query_max_itemsItems per platform per query
live_query_max_concurrencyQueries 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 429 with Retry-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.