ナビゲーションにスキップ

Social media API responses are too large and burn AI tokens: how to cut context cost

Markdownとして表示

A single raw social media API page can carry 30,000–60,000 tokens of CDN image mirrors, avatar hashes, and tracking metadata that an LLM does not need. Passing raw JSON straight into Claude or GPT wastes context budget and slows every turn.

With BeatAPI, three built-in patterns reduce token consumption by 70–90% while keeping full payloads accessible on demand.

1. Use BeatAPI MCP’s automatic preview and free 1-hour read-back

When your AI agent calls any social action through BeatAPI remote MCP (https://beatapi.io/mcp), BeatAPI returns a compact preview for large responses instead of injecting the entire JSON blob into chat context.

  • Review the preview first to confirm you pulled the right video, account, or keyword.
  • If you need the full payload, call capabilities_run with operation: "result" and the returned request_id within 1 hour. Reading the stored result costs $0 and does not trigger another platform call.

See Capabilities API for the exact operation: "result" contract.

2. Pass raw: false on endpoints that support simplified payloads

Several BeatAPI actions accept raw: false to return a clean, flattened structure instead of nested platform wrappers:

  • wechat_mp.v2.fetch_account_articles (raw: false): returns flat data.articles[] with just app_msg_id, idx, title, digest, url, create_time, and update_time.
  • wechat_channels.v2.fetch_video_comments (raw: false): returns clean data.comments[], data.down_continue, and data.last_buffer.

Check whether an action supports raw: false anytime using free POST /v1/capabilities/inspect.

3. Strip unused fields in 10 lines of Python before calling an LLM

For automated scripts and n8n/Python pipelines calling POST /v1/social-data/call directly, save the raw JSON to disk for archival, and pass only 4–5 fields per item into your LLM prompt:

import json
raw = json.load(open("wechat-articles-page-1.json", encoding="utf-8"))
slim = [
{"title": a.get("title"), "digest": a.get("digest"), "url": a.get("url")}
for a in raw.get("data", {}).get("articles", [])
]
# Feed `slim` to Claude/GPT — typically 10x–20x fewer tokens than raw JSON
print(json.dumps(slim, ensure_ascii=False)[:500])

Because BeatAPI serves both social data actions and 70+ text models (including lower-cost summarizers like deepseek-v4.1-flash and gemini-3.8-flash) on one USD balance, you can run bulk extraction with a smaller model first and reserve flagship models for final synthesis.