---
title: Live Queries
description: Collect a fresh batch from platforms now. Create a query, wait for each platform, then page through the results.
type: guide
status: stable
updated: 2026-12-03
url: /en/docs/live-query
markdown: /en/docs/live-query.md
---

Read as needed; not a required onboarding step. Path：[Data Access Path](/en/docs)

# 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](/en/docs/search) instead. To read existing user profiles, use [browse](/en/docs/browse#users).

The whole process is asynchronous:


```mermaid
sequenceDiagram
  participant App as Your program
  participant API as MarsYoo API
  App->>API: Create a live query
  API-->>App: 202 + query ID
  App->>API: Poll status
  API-->>App: Progress per platform
  App->>API: Read results when all finish
  API-->>App: Documents + page cursor
```


## Before you start [#before]

- 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](#billing).

## Create a query [#create]

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.

| 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](#time-range) |
| `conditions` | No | Location, price, rating and other conditions; see [collection conditions](#conditions) |

`max_items` is a ceiling, not a guarantee.

### Idempotency-Key [#idempotency]

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 [#poll]


```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 [#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 [#versions]

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:

| 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](/en/docs/documents#versions-batch), or use `GET /v1/documents/{id}/content?version_id=ver_...`.

## Cancel a query [#cancel]


```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 [#time-range]

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]

`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_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_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 [#platforms]

### X [#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 [#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 [#billing]

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:

| 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 [#errors]

- 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](/en/docs/errors). All parameters: [API reference](/en/public-api-reference).

You can also try it in the [Playground](/en/portal/playground) by switching to **Live**. This creates a real query and uses credits.

## Continue Your Task

[Return to the integration path](/en/docs); return to your task after consulting this reference.
