# How can I know what a social data job will cost before I run it?

> Estimate a Douyin or YouTube data job before spending: count the calls, price them from the public price book, cap the budget in code, check each charge.

Canonical page: https://okdata.online/answers/estimate-data-api-cost-before-running/

**Short answer: **Count the calls, then multiply by each endpoint's published price. A Douyin research job of 30 searches and 150 comment pages costs $0.90 on okdata: search is $0.02 a call and comments $0.002 a page. Per-call prices do not depend on how many items come back, so the estimate is also the most the job can cost.

Before a marketing lead signs off on a data pull, someone has to say what it will cost. With per-call pricing that is arithmetic, done in three steps.

## 1. Write the job as calls

A typical Douyin category study: 10 keywords, three pages of search each, then the comments on the top 30 videos, five pages per video.

| Step | Endpoint | Calls | Cost |
|---|---|---|---|
| Search | [Douyin video search](/apis/douyin/videos/search/) | 10 × 3 = 30 | $0.60 |
| Comments | [Douyin video comments](/apis/douyin/videos/comments/list/) | 30 × 5 = 150 | $0.30 |
| Total | | 180 | $0.90 |

The same shape on YouTube, using [YouTube video search](/apis/youtube/videos/search/), costs $0.12 for the search step.

## 2. Price it from the price book, then cap it in code

Every price is on the [pricing page](/pricing/), which also has a monthly cost calculator, and in machine-readable form at `https://okdata.online/prices.json`. Agents connected over [MCP](/mcp/) can call the free `describe` tool to read an endpoint's price before spending anything.

```python
import os, requests
from decimal import Decimal

book = requests.get("https://okdata.online/prices.json", timeout=30).json()
price = {e["id"]: Decimal(e["price"]) for e in book["endpoints"]}
plan = {"douyin.videos.search": 30, "douyin.videos.comments.list": 150}
estimate = sum(price[k] * n for k, n in plan.items())
print("estimate:", estimate, "USD")

BUDGET, spent = estimate, Decimal("0")
H = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}

def call(endpoint_path, **params):
    global spent
    if spent >= BUDGET:
        raise RuntimeError(f"budget reached: {spent} USD")
    body = requests.get(f"https://api.okdata.online{endpoint_path}", headers=H, params=params, timeout=60).json()
    if body["code"] != "ok":
        raise RuntimeError(f"{body['code']}: {body['message']}")
    spent += Decimal(body["meta"]["billing"]["amount"])
    return body

first_page = call("/v1/douyin/videos/search", query="露营装备")
```

## 3. Check the real charge as you go

Each response carries `meta.billing.amount` and `balance_after`. `GET https://api.okdata.online/v1/account` shows the balance at any time, and `GET https://api.okdata.online/v1/calls/{request_id}` shows what any single call cost.

## Why the estimate holds

- Per-call endpoints charge the same whether a page holds 20 items or 3, so fewer results never cost more.
- Before each call, the most it can cost is held from your balance. If the balance cannot cover it, the call is refused with `insufficient_balance`, free.
- The one per-item endpoint, [Official Account search](/apis/wechat_mp/accounts/search/), is capped at $0.58 per call.

What makes estimates drift is the plan, not the price: a keyword with fewer posts than expected stops early and costs less, and an agent told to keep going until it finds something can run long. Give agents a page limit as well as a budget.

## Endpoints used

- [Douyin video search](https://okdata.online/apis/douyin/videos/search/) `douyin.videos.search`: $0.02 per call · about 20 videos per page
- [Douyin video comments](https://okdata.online/apis/douyin/videos/comments/list/) `douyin.videos.comments.list`: $0.002 per call · about 20 comments per page
- [YouTube video search](https://okdata.online/apis/youtube/videos/search/) `youtube.videos.search`: $0.004 per call · about 20 videos per page

Updated 2026-11-12
