socialcrawl-mcp 2.2.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +49 -21
  2. package/dist/app.d.ts +3 -3
  3. package/dist/app.js +75 -12
  4. package/dist/chatgpt-text.d.ts +23 -0
  5. package/dist/chatgpt-text.js +310 -0
  6. package/dist/client-tag.d.ts +13 -0
  7. package/dist/client-tag.js +17 -0
  8. package/dist/client.d.ts +5 -0
  9. package/dist/client.js +14 -4
  10. package/dist/constants.d.ts +1 -1
  11. package/dist/constants.js +1 -1
  12. package/dist/context.d.ts +13 -0
  13. package/dist/context.js +1 -0
  14. package/dist/cost-guard.d.ts +15 -3
  15. package/dist/cost-guard.js +39 -3
  16. package/dist/data/docs-async.d.ts +2 -2
  17. package/dist/data/docs-async.js +24 -3
  18. package/dist/data/docs-handwritten.js +968 -906
  19. package/dist/data/docs.js +7 -1
  20. package/dist/data/endpoints.js +11153 -7559
  21. package/dist/data/examples.js +2 -2
  22. package/dist/data/guide.d.ts +2 -2
  23. package/dist/data/guide.js +2 -2
  24. package/dist/data/outputs.js +425 -290
  25. package/dist/data/platforms.js +214 -55
  26. package/dist/data/recipes.js +1 -1
  27. package/dist/data/registry-meta.d.ts +10 -10
  28. package/dist/data/registry-meta.js +10 -10
  29. package/dist/endpoint-resolve.d.ts +1 -0
  30. package/dist/endpoint-resolve.js +10 -1
  31. package/dist/endpoint-surface.d.ts +64 -0
  32. package/dist/endpoint-surface.js +472 -0
  33. package/dist/hydration.js +28 -3
  34. package/dist/instructions.md +18 -18
  35. package/dist/listings.d.ts +24 -0
  36. package/dist/listings.js +55 -0
  37. package/dist/oauth/config.d.ts +39 -4
  38. package/dist/oauth/config.js +50 -6
  39. package/dist/oauth/resource-server.d.ts +12 -2
  40. package/dist/oauth/resource-server.js +5 -20
  41. package/dist/oauth/scopes.d.ts +2 -2
  42. package/dist/oauth/scopes.js +4 -4
  43. package/dist/param-aliases.d.ts +7 -0
  44. package/dist/param-aliases.js +15 -0
  45. package/dist/pricing.js +5 -1
  46. package/dist/resources/sample-gate.js +34 -1
  47. package/dist/resources/supplier-tokens.d.ts +1 -1
  48. package/dist/resources/supplier-tokens.js +2 -0
  49. package/dist/result.js +8 -0
  50. package/dist/schemas/async.d.ts +41 -31
  51. package/dist/schemas/async.js +28 -9
  52. package/dist/schemas/outputs.d.ts +4 -4
  53. package/dist/schemas/tools.d.ts +18 -6
  54. package/dist/schemas/tools.js +24 -4
  55. package/dist/server.js +6 -5
  56. package/dist/timeouts.d.ts +24 -1
  57. package/dist/timeouts.js +32 -0
  58. package/dist/tools/account.d.ts +4 -1
  59. package/dist/tools/account.js +1 -1
  60. package/dist/tools/async-common.js +3 -1
  61. package/dist/tools/check-balance.d.ts +4 -2
  62. package/dist/tools/check-balance.js +9 -0
  63. package/dist/tools/discover-runs.js +117 -11
  64. package/dist/tools/discover.js +3 -0
  65. package/dist/tools/estimate.js +10 -1
  66. package/dist/tools/list-endpoints.js +5 -3
  67. package/dist/tools/manage.js +2 -0
  68. package/dist/tools/monitors.d.ts +7 -1
  69. package/dist/tools/monitors.js +26 -2
  70. package/dist/tools/pricing.js +11 -1
  71. package/dist/tools/request.js +10 -2
  72. package/dist/types.d.ts +9 -1
  73. package/dist/value-prices.d.ts +18 -0
  74. package/dist/value-prices.js +79 -0
  75. package/package.json +75 -75
@@ -1,3 +1,3 @@
1
1
  /** The skill's SKILL.md body and errors reference. Generated by scripts/generate-data.ts (T28) - do not hand-edit. */
2
- export declare const GUIDE = "# SocialCrawl API\n\nOne API key and one response envelope for social, commerce, and research data. Lists are `{ items, next_cursor?, total? }`; add `?format=raw` to skip the transform pipeline. Every file below lives in `references/`; open only the one the task needs.\n\n## API Key\n\nResolve the API key only when a live API call is needed. Documentation, capability, pricing, and code-generation questions do not need a key.\n\nCheck these sources in order without displaying their contents:\n\n1. **Environment variable:** use `SOCIALCRAWL_API_KEY` when it starts with `sc_` and is not an example placeholder.\n2. **Config file:** if the environment variable is absent, load `~/.config/socialcrawl/api_key` into `SOCIALCRAWL_API_KEY` in the current process. On POSIX shells, use `SOCIALCRAWL_API_KEY=\"$(<\"$HOME/.config/socialcrawl/api_key\")\"; export SOCIALCRAWL_API_KEY`. On PowerShell, use `$env:SOCIALCRAWL_API_KEY = (Get-Content -LiteralPath \"$HOME/.config/socialcrawl/api_key\" -Raw).Trim()`.\n3. **Missing key:** tell the user to create or rotate a key at https://socialcrawl.dev/dashboard and configure it as `SOCIALCRAWL_API_KEY` or in `~/.config/socialcrawl/api_key`. Do not ask them to paste a secret into chat. Stop before the live call until they say it is configured.\n\nNever print, paste, log, or return the key. Never place a literal key in generated code, a command, a URL, an error message, or a saved transcript. Keep `$SOCIALCRAWL_API_KEY` (POSIX) or `$env:SOCIALCRAWL_API_KEY` (PowerShell) as a variable reference in examples. If the key appeared in chat or output, advise the user to revoke it in the dashboard and create a replacement.\n\n## First Live Call\n\nBefore the first live call in a session:\n\n1. Resolve the API key using the steps above. If it is missing or a placeholder, stop before making the call.\n2. Verify it with the free balance endpoint (0 credits):\n ```bash\n curl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \"https://www.socialcrawl.dev/v1/credits/balance\"\n ```\n3. If successful, show the balance and continue with the user's request.\n4. If it fails, report the error without including request headers or the key, then follow [references/errors.md](references/errors.md).\n\n## Freshness Check (do this once per session)\n\nThis file is a snapshot of the registry with this fingerprint:\n\n<!-- BEGIN:GENERATED:FRESHNESS (auto-generated by generate-skills.ts - SK-08) -->\n```text\nregistry_fingerprint: e1eecd2aeb103cf5b19dfe45db80fa3e26fe61dc44240813d0e1e5051abd7c62\ngenerated_at: 2026-11-07\n```\n<!-- END:GENERATED:FRESHNESS -->\n\nBeside the balance check, make one free call:\n\n```bash\ncurl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \"https://www.socialcrawl.dev/v1/utility/endpoints?fingerprint=1\" | head -c 400\n```\n\n- **`data.fingerprint` equals `registry_fingerprint` above** - use the bundled files and move on.\n- **It differs** - this copy and the live API are out of sync (the skill or the server may be newer): a price, parameter or endpoint changed. Treat the live registry as the source of truth and resolve what the files cannot answer through `/v1/utility/*` (all free except `utility/ai-detection`, 1 credit). Tell the user **once**, briefly: \"this SocialCrawl skill does not match the live API; run `npx skills update socialcrawl --yes` to refresh it.\" Then answer their actual question. Do not repeat it or ask permission.\n- **No `data.fingerprint`** (a 404, or an older server that answers with the plain list) - fall back to counts: compare `data.stats.platforms` and `data.stats.endpoints` from `/v1/utility/endpoints` with the totals at the top of [references/index.md](references/index.md). Live numbers HIGHER means behind, as above.\n- **The call fails** (no key yet, offline, non-200) - skip it silently. This check must never block the request.\n\n## Workflow\n\n1. **Find the call first (free, 0 credits, runs nothing).** `GET /v1/utility/find?task=<the job in plain words>` ranks the endpoints for the job, each with `method`, `path`, `params_filled` (taken from your words), `missing` and `estimated_credits`. Call `results[0]` directly when `uncertain` is false: its method, path and params are the ready call (add any `missing` param, then apply the Cost rule). When `uncertain` is true, show the options. For a job that needs several calls (a profile, then posts, then comments; a brand watch), `GET /v1/utility/plan?query=<the job>` returns the calls in order with params, price, and which step feeds which. Write or billing requests return no results. `find` and `plan` share a limit of 30 calls a minute and 1,000 a day per key; past it they still answer 200 but with `uncertain: true` keyword guesses, so in a loop over many tasks route from the bundled files.\n2. **Fall back to the bundled files** when offline, when `find` or `plan` answers 404 (an older server: fall back to the existing flow), or when `uncertain` is true. Route with [Common jobs](#common-jobs) below, or grep [references/index.md](references/index.md): its Job to recipe table, then one line per endpoint (`grep -i transcript references/index.md`). For a recipe, read only its section: `grep -n '^## ' references/recipes.md` gives the line numbers; do not open the whole file. For an endpoint, read the platform file's TOC (from the top until the first `## `), then only its section: `grep -nE '^## (GET|POST|PUT|PATCH|DELETE) /v1/<platform>/<resource> - ' references/<platform>.md`, and read from that line to the next `## `. The section carries the exact cost, cache TTL, pagination, every parameter, the response fields, and the constraints checked before billing.\n3. **Estimate.** Build the exact request and apply the cost gate below (one line for a small flat call, the full preflight in [references/cost-gate.md](references/cost-gate.md) for anything metered or large). A heading's number can be a per-row or per-page unit, not the request total.\n4. **Call.** Resolve the key, then run the request exactly as the section shows it, keeping its HTTP method and body shape. If the user already asked to run this exact paid request, the cost disclosure is enough, except the Ask level: always ask (see the gate in the Cost rule); otherwise ask only before a paid call or wider scope they did not authorise.\n5. **Report.** Return the data, then `credits_used` and `credits_remaining`. For an async job report the hold at submission and the settled charge on completion.\n\n## Common jobs\n\nThe first call for the asks agents meet most, generated from the registry recipes (`{x}` is yours to fill). `find` gives the same answer with your values filled in.\n\n<!-- BEGIN:GENERATED:COMMON_JOBS (auto-generated by generate-skills.ts from registry recipes) -->\n| Job | First call | Then |\n|-----|------------|------|\n| Comments on a post to CSV | `GET /v1/tiktok/post/comments?url={url}&sort=recent&scan_pages=3` | `paginate.py` piped to `to_csv.py --archetype Comment`; any platform's `<platform>/post/comments`; [recipe](references/recipes.md#export-the-latest-n-comments-on-a-tiktok-video) |\n| Creators or influencers by niche, size or country | `GET /v1/prism/creators?keywords={niche}&country={country}&min_followers={min_followers}` | a `202` continues in the background (follow `data.next.status_url`); a product to promote goes in `campaign`, creators you already have in `handles` with `purpose`; [guide](https://www.socialcrawl.dev/docs/prism/creators) |\n| A product's reviews across retailers | `GET /v1/prism/product-reviews?query={product}` | covers Amazon, Google Shopping and Trustpilot reviews; Walmart, Target, Home Depot: `<retailer>/reviews`; [recipe](references/recipes.md#one-report-on-a-products-reviews-across-marketplaces) |\n| Stock price and news | `GET /v1/finance/ticker-search?keyword={company}` | then `finance/quote` (`quote.price.current`) and `finance/news`; [recipe](references/recipes.md#a-stocks-current-price-and-latest-headlines) |\n| YouTube transcript | `GET /v1/youtube/video/transcript?url={url}` | [recipe](references/recipes.md#transcribe-a-video) |\n| Alert on new posts or changes | `POST /v1/monitors` (body `recipe: instagram/profile/posts`) | only when `GET /v1/utility/estimate?id=monitors` returns 200, send `?dry_run=1` first to validate and price without creating; otherwise describe the request and create nothing until the user agrees; for a recurring digest of what is new about a topic, keyword or brand, every 1h or slower, call `POST /v1/search/everywhere` with `schedule` (every `1h` or slower, `dry_run` first), at 20 credits a search per fire and only rows that watch has not delivered, read through `GET /v1/events`, a webhook endpoint or the watch's own `last_fire`; a page: `web/monitors`; [recipe](references/recipes.md#track-a-creators-new-posts-every-day) |\n| Stats for a list of post URLs | `POST /v1/prism/post-stats` (JSON body `urls`) | a file of URLs: `batch.py --urls`; [recipe](references/recipes.md#engagement-stats-for-a-list-of-post-urls) |\n| Korean / Naver search | `GET /v1/naver/brief?query={keyword}&corpora=news,blog,cafearticle,kin` | one corpus: `naver/blog/search`, `naver/news/search`; [recipe](references/recipes.md#what-korean-consumers-say-about-a-product-and-search-interest) |\n| Profile lookup | `GET /v1/tiktok/profile?handle={handle}` | any `<platform>/profile`; many handles: `prism/profiles`; [recipe](references/recipes.md#a-creators-profile-recent-posts-and-the-comments-on-them) |\n| Scrape a web page | `GET /v1/web/scrape?url={url}` | structured fields: `web/extract`; a whole site: `web/crawl` |\n| One topic on several platforms | `GET /v1/search/multi?query={topic}&platforms=tiktok,instagram,youtube&relevance=filter` | [recipe](references/recipes.md#search-a-topic-on-several-platforms-at-once) |\n<!-- END:GENERATED:COMMON_JOBS -->\n\n## Helpers\n\nBundled scripts in `scripts/` (Python 3). They read the key from `SOCIALCRAWL_API_KEY` or `~/.config/socialcrawl/api_key` and never print it; `--help` on each gives the rest.\n\n```bash\npython3 scripts/sc.py tiktok/profile handle=nike # one call; JSON to stdout, credits_used to stderr\npython3 scripts/paginate.py tiktok/post/comments --items 500 --max-credits 20 url=<post_url> > rows.jsonl # page to N rows within a budget\npython3 scripts/to_csv.py --archetype Comment --in rows.jsonl --out comments.csv # rows to CSV with stable columns\npython3 scripts/batch.py --urls links.txt > stats.jsonl # stats for a file of post URLs (prism/post-stats, or one prism/jobs job past 500)\npython3 scripts/estimate.py tiktok/post/comments --items 500 --offline url=<post_url> # quote offline from assets/endpoints.json\n```\n\n**Code requests:** read the section and cost-gate, write a snippet that reads `SOCIALCRAWL_API_KEY` from the environment with a comment stating the billing unit, and present it without running it.\n\n**Capability and pricing questions:** answer from the index and [references/pricing.md](references/pricing.md) (cost, tiers, packs, refunds, the free-endpoint list). Auth, envelope, pagination, labels, caching, idempotency: [references/api-overview.md](references/api-overview.md). The free `/v1/utility/*` calls answer from the live registry: `endpoints` (filter `?platform=`, `?search=`), `endpoint?id=tiktok/profile` (one endpoint, with measured field fill rates and production latency), `explain-error` (paste a failed response, get the fix), `plan?query=`, `resolve?input=<url or @handle>` (platform and every endpoint that takes it), `capabilities` (cross-cutting params and where each works), `docs-search?query=`, `recipes`, `quickstart`. `utility/ai-detection` is the one paid utility (1 credit a text).\n\n**Ambiguous platform:** if the user says \"get @nike's profile\" with no platform, ask which one.\n\n## Where to look\n\n| Need | Open |\n|------|------|\n| Any single platform (social, commerce, reviews and places, app stores, search/news/finance, research and dev, link-in-bio) | [index.md](references/index.md) lists every platform file with its endpoint count; open `references/<platform>.md` |\n| One call over many platforms: Prism composites, `search/multi`, `search/everywhere` | [prism.md](references/prism.md), [search.md](references/search.md) |\n| A watch on a known account or post, with webhook delivery (Monitors); a keyword or topic digest is a discover schedule | [monitors.md](references/monitors.md); [discover schedules](references/api-overview.md#discover-schedules-v1prismdiscoverschedules) |\n| Follow, resume, extend or schedule a `prism/discover` run (all free) | [api-overview.md](references/api-overview.md#discover-runs-v1prismdiscoverruns), [schedules](references/api-overview.md#discover-schedules-v1prismdiscoverschedules) |\n| Be told when a discover run or schedule produces something: event feed or signed push | [api-overview.md](references/api-overview.md#account-event-feed-v1events), [webhook endpoints](references/api-overview.md#webhook-endpoints-v1webhook-endpoints) |\n| \"Which of MY list of accounts posted about X\" (Cohorts, not listening) | [cohorts.md](references/cohorts.md) |\n| Cost of a request or a whole paged walk; spend per API key | [cost-gate.md](references/cost-gate.md), [pricing.md](references/pricing.md), [credits usage](references/api-overview.md#credit-balance) |\n| A failed call | [errors.md](references/errors.md) |\n\n> **Never answer \"not supported\" from this table alone.** It is only as new as this file, and a missing row is far more often a stale copy than a real gap. Before telling a user a platform, endpoint or capability does not exist, check the live registry - it is free:\n>\n> ```bash\n> curl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \\\n> \"https://www.socialcrawl.dev/v1/utility/endpoints?search=douyin\"\n> ```\n>\n> Each row carries `path`, `method`, `credits_label`, `required_params`, `one_of`, `optional_params`, `paginated` and `cache_ttl_seconds`: enough to make the call without this file. Only say it is unsupported when the search returns `total: 0`.\n\n**Comparing products across retailers:** Amazon, Walmart, Target, eBay and Home Depot share the canonical Product / Review / Seller schemas, so rows line up. Resolve each retailer's product id (ASIN, item id, TCIN, ...) with its own search, then fetch detail and reviews per retailer. `/v1/prism/product-reviews` is one composite over Amazon, Google Shopping and Trustpilot reviews only; for Walmart, Target or Home Depot call `<retailer>/reviews`.\n\n**Several platforms at once:** To search one platform, call that platform's own search. To search several platforms over a date window with every row judged and de-duplicated, call `/v1/prism/discover`. For a quick fused sweep at a flat 20 credits, call `/v1/search/everywhere`, which drops rows outside `from_date`, `to_date`, `since` or `until` but reads one page per source, so a past window can come back thin. `/v1/prism/discover` answers in the call, or answers `202` with a run you follow at `data.next.status_url` (never resubmit a running request); put 2 to 6 topic words in `keywords` and the user's question in `context` ([guide](https://www.socialcrawl.dev/docs/prism/discover)). `/v1/search/multi` runs one query over several platforms' own search, one page per platform, with an optional `since`/`until` window and no background run (each platform's page price, charged only for those that returned rows). Many profiles or post URLs go to `POST /v1/prism/profiles` / `POST /v1/prism/post-stats`, or the background job `POST /v1/prism/jobs`.\n\n**One fused search:** For one fused, ranked search across the platforms it covers at a flat 20 credits a search, call `/v1/search/everywhere`; for a collection of more than 100 rows or more than one page per platform, call `/v1/prism/discover`; for creators, `/v1/prism/creators`; to be told what is new, send `since_watermark` with the `data.next.watermark` of your last answer, or turn the search into a watch with its `data.next.watch`. ([guide](https://www.socialcrawl.dev/docs/search/everywhere)).\n\n**Creators or influencers:** To find creators or influencers (by topic, market, size, or a product to promote), lookalikes of creators, or to measure and rank a list of creators you already have, call `/v1/prism/creators`. For shops, businesses and sellers, call `/v1/prism/discover` with `view=accounts`. It answers in the call or answers `202` with a run you follow at `data.next.status_url`; put 2 to 6 topic words in `keywords` and what the creators post about in `context`, a product to promote in `campaign`, or creators you already have in `handles` with `purpose` ([guide](https://www.socialcrawl.dev/docs/prism/creators)).\n\n\n**Alerts and recurring watches:** To be told when something new appears, match the ask to its job: for a recurring digest of what is new about a topic, keyword or brand, every 1h or slower, call `POST /v1/search/everywhere` with `schedule` (every `1h` or slower, `dry_run` first), at 20 credits a search per fire and only rows that watch has not delivered, read through `GET /v1/events`, a webhook endpoint or the watch's own `last_fire`; for the new posts or comments of an account or post you already know, call `POST /v1/monitors` with `webhook_rows: \"new\"`; for a one-off check of what is new since your last check, on an endpoint that takes `since` or `since_id`, call the endpoint's own `since` or `since_id` (for example `GET /v1/twitter/tweet/replies` with `since_id`, which returns an empty list and costs nothing when nothing is new); for metric snapshots of accounts you name (followers, views, likes), taken on a schedule, call `POST /v1/monitors` with a `track` metric; for reading what your watches produced, from a feed you poll or an endpoint that receives a signed push, call `GET /v1/events` with a named `consumer` for reading, and `/v1/webhook-endpoints` for push; a keyword or topic alert is never a Monitor.\n\n## Making calls\n\nBase URL `https://www.socialcrawl.dev`. Most endpoints are GET with query parameters (URL-encode values):\n\n```\ncurl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \\\n \"https://www.socialcrawl.dev/v1/{platform}/{resource}?{param}={value}\"\n```\n\n**Never assume the method.** Each endpoint section is headed by its real verb with a runnable curl. Batch reads, Prism jobs, web jobs, monitors, and cohorts use POST, PATCH, PUT, or DELETE with `content-type: application/json` (`web/parse` is multipart); the list, plus streaming (`Accept: text/event-stream`) and two-step endpoints that need an id from an earlier call, is in [api-overview.md](references/api-overview.md#non-get-routes-streaming-and-two-step-endpoints). Rate limits: 600 requests per minute and 50 concurrent per key; both return 429 with `Retry-After` and are never billed. Many endpoints take 10-45 s (task-polled sources, social profiles on a slow day): use a 60 s client timeout, or the endpoint's `recommended_timeout_s` from `GET /v1/utility/endpoint?id=` (free). Never time out early and resend a different request: an aborted call still runs, is charged and is cached, so resend the **identical** request and it comes back from cache at 0 credits. `POST` to `web/agent`, `web/sessions`, `web/monitors`, `web/parse`, `monitors` and `trustpilot/reviews/history` ignores `Idempotency-Key`: never auto-retry those, or you create (and pay for) a second one.\n\n## Reading a response\n\nDetails are in [api-overview.md](references/api-overview.md). Seven rules before the first call:\n\n- **Placement.** `pagination` (`next_cursor`, `has_more`, `page_size`) and the optional `meta.hint` sit at the envelope root. `dropped`, `_warnings` and every page report (`labels`, `relevance`, `label_share`, `hydration`, `walk`, ...) sit inside `data`. Read `data._warnings`: a parameter applied under the endpoint's own name (`sort was applied as sort_by, this endpoint's name for it.`), an ignored one (`limit was ignored: this endpoint's page size is fixed. ...`) or a handle that resolved to a different account (`resolved_to_different_handle`) is reported there, not as an error.\n- **Paging.** Send `pagination.next_cursor` back as `cursor` and stop on `has_more: false`, not on a short page or on `total`. A page with no rows and `has_more: true` is not the end, so call again with `next_cursor`. A page the source returned empty costs nothing. A zero-match list is `200` with `items: []` at 0 credits.\n- **Get more in one call; do not loop.** Every list endpoint takes `max_items=N` (walk pages until N rows), `max_credits=N` (never spend past it) and `max_pages` (1-50). Each page is billed as one call, `data.walk.stopped` says why it ended (`end`, `max_items`, `max_credits`, `time_budget`, ...) and `pagination.next_cursor` resumes ([details](references/api-overview.md#get-more-in-one-call-max_items-max_credits-max_pages)).\n- **Empty lists say why.** Every `items: []` carries `data.empty_reason` and a one-sentence `data.empty_reason_note`: `no_matches`, `end_of_list`, `nothing_new_since` (your `since` / `stop_at_id` poll found nothing new), `window_filtered`, `relevance_filtered`, `row_filtered`, `already_seen`, or `source_empty_unverified`, the only one worth a retry. Tell the user which it is instead of reporting \"no data\" ([codes](references/api-overview.md#empty-lists-empty_reason)).\n- **Default judgments are free.** Comment, post, review and keyword-search rows carry labels (`computed.labels`) and search rows a relevance score (`computed.relevance`) at no extra cost; `judgments=off` returns the raw page. Opt-in presets (`label=spam|toxic|low_quality|quality|ai_style|ai_written|injection|mention|reports|incentivized`, `relevant_to=`) add **1 credit per started 25 freshly judged rows**, held as `ceil(row cap / 25)` and refunded to the rows actually judged. `relevance=filter` against the query itself is free.\n- **Date windows.** `since` / `until` (`YYYY-MM-DD` or a timestamp) work on about 155 dated lists and on `search/everywhere`. On 25 newest-first lists (the creator feeds and some comment, review and search lists) sending `since` sets their recency sort and the page that reaches the date ends the walk (`pagination.stopped_at`); every other list filters each page, keeps its cursor and bills every page walked, so an empty page that still has `next_cursor` is normal: keep paging. `published_after`, `start_date`, `from_date`, `publish_time=this-week` and `max_age_days` are read as `since`; `published_before`, `end_date` and `to_date` as `until` ([date window](references/api-overview.md#date-window-since-until)). A date on a list whose rows carry none is a free 400 (`unsupported_date_filter`).\n- **Spend controls.** Creator post lists also take `stop_at_id`, so a poll pays only for new pages. Keyword searches take `min_views`, `country` / `exclude_country`, `sort_rows=views`, `seen=<id>` (repeats refunded) on top of the walk (**each page billed**).\n- **`meta.hint`** names one other call that does the job in fewer steps. Its message states the price when that call costs more; follow it only within what the user authorised.\n\n`include=` hydration joins rows to a sibling endpoint and is charged **per row on top of the page**, so never quote the plain heading cost for a hydrated call; the ceilings are in [cost-gate.md](references/cost-gate.md#row-hydration-include) and the traps in [api-overview.md](references/api-overview.md#row-hydration-include).\n\n## Cost rule\n\nCache hits, idempotent replays, every `/v1/utility/*` endpoint except `utility/ai-detection` (1 credit), and `/v1/credits/*` cost 0 credits. Failed calls are refunded, and a request rejected for bad params, a page past the last page, or a rate limit never deducts. Metered endpoints hold an upfront ceiling and refund down to the work done, so the response `credits_used` is the real charge. A band that starts at 0 can settle at 0 (its legs bill only when they return rows), and the top of a wide band is a cap, not the expected charge: `prism/discover` never spends past its `max_credits`. Quote the total for the exact request, not the endpoint's base or unit cost. Scale the gate to the call:\n\n| Call | Gate |\n| --- | --- |\n| Flat price \u2264 5 credits, user asked for it | One line: `\u2248 N credits` |\n| Metered, multi-page, batch, monitor/cohort, or > 25 credits | Full preflight via `estimate.py` / `utility/estimate` |\n| Upfront hold (worst case) > 500 credits or over budget (the user's stated budget) | Ask before calling |\n\nAnything in between, or unsure of the price or params: quote first with the free `GET /v1/utility/estimate?id=<platform/resource>&<params>`. Any reply except a 404 means a current server (a 5xx or network failure is no reply: retry the estimate): use its quote, and `dry_run=1` is then free on any endpoint (validates, fetches nothing). A 404 or `ENDPOINT_NOT_FOUND` means an older server: do **not** send `dry_run=1` (it bills a normal call there, except the labelled dry run an endpoint documents); quote with `scripts/estimate.py` (offline, `assets/endpoints.json`) or the section's **Pricing** line. At every level, report `credits_used` after.\n\n**If the task needs a whole list, price the whole walk before the first page.** Paging to completion multiplies the page cost by the page count, and a heading only shows one page. `instagram/followers` and `instagram/following` are the common case: about 50 accounts a page. A plain walk (5 credits a page) usually ends within a few rows of the profile's count (large verified accounts stop at about 50 rows on every route); `coverage=full` (10 credits a page) is only for a walk that fell short of `data.total`, and at that rate a 2,600-account list is roughly 520 credits, half that on a plain walk. Quote the total and get agreement before starting ([Multi-page walks](references/cost-gate.md#multi-page-walks-coveragefull)).\n\nErrors: classify before retrying with [references/errors.md](references/errors.md), or paste the status and body into the free `GET /v1/utility/explain-error` for the fix. Never retry a 402 unchanged. Credits and balance: `GET /v1/credits/balance` (0 credits); the ledger is `GET /v1/credits/transactions?limit=50`; spend per API key per UTC day (up to 92 days) is `GET /v1/credits/usage?from=&to=&group_by=api_key,day` (both 0 credits).";
3
- export declare const ERRORS_GUIDE = "# Errors\n\nRead this when a call fails. The full code table (status, retryable, what to do) is generated in [api-overview.md](api-overview.md#error-codes); the `error.details` reasons are in [api-overview.md](api-overview.md#error-details-errordetails).\n\n**Fastest fix:** paste the failed status and body into the free `GET /v1/utility/explain-error?status=<code>&body=<error JSON>` (add `request=<the path and query you sent>` to get a corrected request back). It returns the fault in plain words, the steps that fix it, and whether retrying the same request can succeed. Nothing is fetched and it costs 0 credits.\n\n## Classify before retrying\n\nBranch on `error.retryable` first, then on `error.details`, never on the status alone.\n\n- **Fix before retrying (`retryable: false`):** `MISSING_API_KEY`, `INVALID_API_KEY`, `INSUFFICIENT_CREDITS`, `KEY_BUDGET_EXCEEDED`, `INVALID_REQUEST`, `METHOD_NOT_ALLOWED` (the `Allow` header names the right verb), `ENDPOINT_NOT_FOUND`, `PAYLOAD_TOO_LARGE`, `IDEMPOTENCY_KEY_CONFLICT`, `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH` (use a fresh key for the changed payload), `IDEMPOTENCY_REPLAY_UNAVAILABLE`, and every `COHORT_*` code. Explain the corrective action and do not repeat the same request.\n- **Wait, then retry the same request:** `RATE_LIMITED`, `CONCURRENCY_LIMIT` (`Retry-After: 1`), `SERVICE_UNAVAILABLE`, and `409 IDEMPOTENCY_IN_PROGRESS` (`Retry-After` 1-30 s; resend with the **same** `Idempotency-Key`). Honour `Retry-After`, then back off exponentially with jitter. A `Retry-After` longer than a minute (for example `3600` for a source that is down in one market) means stop and report, not wait in a loop.\n- **Transient upstream failure:** `UPSTREAM_ERROR` (502, or 504 on a timeout) and `INTERNAL_ERROR`, refunded. If `error.details.retry_with` is present, `retryable` is `false` and there is no `Retry-After`: the same request fails the same way, so resend once with exactly the params it names (for example `proxy=auto` on `web/scrape`). If `error.incident` is present, stop calling that platform and poll `GET /v1/status/{platform}` every few minutes. Otherwise retry at most once, then report the outage with the endpoint and `request_id`, never the credential.\n- **Not found:** `RESOURCE_NOT_FOUND` is a valid empty outcome, not a retry loop.\n- **Discover runs and the events feed:** `RUN_NOT_FOUND` / `SCHEDULE_NOT_FOUND` (wrong id, or another account's): list your runs or schedules, or start again. `RUN_STATE_CONFLICT` (409): read the run and do what `data.run.next_step` says (a completed run takes `more`, not `resume`). `RUN_EXPIRED` (410): retention passed, start a new run. `NEEDS_ASYNC` (422): drop `async=false` and follow the 202's `data.next.status_url`. `CURSOR_EXPIRED` (410): restart the feed from `details.oldest_cursor` (or `cursor=oldest`) and tell the user the events in `missed_from`..`missed_until` are gone (30-day retention).\n\n## Act on `error.details`\n\nEvery error carries `error.retryable`, and many carry `error.details.reason`; act on it rather than on the status alone:\n\n- **402** (`balance_too_low`, `key_budget_reached`) always says `retry_will_succeed: false`: **never retry a 402 unchanged**. The same request fails until the balance or that key's limit changes. Point the user at `top_up_url` or `key_settings_url`; `key_name`, `key_prefix` and `account_email_masked`, when present, say which key and account ran out. A key budget is a lifetime cap on that key's net spend (refunds give it back; it never resets on its own), so on `key_budget_reached` the `credits_remaining` is the healthy account balance: the user raises the limit or resets the key's usage in Dashboard \u2192 API Keys, or uses another key. On a metered call `pricing: \"ceiling\"` means the quoted credits are the maximum hold (unused credits are refunded) and `credits_typical` is what a call like it is usually charged; `pricing: \"exact\"` means it is charged what it holds. `lower_cost_options` lists each param that lowers the hold, with the `value` to send (`null`: leave it out) and the `credits_required` it gives, and `credits_required_cheapest` is the hold with all of them. When one of those fits `credits_remaining`, offer the user that smaller request, or a top-up for the full one.\n- **400 `page_limit`** (`max_page`, `narrow_with`): the source has no further pages for this query; stop paging and narrow the query instead. It is the end of the walk, not a failure.\n- **400 with `did_you_mean`**: a parameter or value was misnamed. `error.details.received_unknown` lists the names the endpoint did not recognise, `missing` the required one it did not get, and `did_you_mean` the name it takes (`You sent term; this endpoint takes query`). Resend under that name; it is free.\n- **400 `unsupported_date_filter`**: `since` / `until` (or a copied spelling such as `published_after`) on a list whose rows carry no date. Drop the date.\n- **404 `account_gone` / `account_private` / `handle_unresolved`**: follow `error.details.suggestion` once (for a YouTube handle, retry with the stored `channelId` to tell a rename from a removal), then report. `site_not_supported` on `web/scrape` is final; its `suggestion` names the SocialCrawl endpoint for a social link.\n- **404 `ENDPOINT_NOT_FOUND`** may carry `details.did_you_mean` (paths), `did_you_mean_platform` and `retry_with` (the whole corrected URL, for example for a bare `/search`); check the live registry (`GET /v1/utility/endpoints?search=`, free) before saying something is unsupported. On `/v1/web/jobs|monitors|sessions/{id}` it means the id is unknown for this key.\n- **5xx** carry `error.status_url` and, during an open incident, `error.incident` (`id`, `title`, `status`, `impact`, `url`).\n\n## Not errors: `data._warnings` and `meta.hint`\n\nA `200` can still carry advice. `data._warnings` reports a parameter that was ignored or cleaned (a `Query:` label stripped from a search term, a `fields=` path that does not exist, with the path it probably meant) and a handle that resolved to a different account. `meta.hint`, at the envelope root, names one other call that does the job in fewer steps; when that call costs more, its `message` says both prices, so follow it only within what the user authorised. It reaches a key at most once a day per pattern, never on an error; send `X-SocialCrawl-Hints: off` to stop it.\n\n## Retrying paid calls\n\nFor a retryable paid non-streaming request, send an `Idempotency-Key` before the first attempt and reuse it only for the identical payload (same params, same `fields`). A GET with `Accept: text/event-stream` cannot carry an `Idempotency-Key` (free 400); do not automatically retry streaming requests. Never exceed one automatic retry unless the user explicitly asks for continued retries.\n\n**Some POSTs ignore `Idempotency-Key`, so never auto-retry them:** `POST /v1/web/agent`, `/v1/web/sessions`, `/v1/web/monitors`, `/v1/web/parse`, `/v1/monitors` and `/v1/trustpilot/reviews/history`. A resend creates (and, where it bills, bills) a second run, session, monitor or job. Read the list route (`GET /v1/web/jobs`, `GET /v1/web/sessions`, `GET /v1/monitors`) to see whether the first one landed. On `POST /v1/web/crawl` and `/v1/web/batch-scrape` a repeated key returns the existing job (200, 0 credits) without comparing the body.\n\n**A client timeout does not cancel the call.** The server finishes it, charges it and writes it to the cache. Resend the identical request (same or new key) and, within the endpoint's cache TTL, it comes back free from cache (`X-Cache: HIT`). Size your timeout from `recommended_timeout_s` in `GET /v1/utility/endpoint?id=` (60 s is safe almost everywhere).\n\nFailed calls are refunded (upstream errors, circuit-breaker rejections, timeouts, not-found, empty results). `credits_used` on an error envelope is the committed net charge: 0 in almost every case, the kept legs on a partially failed composite. A request rejected for bad params, a page past the source's last page, or a rate limit never deducts at all.";
2
+ export declare const GUIDE = "# SocialCrawl API\n\nOne API key and one response envelope for social, commerce, and research data. Lists are `{ items, next_cursor?, total? }`; add `?format=raw` to skip the transform pipeline. Every file below lives in `references/`; open only the one the task needs.\n\n## API Key\n\nResolve the API key only when a live API call is needed. Documentation, capability, pricing, and code-generation questions do not need a key.\n\nCheck these sources in order without displaying their contents:\n\n1. **Environment variable:** use `SOCIALCRAWL_API_KEY` when it starts with `sc_` and is not an example placeholder.\n2. **Config file:** if the environment variable is absent, load `~/.config/socialcrawl/api_key` into `SOCIALCRAWL_API_KEY` in the current process. On POSIX shells, use `SOCIALCRAWL_API_KEY=\"$(<\"$HOME/.config/socialcrawl/api_key\")\"; export SOCIALCRAWL_API_KEY`. On PowerShell, use `$env:SOCIALCRAWL_API_KEY = (Get-Content -LiteralPath \"$HOME/.config/socialcrawl/api_key\" -Raw).Trim()`.\n3. **Missing key:** tell the user to create or rotate a key at https://socialcrawl.dev/dashboard and configure it as `SOCIALCRAWL_API_KEY` or in `~/.config/socialcrawl/api_key`. Do not ask them to paste a secret into chat. Stop before the live call until they say it is configured.\n\nNever print, paste, log, or return the key. Never place a literal key in generated code, a command, a URL, an error message, or a saved transcript. Keep `$SOCIALCRAWL_API_KEY` (POSIX) or `$env:SOCIALCRAWL_API_KEY` (PowerShell) as a variable reference in examples. If the key appeared in chat or output, advise the user to revoke it in the dashboard and create a replacement.\n\n## First Live Call\n\nBefore the first live call in a session:\n\n1. Resolve the API key using the steps above. If it is missing or a placeholder, stop before making the call.\n2. Verify it with the free balance endpoint (0 credits):\n ```bash\n curl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \"https://www.socialcrawl.dev/v1/credits/balance\"\n ```\n3. If successful, show the user `data.balance` (it equals `credits_remaining`) and continue with the user's request. Do not print the whole response: it also carries account links (`top_up_url`, `checkout_url`) that belong to the account owner and should stay out of transcripts and logs. Share `checkout_url` only with the account owner when `runway.days_left` is under 3; it opens checkout only after they sign in to the dashboard.\n4. If it fails, report the error without including request headers or the key, then follow [references/errors.md](references/errors.md).\n\n## Freshness Check (do this once per session)\n\nThis file is a snapshot of the registry with this fingerprint:\n\n<!-- BEGIN:GENERATED:FRESHNESS (auto-generated by generate-skills.ts - SK-08) -->\n```text\nregistry_fingerprint: 7ae238a672d167c1d9b41e01b19992ac5e988b23433fe43ee17d4ec209af9fa4\ngenerated_at: 2026-11-30\n```\n<!-- END:GENERATED:FRESHNESS -->\n\nBeside the balance check, make one free call:\n\n```bash\ncurl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \"https://www.socialcrawl.dev/v1/utility/endpoints?fingerprint=1\" | head -c 400\n```\n\n- **`data.fingerprint` equals `registry_fingerprint` above** - use the bundled files and move on.\n- **It differs** - this copy and the live API are out of sync (the skill or the server may be newer): a price, parameter or endpoint changed. Treat the live registry as the source of truth. For the section a task needs, read the current copy of this skill, published with every deploy and readable with no API key: https://www.socialcrawl.dev/skills/socialcrawl/references/<platform>.md (same file names and headings as here; https://www.socialcrawl.dev/skills/socialcrawl/SKILL.md for this file), and resolve exact prices and params through `/v1/utility/*` (all free except `utility/ai-detection`, 1 credit). Tell the user **once**, briefly: \"this SocialCrawl skill does not match the live API; run `npx skills update socialcrawl --yes` to refresh it.\" When it was installed as a Claude Code plugin, the command is `claude plugin update socialcrawl@socialcrawl` instead. If you can run shell commands, offer once to run that update for them and run it only on a yes, then re-read this file. A copy uploaded to claude.ai is refreshed by uploading the latest package, https://github.com/socialcrawl/skills/raw/main/socialcrawl.skill. Then answer their actual question. Do not repeat it.\n- **No `data.fingerprint`** (a 404, or an older server that answers with the plain list) - fall back to counts: compare `data.stats.platforms` and `data.stats.endpoints` from `/v1/utility/endpoints` with the totals at the top of [references/index.md](references/index.md). Live numbers HIGHER means behind, as above.\n- **The call fails** (no key yet, offline, non-200) - skip it silently. This check must never block the request.\n\n## Workflow\n\n1. **Find the call first (free, 0 credits, runs nothing).** `GET /v1/utility/find?task=<the job in plain words>` ranks the endpoints for the job, each with `method`, `path`, `params_filled` (taken from your words), `missing`, `estimated_credits` (the most that call can cost with the params shown) and `credits_ceiling` (the most it can cost once the params in `ceiling_params` are added too, such as `coverage=full` or a higher `limit`). Call `results[0]` directly when `uncertain` is false: its method, path and params are the ready call (add any `missing` param, then apply the Cost rule). Before you add a param the row did not fill, gate on `credits_ceiling`, not `estimated_credits`. Check `params_filled` against the task: a search value should be the product or topic name only, and `country`/`language` filled from Hangul (KR, ko) are marked in `inferred_params`. When `uncertain` is true, show the options. For a job that needs several calls (a profile, then posts, then comments; a brand watch), `GET /v1/utility/plan?query=<the job>` returns the calls in order with params, price, and which step feeds which. Write or billing requests return no results. `find` and `plan` share a limit of 30 calls a minute and 1,000 a day per key; past it they still answer 200 but with `uncertain: true` keyword guesses, so in a loop over many tasks route from the bundled files.\n2. **Fall back to the bundled files** when offline, when `find` or `plan` answers 404 (an older server: fall back to the existing flow), or when `uncertain` is true. Route with [Common jobs](#common-jobs) below, or grep [references/index.md](references/index.md): its Job to recipe table, then one line per endpoint (`grep -i transcript references/index.md`). For a recipe, read only its section: `grep -n '^## ' references/recipes.md` gives the line numbers; do not open the whole file. For an endpoint, read the platform file's TOC (from the top until the first `## `), then only its section: `grep -nE '^## (GET|POST|PUT|PATCH|DELETE) /v1/<platform>/<resource> - ' references/<platform>.md`, and read from that line to the next `## `. The section carries the exact cost, cache TTL, pagination, every parameter, the response fields, and the constraints checked before billing.\n3. **Estimate.** Build the exact request and apply the cost gate below (one line for a small flat call, the full preflight in [references/cost-gate.md](references/cost-gate.md) for anything metered or large). A heading's number can be a per-row or per-page unit, not the request total. **When an endpoint's heading price is a range** (`1-178 credits`), its price depends on its params: read `GET /v1/utility/endpoint?id=<platform/resource>` (free) for the live price rule before calling, then quote the exact request with `utility/estimate`, even when this copy of the skill matches the live fingerprint.\n4. **Call.** Resolve the key, then run the request exactly as the section shows it, keeping its HTTP method and body shape. If the user already asked to run this exact paid request, the cost disclosure is enough, except the Ask level: always ask (see the gate in the Cost rule); otherwise ask only before a paid call or wider scope they did not authorise.\n5. **Report.** Return the data, then `credits_used` and `credits_remaining`. For an async job report the hold at submission and the settled charge on completion.\n\n## Common jobs\n\nThe first call for the asks agents meet most, generated from the registry recipes (`{x}` is yours to fill). `find` gives the same answer with your values filled in.\n\n<!-- BEGIN:GENERATED:COMMON_JOBS (auto-generated by generate-skills.ts from registry recipes) -->\n| Job | First call | Then |\n|-----|------------|------|\n| Comments on a post to CSV | `GET /v1/tiktok/post/comments?url={url}&sort=recent&scan_pages=3` | `paginate.py` piped to `to_csv.py --archetype Comment`; any platform's `<platform>/post/comments`; [recipe](references/recipes.md#export-the-latest-n-comments-on-a-tiktok-video) |\n| Creators or influencers by niche, size or country | `GET /v1/prism/creators?keywords={niche}&country={country}&min_followers={min_followers}` | a `202` continues in the background (follow `data.next.status_url`); a product to promote goes in `campaign`, creators you already have in `handles` with `purpose`; [guide](https://www.socialcrawl.dev/docs/prism/creators) |\n| A product's reviews across retailers | `GET /v1/prism/product-reviews?query={product}` | covers Amazon, Google Shopping and Trustpilot reviews; Walmart, Target, Home Depot: `<retailer>/reviews`; [recipe](references/recipes.md#one-report-on-a-products-reviews-across-marketplaces) |\n| Stock price and news | `GET /v1/finance/ticker-search?keyword={company}` | then `finance/quote` (`quote.price.current`) and `finance/news`; [recipe](references/recipes.md#a-stocks-current-price-and-latest-headlines) |\n| YouTube transcript | `GET /v1/youtube/video/transcript?url={url}` | [recipe](references/recipes.md#transcribe-a-video) |\n| Alert on new posts or changes | `POST /v1/monitors` (body `recipe: instagram/profile/posts`) | only when `GET /v1/utility/estimate?id=monitors` returns 200, send `?dry_run=1` first to validate and price without creating; otherwise describe the request and create nothing until the user agrees; for a recurring digest of what is new about a topic, keyword or brand, every 1h or slower, call `POST /v1/search/everywhere` with `schedule` (every `1h` or slower, `dry_run` first), at 20 credits a search per fire and only rows that watch has not delivered, read through `GET /v1/events`, a webhook endpoint or the watch's own `last_fire`; a page: `web/monitors`; [recipe](references/recipes.md#track-a-creators-new-posts-every-day) |\n| Stats for a list of post URLs | `POST /v1/prism/post-stats` (JSON body `urls`) | a file of URLs: `batch.py --urls`; [recipe](references/recipes.md#engagement-stats-for-a-list-of-post-urls) |\n| Korean / Naver search | `GET /v1/naver/brief?query={keyword}&corpora=news,blog,cafearticle,kin` | one corpus: `naver/blog/search`, `naver/news/search`; [recipe](references/recipes.md#what-korean-consumers-say-about-a-product-and-search-interest) |\n| Profile lookup | `GET /v1/tiktok/profile?handle={handle}` | any `<platform>/profile`; many handles: `prism/profiles`; [recipe](references/recipes.md#a-creators-profile-recent-posts-and-the-comments-on-them) |\n| Scrape a web page | `GET /v1/web/scrape?url={url}` | structured fields: `web/extract`; a whole site: `web/crawl` |\n| One topic on several platforms | `GET /v1/search/multi?query={topic}&platforms=tiktok,instagram,youtube&relevance=filter` | [recipe](references/recipes.md#search-a-topic-on-several-platforms-at-once) |\n<!-- END:GENERATED:COMMON_JOBS -->\n\n## Helpers\n\nBundled scripts in `scripts/` (Python 3). They read the key from `SOCIALCRAWL_API_KEY` or `~/.config/socialcrawl/api_key` and never print it; `--help` on each gives the rest.\n\n```bash\npython3 scripts/sc.py tiktok/profile handle=nike # one call; JSON to stdout, credits_used to stderr\npython3 scripts/paginate.py tiktok/post/comments --items 500 --max-credits 20 url=<post_url> > rows.jsonl # page to N rows within a budget\npython3 scripts/to_csv.py --archetype Comment --in rows.jsonl --out comments.csv # rows to CSV with stable columns\npython3 scripts/batch.py --urls links.txt > stats.jsonl # stats for a file of post URLs (prism/post-stats, or one prism/jobs job past 500)\npython3 scripts/estimate.py tiktok/post/comments --items 500 --offline url=<post_url> # quote offline from assets/endpoints.json\n```\n\n**Code requests:** read the section and cost-gate, write a snippet that reads `SOCIALCRAWL_API_KEY` from the environment with a comment stating the billing unit, and present it without running it.\n\n**Capability and pricing questions:** answer from the index and [references/pricing.md](references/pricing.md) (cost, tiers, packs, refunds, the free-endpoint list). Auth, envelope, pagination, labels, caching, idempotency: [references/api-overview.md](references/api-overview.md). The free `/v1/utility/*` calls answer from the live registry: `endpoints` (filter `?platform=`, `?search=`), `endpoint?id=tiktok/profile` (one endpoint, with measured field fill rates and production latency), `explain-error` (paste a failed response, get the fix), `plan?query=`, `resolve?input=<url or @handle>` (platform and every endpoint that takes it), `capabilities` (cross-cutting params and where each works), `docs-search?query=`, `recipes`, `quickstart`. `utility/ai-detection` is the one paid utility (1 credit a text).\n\n**Ambiguous platform:** if the user says \"get @nike's profile\" with no platform, ask which one.\n\n## Where to look\n\n| Need | Open |\n|------|------|\n| Any single platform (social, commerce, reviews and places, app stores, search/news/finance, research and dev, link-in-bio) | [index.md](references/index.md) lists every platform file with its endpoint count; open `references/<platform>.md` |\n| One call over many platforms: Prism composites, `search/multi`, `search/everywhere` | [prism.md](references/prism.md), [search.md](references/search.md) |\n| A watch on a known account or post, with webhook delivery (Monitors); a keyword or topic digest is a discover schedule | [monitors.md](references/monitors.md); [discover schedules](references/api-overview.md#discover-schedules-v1prismdiscoverschedules) |\n| Follow, resume, extend or schedule a `prism/discover` run (all free) | [api-overview.md](references/api-overview.md#discover-runs-v1prismdiscoverruns), [schedules](references/api-overview.md#discover-schedules-v1prismdiscoverschedules) |\n| Be told when a discover run or schedule produces something: event feed or signed push | [api-overview.md](references/api-overview.md#account-event-feed-v1events), [webhook endpoints](references/api-overview.md#webhook-endpoints-v1webhook-endpoints) |\n| \"Which of MY list of accounts posted about X\" (Cohorts, not listening) | [cohorts.md](references/cohorts.md) |\n| Cost of a request or a whole paged walk; spend per API key | [cost-gate.md](references/cost-gate.md), [pricing.md](references/pricing.md), [credits usage](references/api-overview.md#credit-balance) |\n| A failed call | [errors.md](references/errors.md) |\n\n> **Never answer \"not supported\" from this table alone.** It is only as new as this file, and a missing row is far more often a stale copy than a real gap. Before telling a user a platform, endpoint or capability does not exist, check the live registry - it is free:\n>\n> ```bash\n> curl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \\\n> \"https://www.socialcrawl.dev/v1/utility/endpoints?search=douyin\"\n> ```\n>\n> Each row carries `path`, `method`, `credits_label`, `required_params`, `one_of`, `optional_params`, `paginated` and `cache_ttl_seconds`: enough to make the call without this file. Only say it is unsupported when the search returns `total: 0`.\n\n**Comparing products across retailers:** Amazon, Walmart, Target, eBay and Home Depot share the canonical Product / Review / Seller schemas, so rows line up. Resolve each retailer's product id (ASIN, item id, TCIN, ...) with its own search, then fetch detail and reviews per retailer. `/v1/prism/product-reviews` is one composite over Amazon, Google Shopping and Trustpilot reviews only; for Walmart, Target or Home Depot call `<retailer>/reviews`.\n\n**Several platforms at once:** To search one platform, call that platform's own search. To search several platforms over a date window with every row judged and de-duplicated, call `/v1/prism/discover`. For a quick fused sweep at a flat 20 credits, call `/v1/search/everywhere`, which drops rows outside `from_date`, `to_date`, `since` or `until` but reads one page per source, so a past window can come back thin. `/v1/prism/discover` answers in the call, or answers `202` with a run you follow at `data.next.status_url` (never resubmit a running request); put 2 to 6 topic words in `keywords` and the user's question in `context` ([guide](https://www.socialcrawl.dev/docs/prism/discover)). `/v1/search/multi` runs one query over several platforms' own search, one page per platform, with an optional `since`/`until` window and no background run (each platform's page price, charged only for those that returned rows). Many profiles or post URLs go to `POST /v1/prism/profiles` / `POST /v1/prism/post-stats`, or the background job `POST /v1/prism/jobs`.\n\n**One fused search:** For one fused, ranked search across the platforms it covers at a flat 20 credits a search, call `/v1/search/everywhere`; for a collection of more than 100 rows or more than one page per platform, call `/v1/prism/discover`; for creators, `/v1/prism/creators`; to be told what is new, send `since_watermark` with the `data.next.watermark` of your last answer, or turn the search into a watch with its `data.next.watch`. ([guide](https://www.socialcrawl.dev/docs/search/everywhere)).\n\n**Creators or influencers:** To find creators or influencers (by topic, market, size, or a product to promote), lookalikes of creators, or to measure and rank a list of creators you already have, call `/v1/prism/creators`. For shops, businesses and sellers, call `/v1/prism/discover` with `view=accounts`. It answers in the call or answers `202` with a run you follow at `data.next.status_url`; put 2 to 6 topic words in `keywords` and what the creators post about in `context`, a product to promote in `campaign`, or creators you already have in `handles` with `purpose` ([guide](https://www.socialcrawl.dev/docs/prism/creators)).\n\n\n**Alerts and recurring watches:** To be told when something new appears, match the ask to its job: for a recurring digest of what is new about a topic, keyword or brand, every 1h or slower, call `POST /v1/search/everywhere` with `schedule` (every `1h` or slower, `dry_run` first), at 20 credits a search per fire and only rows that watch has not delivered, read through `GET /v1/events`, a webhook endpoint or the watch's own `last_fire`; for the new posts or comments of an account or post you already know, call `POST /v1/monitors` with `webhook_rows: \"new\"`; for a one-off check of what is new since your last check, on an endpoint that takes `since` or `since_id`, call the endpoint's own `since` or `since_id` (for example `GET /v1/twitter/tweet/replies` with `since_id`, which returns an empty list and costs nothing when nothing is new); for metric snapshots of accounts you name (followers, views, likes), taken on a schedule, call `POST /v1/monitors` with a `track` metric; for reading what your watches produced, from a feed you poll or an endpoint that receives a signed push, call `GET /v1/events` with a named `consumer` for reading, and `/v1/webhook-endpoints` for push; a keyword or topic alert is never a Monitor.\n\n## Making calls\n\nBase URL `https://www.socialcrawl.dev`. Most endpoints are GET with query parameters (URL-encode values):\n\n```\ncurl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \\\n \"https://www.socialcrawl.dev/v1/{platform}/{resource}?{param}={value}\"\n```\n\n**Never assume the method.** Each endpoint section is headed by its real verb with a runnable curl. Batch reads, Prism jobs, web jobs, monitors, and cohorts use POST, PATCH, PUT, or DELETE with `content-type: application/json` (`web/parse` is multipart); the list, plus streaming (`Accept: text/event-stream`) and two-step endpoints that need an id from an earlier call, is in [api-overview.md](references/api-overview.md#non-get-routes-streaming-and-two-step-endpoints). Rate limits: 600 requests per minute and 50 concurrent per key; both return 429 with `Retry-After` and are never billed. Many endpoints take 10-45 s (task-polled sources, social profiles on a slow day): use a 60 s client timeout, or the endpoint's `recommended_timeout_s` from `GET /v1/utility/endpoint?id=` (free). Never time out early and resend a different request: an aborted JSON call still runs, is charged and is cached, so resend the **identical** request and it comes back from cache at 0 credits. A streamed call (`Accept: text/event-stream`) that you abort is refunded and is not cached, so its resend is billed as a new call. A 429 body repeats the wait as `error.details.retry_after_s`; a 504 with `error.details.reason: \"task_queued\"` is picked up by the identical request within the hour, or send it with `Prefer: respond-async` for a job to poll at `data.next.status_url`. `POST` to `web/agent`, `web/sessions`, `web/monitors`, `web/parse`, `monitors` and `trustpilot/reviews/history` ignores `Idempotency-Key`: never auto-retry those, or you create (and pay for) a second one.\n\n## Reading a response\n\nDetails are in [api-overview.md](references/api-overview.md). Seven rules before the first call:\n\n- **Placement.** `pagination` (`next_cursor`, `has_more`, `page_size`) and the optional `meta.hint` sit at the envelope root. `dropped`, `_warnings` and every page report (`labels`, `relevance`, `label_share`, `hydration`, `walk`, ...) sit inside `data`. Read `data._warnings`: a parameter applied under the endpoint's own name (`sort was applied as sort_by, this endpoint's name for it.`), an ignored one (`limit was ignored: this endpoint's page size is fixed. ...`) or a handle that resolved to a different account (`resolved_to_different_handle`) is reported there, not as an error.\n- **Paging.** Send `pagination.next_cursor` back as `cursor` and stop on `has_more: false`, not on a short page or on `total`. A page with no rows and `has_more: true` is not the end, so call again with `next_cursor`. A page the source returned empty costs nothing; a page your `since` or `until` emptied costs what a page costs. A zero-match list is `200` with `items: []` at 0 credits.\n- **Get more in one call; do not loop.** Most list endpoints take `max_items=N` (walk pages until N rows), `max_credits=N` (never spend past it) and `max_pages` (1-50); check the endpoint's parameters first, because self-walking endpoints, the `-full` lanes, job reads and `prism/discover` do not. Each page is billed as one call, `data.walk.stopped` says why it ended (`end`, `max_items`, `max_credits`, `time_budget`, ...) and `pagination.next_cursor` resumes ([details](references/api-overview.md#get-more-in-one-call-max_items-max_credits-max_pages)).\n- **Empty lists say why.** Every `items: []` carries `data.empty_reason` and a one-sentence `data.empty_reason_note`: `no_matches`, `end_of_list`, `nothing_new_since` (your `since` / `stop_at_id` poll found nothing new), `window_filtered`, `relevance_filtered`, `row_filtered`, `already_seen`, or `source_empty_unverified`, the only one worth a retry. Tell the user which it is instead of reporting \"no data\" ([codes](references/api-overview.md#empty-lists-empty_reason)).\n- **Default judgments are free.** Comment, post, review and keyword-search rows carry labels (`computed.labels`) and search rows a relevance score (`computed.relevance`) at no extra cost; `judgments=off` returns the raw page. Opt-in presets (`label=spam|toxic|low_quality|quality|ai_style|ai_written|injection|mention|reports|incentivized`, `relevant_to=`) add **1 credit per started 25 freshly judged rows**, held as `ceil(row cap / 25)` and refunded to the rows actually judged. `relevance=filter` against the query itself is free.\n- **Date windows.** `since` / `until` (`YYYY-MM-DD` or a timestamp) work on about 155 dated lists and on `search/everywhere`. On 25 newest-first lists (the creator feeds and some comment, review and search lists) sending `since` sets their recency sort and the page that reaches the date ends the walk (`pagination.stopped_at`); every other list filters each page, keeps its cursor and bills every page walked, so an empty page that still has `next_cursor` is normal: keep paging. `published_after`, `start_date`, `from_date`, `publish_time=this-week` and `max_age_days` are read as `since`; `published_before`, `end_date` and `to_date` as `until` ([date window](references/api-overview.md#date-window-since-until)). A date on a list whose rows carry none is a free 400 (`unsupported_date_filter`).\n- **Spend controls.** Creator post lists also take `stop_at_id`, so a poll pays only for new pages. Keyword searches take `min_views`, `country` / `exclude_country`, `sort_rows=views`, `seen=<id>` (repeats refunded) on top of the walk (**each page billed**).\n- **`meta.hint`** names one other call that does the job in fewer steps. Its message states the price when that call costs more; follow it only within what the user authorised.\n\n`include=` hydration joins rows to a sibling endpoint and is charged **per row on top of the page**, so never quote the plain heading cost for a hydrated call; the ceilings are in [cost-gate.md](references/cost-gate.md#row-hydration-include) and the traps in [api-overview.md](references/api-overview.md#row-hydration-include).\n\n## Cost rule\n\nCache hits, idempotent replays, every `/v1/utility/*` endpoint except `utility/ai-detection` (1 credit), and `/v1/credits/*` cost 0 credits. Failed calls are refunded, and a request rejected for bad params, a page past the last page, or a rate limit never deducts. Metered endpoints hold an upfront ceiling and refund down to the work done, so the response `credits_used` is the real charge. A band that starts at 0 can settle at 0 (its legs bill only when they return rows), and the top of a wide band is a cap, not the expected charge: `prism/discover` never spends past its `max_credits`. Quote the total for the exact request, not the endpoint's base or unit cost. Scale the gate to the call:\n\n| Call | Gate |\n| --- | --- |\n| Flat price \u2264 5 credits, user asked for it | One line: `\u2248 N credits` |\n| Metered, multi-page, batch, monitor/cohort, or > 25 credits | Full preflight via `estimate.py` / `utility/estimate` |\n| Upfront hold (worst case) > 500 credits or over budget (the user's stated budget) | Ask before calling |\n\nAnything in between, or unsure of the price or params: quote first with the free `GET /v1/utility/estimate?id=<platform/resource>&<params>`. Any reply except a 404 means a current server (a 5xx or network failure is no reply: retry the estimate): use its quote and gate on `hold`, which is the most the request can bill (every page of a `max_pages` or `max_items` walk, and the legs a composite bills itself); `upfront_hold` is only what is deducted when the call starts, and `quote_basis` names the params that were priced, so check it matches the request you will send. `dry_run=1` is then free on any endpoint (validates, fetches nothing). A 404 or `ENDPOINT_NOT_FOUND` means an older server: do **not** send `dry_run=1` (it bills a normal call there, except the labelled dry run an endpoint documents); quote with `scripts/estimate.py` (offline, `assets/endpoints.json`) or the section's **Pricing** line. At every level, report `credits_used` after.\n\n**If the task needs a whole list, price the whole walk before the first page.** Paging to completion multiplies the page cost by the page count, and a heading only shows one page. `instagram/followers` and `instagram/following` are the common case: about 50 accounts a page. A plain walk (5 credits a page) usually ends within a few rows of the profile's count (large verified accounts stop at about 50 rows on every route); `coverage=full` (10 credits a page) is only for a walk that fell short of `data.total`, and at that rate a 2,600-account list is roughly 520 credits, half that on a plain walk. Quote the total and get agreement before starting ([Multi-page walks](references/cost-gate.md#multi-page-walks-coveragefull)).\n\nErrors: classify before retrying with [references/errors.md](references/errors.md), or paste the status and body into the free `GET /v1/utility/explain-error` for the fix. Never retry a 402 unchanged. Credits and balance: `GET /v1/credits/balance` (0 credits); the ledger is `GET /v1/credits/transactions?limit=50`; spend per API key per UTC day (up to 92 days) is `GET /v1/credits/usage?from=&to=&group_by=api_key,day` (both 0 credits). When several agents share one key, have each send `x-client-tag: <name>` (1 to 64 letters, digits, `.`, `_`, `:` or `-`); `GET /v1/credits/usage?group_by=tag` then splits the spend per agent and `GET /v1/credits/transactions?tag=<name>` lists one agent's rows.";
3
+ export declare const ERRORS_GUIDE = "# Errors\n\nRead this when a call fails. The full code table (status, retryable, what to do) is generated in [api-overview.md](api-overview.md#error-codes); the `error.details` reasons are in [api-overview.md](api-overview.md#error-details-errordetails).\n\n**Fastest fix:** paste the failed status and body into the free `GET /v1/utility/explain-error?status=<code>&body=<error JSON>` (add `request=<the path and query you sent>` to get a corrected request back). It returns the fault in plain words, the steps that fix it, and whether retrying the same request can succeed. Nothing is fetched and it costs 0 credits.\n\n## Classify before retrying\n\nBranch on `error.retryable` first, then on `error.details`, never on the status alone.\n\n- **Fix before retrying (`retryable: false`):** `MISSING_API_KEY`, `INVALID_API_KEY`, `INSUFFICIENT_CREDITS`, `KEY_BUDGET_EXCEEDED`, `INVALID_REQUEST`, `METHOD_NOT_ALLOWED` (the `Allow` header names the right verb), `ENDPOINT_NOT_FOUND`, `PAYLOAD_TOO_LARGE`, `IDEMPOTENCY_KEY_CONFLICT`, `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH` (use a fresh key for the changed payload), `IDEMPOTENCY_REPLAY_UNAVAILABLE`, and every `COHORT_*` code. Explain the corrective action and do not repeat the same request.\n- **Wait, then retry the same request:** `RATE_LIMITED`, `CONCURRENCY_LIMIT` (`Retry-After: 1`), `SERVICE_UNAVAILABLE`, and `409 IDEMPOTENCY_IN_PROGRESS` (`Retry-After` 1-30 s; resend with the **same** `Idempotency-Key`). Honour `Retry-After`, then back off exponentially with jitter. A `Retry-After` longer than a minute (for example `3600` for a source that is down in one market) means stop and report, not wait in a loop.\n- **Transient upstream failure:** `UPSTREAM_ERROR` (502, or 504 on a timeout) and `INTERNAL_ERROR`, refunded. If `error.details.retry_with` is present, `retryable` is `false` and there is no `Retry-After`: the same request fails the same way, so resend once with exactly the params it names (for example `proxy=auto` on `web/scrape`). If `error.incident` is present, stop calling that platform and poll `GET /v1/status/{platform}` every few minutes. Otherwise retry at most once, then report the outage with the endpoint and `request_id`, never the credential.\n- **Out of time on our side:** a request still unanswered at 54 s gets the standard error envelope with a request id and `Retry-After`, not the hosting platform's bare 504. A request with under 500 ms of its time left answers a refunded 503 with `Retry-After: 5` instead of starting a source call it cannot finish, and a busy database answers a free `503 SERVICE_UNAVAILABLE` with `Retry-After: 5` within about 3 to 11 s. Wait the `Retry-After`, then resend the identical request once.\n- **Not found:** `RESOURCE_NOT_FOUND` is a valid empty outcome, not a retry loop.\n- **Discover runs and the events feed:** `RUN_NOT_FOUND` / `SCHEDULE_NOT_FOUND` (wrong id, or another account's): list your runs or schedules, or start again. `RUN_STATE_CONFLICT` (409): read the run and do what `data.run.next_step` says (a completed run takes `more`, not `resume`). `RUN_EXPIRED` (410): retention passed, start a new run. `NEEDS_ASYNC` (422): drop `async=false` and follow the 202's `data.next.status_url`. `CURSOR_EXPIRED` (410): restart the feed from `details.oldest_cursor` (or `cursor=oldest`) and tell the user the events in `missed_from`..`missed_until` are gone (30-day retention).\n\n## Act on `error.details`\n\nEvery error carries `error.retryable`, and many carry `error.details.reason`; act on it rather than on the status alone:\n\n- **402** (`balance_too_low`, `key_budget_reached`) always says `retry_will_succeed: false`: **never retry a 402 unchanged**. The same request fails until the balance or that key's limit changes. Point the user at `top_up_url` or `key_settings_url`; `key_name`, `key_prefix` and `account_email_masked`, when present, say which key and account ran out. A key budget is a lifetime cap on that key's net spend (refunds give it back; it never resets on its own), so on `key_budget_reached` the `credits_remaining` is the healthy account balance: the user raises the limit or resets the key's usage in Dashboard \u2192 API Keys, or uses another key. On a metered call `pricing: \"ceiling\"` means the quoted credits are the maximum hold (unused credits are refunded) and `credits_typical` is what a call like it is usually charged; `pricing: \"exact\"` means it is charged what it holds. `lower_cost_options` lists each param that lowers the hold, with the `value` to send (`null`: leave it out) and the `credits_required` it gives, and `credits_required_cheapest` is the hold with all of them. When one of those fits `credits_remaining`, offer the user that smaller request, or a top-up for the full one.\n- **400 `page_limit`** (`max_page`, `narrow_with`): the source has no further pages for this query; stop paging and narrow the query instead. It is the end of the walk, not a failure.\n- **400 with `did_you_mean`**: a parameter or value was misnamed. `error.details.received_unknown` lists the names the endpoint did not recognise, `missing` the required one it did not get, and `did_you_mean` the name it takes (`You sent term; this endpoint takes query`). Resend under that name; it is free.\n- **400 `INVALID_REQUEST` naming a param on a single-source lane** (for example `weibo/profile`, `goodreads/quotes`, `airbnb/search`, `airbnb/listing/availability`): the value you sent is wrong for that source (an id or URL it cannot read, a date it refuses). It is free and final; fix the param named in `error.details.param` and resend. These lanes used to answer a refunded, retryable 502 for the same input, so do not retry one unchanged.\n- **400 `unsupported_date_filter`**: `since` / `until` (or a copied spelling such as `published_after`) on a list whose rows carry no date. Drop the date.\n- **404 `account_gone` / `account_private` / `handle_unresolved`**: follow `error.details.suggestion` once (for a YouTube handle, retry with the stored `channelId` to tell a rename from a removal), then report. `site_not_supported` on `web/scrape` is final; its `suggestion` names the SocialCrawl endpoint for a social link.\n- **404 `ENDPOINT_NOT_FOUND`** may carry `details.did_you_mean` (paths), `did_you_mean_platform` and `retry_with` (the whole corrected URL, for example for a bare `/search`); check the live registry (`GET /v1/utility/endpoints?search=`, free) before saying something is unsupported. On `/v1/web/jobs|monitors|sessions/{id}` it means the id is unknown for this key.\n- **404 `url_unreachable`** on `web/scrape` and `web/extract`: the address is dead or does not resolve. Free and final; check the URL with the user. `site_not_supported` answers the same way on `web/extract` as on `web/scrape`.\n- **503 `breaker_open`**: that source is paused. The request was refused without being sent and was not billed. Until the time the message states, the same request fails the same way; the same request **without the option the message names** works now. With no stated time, wait for `Retry-After`.\n- **503 \"retry the same cursor\"** on a later search page (`facebook/search/posts`, and `not_found_unconfirmed` on `tiktok/search`): refunded. Resend the **same** cursor once later. When that cursor answers empty again on a later request (`facebook/search/posts`: at least 10 minutes after its first empty answer), the answer is a free `200` with `items: []` and `has_more: false`: the walk has ended.\n- **502 `profile_lookup_timeout`** on `tiktok/user/live`: TikTok did not return the account in time. Refunded; retry later.\n- **5xx** carry `error.status_url` and, during an open incident, `error.incident` (`id`, `title`, `status`, `impact`, `url`). A refunded **504** carries `Retry-After: 30`: wait that long before the one automatic retry.\n- **429** bodies carry `error.details` as well as the headers (`reason`, for example `concurrency`, `limit`, `current`, `remaining`, `retry_after_s`), for clients that drop headers.\n\n## Not errors: `data._warnings` and `meta.hint`\n\nA `200` can still carry advice. `data._warnings` reports a parameter that was ignored or cleaned (a `Query:` label stripped from a search term, a `fields=` path that does not exist, with the path it probably meant) and a handle that resolved to a different account. `meta.hint`, at the envelope root, names one other call that does the job in fewer steps; when that call costs more, its `message` says both prices, so follow it only within what the user authorised. It reaches a key at most once a day per pattern, never on an error; send `X-SocialCrawl-Hints: off` to stop it.\n\n## Retrying paid calls\n\nFor a retryable paid non-streaming request, send an `Idempotency-Key` before the first attempt and reuse it only for the identical payload (same params, same `fields`). A GET with `Accept: text/event-stream` cannot carry an `Idempotency-Key` (free 400); do not automatically retry streaming requests. Never exceed one automatic retry unless the user explicitly asks for continued retries.\n\n**Some POSTs ignore `Idempotency-Key`, so never auto-retry them:** `POST /v1/web/agent`, `/v1/web/sessions`, `/v1/web/monitors`, `/v1/web/parse`, `/v1/monitors` and `/v1/trustpilot/reviews/history`. A resend creates (and, where it bills, bills) a second run, session, monitor or job. Read the list route (`GET /v1/web/jobs`, `GET /v1/web/sessions`, `GET /v1/monitors`) to see whether the first one landed. On `POST /v1/web/crawl` and `/v1/web/batch-scrape` a repeated key returns the existing job (200, 0 credits) without comparing the body.\n\n**A client timeout does not cancel the call.** The server finishes it, charges it and writes it to the cache. Resend the identical request (same or new key) and, within the endpoint's cache TTL, it comes back free from cache (`X-Cache: HIT`). Size your timeout from `recommended_timeout_s` in `GET /v1/utility/endpoint?id=` (60 s is safe almost everywhere).\n\nFailed calls are refunded (upstream errors, circuit-breaker rejections, timeouts, not-found, empty results). `credits_used` on an error envelope is the committed net charge: 0 in almost every case, the kept legs on a partially failed composite. A request rejected for bad params, a page past the source's last page, or a rate limit never deducts at all.";
@@ -1,4 +1,4 @@
1
1
  /** The skill's SKILL.md body and errors reference. Generated by scripts/generate-data.ts (T28) - do not hand-edit. */
2
- export const GUIDE = "# SocialCrawl API\n\nOne API key and one response envelope for social, commerce, and research data. Lists are `{ items, next_cursor?, total? }`; add `?format=raw` to skip the transform pipeline. Every file below lives in `references/`; open only the one the task needs.\n\n## API Key\n\nResolve the API key only when a live API call is needed. Documentation, capability, pricing, and code-generation questions do not need a key.\n\nCheck these sources in order without displaying their contents:\n\n1. **Environment variable:** use `SOCIALCRAWL_API_KEY` when it starts with `sc_` and is not an example placeholder.\n2. **Config file:** if the environment variable is absent, load `~/.config/socialcrawl/api_key` into `SOCIALCRAWL_API_KEY` in the current process. On POSIX shells, use `SOCIALCRAWL_API_KEY=\"$(<\"$HOME/.config/socialcrawl/api_key\")\"; export SOCIALCRAWL_API_KEY`. On PowerShell, use `$env:SOCIALCRAWL_API_KEY = (Get-Content -LiteralPath \"$HOME/.config/socialcrawl/api_key\" -Raw).Trim()`.\n3. **Missing key:** tell the user to create or rotate a key at https://socialcrawl.dev/dashboard and configure it as `SOCIALCRAWL_API_KEY` or in `~/.config/socialcrawl/api_key`. Do not ask them to paste a secret into chat. Stop before the live call until they say it is configured.\n\nNever print, paste, log, or return the key. Never place a literal key in generated code, a command, a URL, an error message, or a saved transcript. Keep `$SOCIALCRAWL_API_KEY` (POSIX) or `$env:SOCIALCRAWL_API_KEY` (PowerShell) as a variable reference in examples. If the key appeared in chat or output, advise the user to revoke it in the dashboard and create a replacement.\n\n## First Live Call\n\nBefore the first live call in a session:\n\n1. Resolve the API key using the steps above. If it is missing or a placeholder, stop before making the call.\n2. Verify it with the free balance endpoint (0 credits):\n ```bash\n curl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \"https://www.socialcrawl.dev/v1/credits/balance\"\n ```\n3. If successful, show the balance and continue with the user's request.\n4. If it fails, report the error without including request headers or the key, then follow [references/errors.md](references/errors.md).\n\n## Freshness Check (do this once per session)\n\nThis file is a snapshot of the registry with this fingerprint:\n\n<!-- BEGIN:GENERATED:FRESHNESS (auto-generated by generate-skills.ts - SK-08) -->\n```text\nregistry_fingerprint: e1eecd2aeb103cf5b19dfe45db80fa3e26fe61dc44240813d0e1e5051abd7c62\ngenerated_at: 2026-11-07\n```\n<!-- END:GENERATED:FRESHNESS -->\n\nBeside the balance check, make one free call:\n\n```bash\ncurl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \"https://www.socialcrawl.dev/v1/utility/endpoints?fingerprint=1\" | head -c 400\n```\n\n- **`data.fingerprint` equals `registry_fingerprint` above** - use the bundled files and move on.\n- **It differs** - this copy and the live API are out of sync (the skill or the server may be newer): a price, parameter or endpoint changed. Treat the live registry as the source of truth and resolve what the files cannot answer through `/v1/utility/*` (all free except `utility/ai-detection`, 1 credit). Tell the user **once**, briefly: \"this SocialCrawl skill does not match the live API; run `npx skills update socialcrawl --yes` to refresh it.\" Then answer their actual question. Do not repeat it or ask permission.\n- **No `data.fingerprint`** (a 404, or an older server that answers with the plain list) - fall back to counts: compare `data.stats.platforms` and `data.stats.endpoints` from `/v1/utility/endpoints` with the totals at the top of [references/index.md](references/index.md). Live numbers HIGHER means behind, as above.\n- **The call fails** (no key yet, offline, non-200) - skip it silently. This check must never block the request.\n\n## Workflow\n\n1. **Find the call first (free, 0 credits, runs nothing).** `GET /v1/utility/find?task=<the job in plain words>` ranks the endpoints for the job, each with `method`, `path`, `params_filled` (taken from your words), `missing` and `estimated_credits`. Call `results[0]` directly when `uncertain` is false: its method, path and params are the ready call (add any `missing` param, then apply the Cost rule). When `uncertain` is true, show the options. For a job that needs several calls (a profile, then posts, then comments; a brand watch), `GET /v1/utility/plan?query=<the job>` returns the calls in order with params, price, and which step feeds which. Write or billing requests return no results. `find` and `plan` share a limit of 30 calls a minute and 1,000 a day per key; past it they still answer 200 but with `uncertain: true` keyword guesses, so in a loop over many tasks route from the bundled files.\n2. **Fall back to the bundled files** when offline, when `find` or `plan` answers 404 (an older server: fall back to the existing flow), or when `uncertain` is true. Route with [Common jobs](#common-jobs) below, or grep [references/index.md](references/index.md): its Job to recipe table, then one line per endpoint (`grep -i transcript references/index.md`). For a recipe, read only its section: `grep -n '^## ' references/recipes.md` gives the line numbers; do not open the whole file. For an endpoint, read the platform file's TOC (from the top until the first `## `), then only its section: `grep -nE '^## (GET|POST|PUT|PATCH|DELETE) /v1/<platform>/<resource> - ' references/<platform>.md`, and read from that line to the next `## `. The section carries the exact cost, cache TTL, pagination, every parameter, the response fields, and the constraints checked before billing.\n3. **Estimate.** Build the exact request and apply the cost gate below (one line for a small flat call, the full preflight in [references/cost-gate.md](references/cost-gate.md) for anything metered or large). A heading's number can be a per-row or per-page unit, not the request total.\n4. **Call.** Resolve the key, then run the request exactly as the section shows it, keeping its HTTP method and body shape. If the user already asked to run this exact paid request, the cost disclosure is enough, except the Ask level: always ask (see the gate in the Cost rule); otherwise ask only before a paid call or wider scope they did not authorise.\n5. **Report.** Return the data, then `credits_used` and `credits_remaining`. For an async job report the hold at submission and the settled charge on completion.\n\n## Common jobs\n\nThe first call for the asks agents meet most, generated from the registry recipes (`{x}` is yours to fill). `find` gives the same answer with your values filled in.\n\n<!-- BEGIN:GENERATED:COMMON_JOBS (auto-generated by generate-skills.ts from registry recipes) -->\n| Job | First call | Then |\n|-----|------------|------|\n| Comments on a post to CSV | `GET /v1/tiktok/post/comments?url={url}&sort=recent&scan_pages=3` | `paginate.py` piped to `to_csv.py --archetype Comment`; any platform's `<platform>/post/comments`; [recipe](references/recipes.md#export-the-latest-n-comments-on-a-tiktok-video) |\n| Creators or influencers by niche, size or country | `GET /v1/prism/creators?keywords={niche}&country={country}&min_followers={min_followers}` | a `202` continues in the background (follow `data.next.status_url`); a product to promote goes in `campaign`, creators you already have in `handles` with `purpose`; [guide](https://www.socialcrawl.dev/docs/prism/creators) |\n| A product's reviews across retailers | `GET /v1/prism/product-reviews?query={product}` | covers Amazon, Google Shopping and Trustpilot reviews; Walmart, Target, Home Depot: `<retailer>/reviews`; [recipe](references/recipes.md#one-report-on-a-products-reviews-across-marketplaces) |\n| Stock price and news | `GET /v1/finance/ticker-search?keyword={company}` | then `finance/quote` (`quote.price.current`) and `finance/news`; [recipe](references/recipes.md#a-stocks-current-price-and-latest-headlines) |\n| YouTube transcript | `GET /v1/youtube/video/transcript?url={url}` | [recipe](references/recipes.md#transcribe-a-video) |\n| Alert on new posts or changes | `POST /v1/monitors` (body `recipe: instagram/profile/posts`) | only when `GET /v1/utility/estimate?id=monitors` returns 200, send `?dry_run=1` first to validate and price without creating; otherwise describe the request and create nothing until the user agrees; for a recurring digest of what is new about a topic, keyword or brand, every 1h or slower, call `POST /v1/search/everywhere` with `schedule` (every `1h` or slower, `dry_run` first), at 20 credits a search per fire and only rows that watch has not delivered, read through `GET /v1/events`, a webhook endpoint or the watch's own `last_fire`; a page: `web/monitors`; [recipe](references/recipes.md#track-a-creators-new-posts-every-day) |\n| Stats for a list of post URLs | `POST /v1/prism/post-stats` (JSON body `urls`) | a file of URLs: `batch.py --urls`; [recipe](references/recipes.md#engagement-stats-for-a-list-of-post-urls) |\n| Korean / Naver search | `GET /v1/naver/brief?query={keyword}&corpora=news,blog,cafearticle,kin` | one corpus: `naver/blog/search`, `naver/news/search`; [recipe](references/recipes.md#what-korean-consumers-say-about-a-product-and-search-interest) |\n| Profile lookup | `GET /v1/tiktok/profile?handle={handle}` | any `<platform>/profile`; many handles: `prism/profiles`; [recipe](references/recipes.md#a-creators-profile-recent-posts-and-the-comments-on-them) |\n| Scrape a web page | `GET /v1/web/scrape?url={url}` | structured fields: `web/extract`; a whole site: `web/crawl` |\n| One topic on several platforms | `GET /v1/search/multi?query={topic}&platforms=tiktok,instagram,youtube&relevance=filter` | [recipe](references/recipes.md#search-a-topic-on-several-platforms-at-once) |\n<!-- END:GENERATED:COMMON_JOBS -->\n\n## Helpers\n\nBundled scripts in `scripts/` (Python 3). They read the key from `SOCIALCRAWL_API_KEY` or `~/.config/socialcrawl/api_key` and never print it; `--help` on each gives the rest.\n\n```bash\npython3 scripts/sc.py tiktok/profile handle=nike # one call; JSON to stdout, credits_used to stderr\npython3 scripts/paginate.py tiktok/post/comments --items 500 --max-credits 20 url=<post_url> > rows.jsonl # page to N rows within a budget\npython3 scripts/to_csv.py --archetype Comment --in rows.jsonl --out comments.csv # rows to CSV with stable columns\npython3 scripts/batch.py --urls links.txt > stats.jsonl # stats for a file of post URLs (prism/post-stats, or one prism/jobs job past 500)\npython3 scripts/estimate.py tiktok/post/comments --items 500 --offline url=<post_url> # quote offline from assets/endpoints.json\n```\n\n**Code requests:** read the section and cost-gate, write a snippet that reads `SOCIALCRAWL_API_KEY` from the environment with a comment stating the billing unit, and present it without running it.\n\n**Capability and pricing questions:** answer from the index and [references/pricing.md](references/pricing.md) (cost, tiers, packs, refunds, the free-endpoint list). Auth, envelope, pagination, labels, caching, idempotency: [references/api-overview.md](references/api-overview.md). The free `/v1/utility/*` calls answer from the live registry: `endpoints` (filter `?platform=`, `?search=`), `endpoint?id=tiktok/profile` (one endpoint, with measured field fill rates and production latency), `explain-error` (paste a failed response, get the fix), `plan?query=`, `resolve?input=<url or @handle>` (platform and every endpoint that takes it), `capabilities` (cross-cutting params and where each works), `docs-search?query=`, `recipes`, `quickstart`. `utility/ai-detection` is the one paid utility (1 credit a text).\n\n**Ambiguous platform:** if the user says \"get @nike's profile\" with no platform, ask which one.\n\n## Where to look\n\n| Need | Open |\n|------|------|\n| Any single platform (social, commerce, reviews and places, app stores, search/news/finance, research and dev, link-in-bio) | [index.md](references/index.md) lists every platform file with its endpoint count; open `references/<platform>.md` |\n| One call over many platforms: Prism composites, `search/multi`, `search/everywhere` | [prism.md](references/prism.md), [search.md](references/search.md) |\n| A watch on a known account or post, with webhook delivery (Monitors); a keyword or topic digest is a discover schedule | [monitors.md](references/monitors.md); [discover schedules](references/api-overview.md#discover-schedules-v1prismdiscoverschedules) |\n| Follow, resume, extend or schedule a `prism/discover` run (all free) | [api-overview.md](references/api-overview.md#discover-runs-v1prismdiscoverruns), [schedules](references/api-overview.md#discover-schedules-v1prismdiscoverschedules) |\n| Be told when a discover run or schedule produces something: event feed or signed push | [api-overview.md](references/api-overview.md#account-event-feed-v1events), [webhook endpoints](references/api-overview.md#webhook-endpoints-v1webhook-endpoints) |\n| \"Which of MY list of accounts posted about X\" (Cohorts, not listening) | [cohorts.md](references/cohorts.md) |\n| Cost of a request or a whole paged walk; spend per API key | [cost-gate.md](references/cost-gate.md), [pricing.md](references/pricing.md), [credits usage](references/api-overview.md#credit-balance) |\n| A failed call | [errors.md](references/errors.md) |\n\n> **Never answer \"not supported\" from this table alone.** It is only as new as this file, and a missing row is far more often a stale copy than a real gap. Before telling a user a platform, endpoint or capability does not exist, check the live registry - it is free:\n>\n> ```bash\n> curl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \\\n> \"https://www.socialcrawl.dev/v1/utility/endpoints?search=douyin\"\n> ```\n>\n> Each row carries `path`, `method`, `credits_label`, `required_params`, `one_of`, `optional_params`, `paginated` and `cache_ttl_seconds`: enough to make the call without this file. Only say it is unsupported when the search returns `total: 0`.\n\n**Comparing products across retailers:** Amazon, Walmart, Target, eBay and Home Depot share the canonical Product / Review / Seller schemas, so rows line up. Resolve each retailer's product id (ASIN, item id, TCIN, ...) with its own search, then fetch detail and reviews per retailer. `/v1/prism/product-reviews` is one composite over Amazon, Google Shopping and Trustpilot reviews only; for Walmart, Target or Home Depot call `<retailer>/reviews`.\n\n**Several platforms at once:** To search one platform, call that platform's own search. To search several platforms over a date window with every row judged and de-duplicated, call `/v1/prism/discover`. For a quick fused sweep at a flat 20 credits, call `/v1/search/everywhere`, which drops rows outside `from_date`, `to_date`, `since` or `until` but reads one page per source, so a past window can come back thin. `/v1/prism/discover` answers in the call, or answers `202` with a run you follow at `data.next.status_url` (never resubmit a running request); put 2 to 6 topic words in `keywords` and the user's question in `context` ([guide](https://www.socialcrawl.dev/docs/prism/discover)). `/v1/search/multi` runs one query over several platforms' own search, one page per platform, with an optional `since`/`until` window and no background run (each platform's page price, charged only for those that returned rows). Many profiles or post URLs go to `POST /v1/prism/profiles` / `POST /v1/prism/post-stats`, or the background job `POST /v1/prism/jobs`.\n\n**One fused search:** For one fused, ranked search across the platforms it covers at a flat 20 credits a search, call `/v1/search/everywhere`; for a collection of more than 100 rows or more than one page per platform, call `/v1/prism/discover`; for creators, `/v1/prism/creators`; to be told what is new, send `since_watermark` with the `data.next.watermark` of your last answer, or turn the search into a watch with its `data.next.watch`. ([guide](https://www.socialcrawl.dev/docs/search/everywhere)).\n\n**Creators or influencers:** To find creators or influencers (by topic, market, size, or a product to promote), lookalikes of creators, or to measure and rank a list of creators you already have, call `/v1/prism/creators`. For shops, businesses and sellers, call `/v1/prism/discover` with `view=accounts`. It answers in the call or answers `202` with a run you follow at `data.next.status_url`; put 2 to 6 topic words in `keywords` and what the creators post about in `context`, a product to promote in `campaign`, or creators you already have in `handles` with `purpose` ([guide](https://www.socialcrawl.dev/docs/prism/creators)).\n\n\n**Alerts and recurring watches:** To be told when something new appears, match the ask to its job: for a recurring digest of what is new about a topic, keyword or brand, every 1h or slower, call `POST /v1/search/everywhere` with `schedule` (every `1h` or slower, `dry_run` first), at 20 credits a search per fire and only rows that watch has not delivered, read through `GET /v1/events`, a webhook endpoint or the watch's own `last_fire`; for the new posts or comments of an account or post you already know, call `POST /v1/monitors` with `webhook_rows: \"new\"`; for a one-off check of what is new since your last check, on an endpoint that takes `since` or `since_id`, call the endpoint's own `since` or `since_id` (for example `GET /v1/twitter/tweet/replies` with `since_id`, which returns an empty list and costs nothing when nothing is new); for metric snapshots of accounts you name (followers, views, likes), taken on a schedule, call `POST /v1/monitors` with a `track` metric; for reading what your watches produced, from a feed you poll or an endpoint that receives a signed push, call `GET /v1/events` with a named `consumer` for reading, and `/v1/webhook-endpoints` for push; a keyword or topic alert is never a Monitor.\n\n## Making calls\n\nBase URL `https://www.socialcrawl.dev`. Most endpoints are GET with query parameters (URL-encode values):\n\n```\ncurl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \\\n \"https://www.socialcrawl.dev/v1/{platform}/{resource}?{param}={value}\"\n```\n\n**Never assume the method.** Each endpoint section is headed by its real verb with a runnable curl. Batch reads, Prism jobs, web jobs, monitors, and cohorts use POST, PATCH, PUT, or DELETE with `content-type: application/json` (`web/parse` is multipart); the list, plus streaming (`Accept: text/event-stream`) and two-step endpoints that need an id from an earlier call, is in [api-overview.md](references/api-overview.md#non-get-routes-streaming-and-two-step-endpoints). Rate limits: 600 requests per minute and 50 concurrent per key; both return 429 with `Retry-After` and are never billed. Many endpoints take 10-45 s (task-polled sources, social profiles on a slow day): use a 60 s client timeout, or the endpoint's `recommended_timeout_s` from `GET /v1/utility/endpoint?id=` (free). Never time out early and resend a different request: an aborted call still runs, is charged and is cached, so resend the **identical** request and it comes back from cache at 0 credits. `POST` to `web/agent`, `web/sessions`, `web/monitors`, `web/parse`, `monitors` and `trustpilot/reviews/history` ignores `Idempotency-Key`: never auto-retry those, or you create (and pay for) a second one.\n\n## Reading a response\n\nDetails are in [api-overview.md](references/api-overview.md). Seven rules before the first call:\n\n- **Placement.** `pagination` (`next_cursor`, `has_more`, `page_size`) and the optional `meta.hint` sit at the envelope root. `dropped`, `_warnings` and every page report (`labels`, `relevance`, `label_share`, `hydration`, `walk`, ...) sit inside `data`. Read `data._warnings`: a parameter applied under the endpoint's own name (`sort was applied as sort_by, this endpoint's name for it.`), an ignored one (`limit was ignored: this endpoint's page size is fixed. ...`) or a handle that resolved to a different account (`resolved_to_different_handle`) is reported there, not as an error.\n- **Paging.** Send `pagination.next_cursor` back as `cursor` and stop on `has_more: false`, not on a short page or on `total`. A page with no rows and `has_more: true` is not the end, so call again with `next_cursor`. A page the source returned empty costs nothing. A zero-match list is `200` with `items: []` at 0 credits.\n- **Get more in one call; do not loop.** Every list endpoint takes `max_items=N` (walk pages until N rows), `max_credits=N` (never spend past it) and `max_pages` (1-50). Each page is billed as one call, `data.walk.stopped` says why it ended (`end`, `max_items`, `max_credits`, `time_budget`, ...) and `pagination.next_cursor` resumes ([details](references/api-overview.md#get-more-in-one-call-max_items-max_credits-max_pages)).\n- **Empty lists say why.** Every `items: []` carries `data.empty_reason` and a one-sentence `data.empty_reason_note`: `no_matches`, `end_of_list`, `nothing_new_since` (your `since` / `stop_at_id` poll found nothing new), `window_filtered`, `relevance_filtered`, `row_filtered`, `already_seen`, or `source_empty_unverified`, the only one worth a retry. Tell the user which it is instead of reporting \"no data\" ([codes](references/api-overview.md#empty-lists-empty_reason)).\n- **Default judgments are free.** Comment, post, review and keyword-search rows carry labels (`computed.labels`) and search rows a relevance score (`computed.relevance`) at no extra cost; `judgments=off` returns the raw page. Opt-in presets (`label=spam|toxic|low_quality|quality|ai_style|ai_written|injection|mention|reports|incentivized`, `relevant_to=`) add **1 credit per started 25 freshly judged rows**, held as `ceil(row cap / 25)` and refunded to the rows actually judged. `relevance=filter` against the query itself is free.\n- **Date windows.** `since` / `until` (`YYYY-MM-DD` or a timestamp) work on about 155 dated lists and on `search/everywhere`. On 25 newest-first lists (the creator feeds and some comment, review and search lists) sending `since` sets their recency sort and the page that reaches the date ends the walk (`pagination.stopped_at`); every other list filters each page, keeps its cursor and bills every page walked, so an empty page that still has `next_cursor` is normal: keep paging. `published_after`, `start_date`, `from_date`, `publish_time=this-week` and `max_age_days` are read as `since`; `published_before`, `end_date` and `to_date` as `until` ([date window](references/api-overview.md#date-window-since-until)). A date on a list whose rows carry none is a free 400 (`unsupported_date_filter`).\n- **Spend controls.** Creator post lists also take `stop_at_id`, so a poll pays only for new pages. Keyword searches take `min_views`, `country` / `exclude_country`, `sort_rows=views`, `seen=<id>` (repeats refunded) on top of the walk (**each page billed**).\n- **`meta.hint`** names one other call that does the job in fewer steps. Its message states the price when that call costs more; follow it only within what the user authorised.\n\n`include=` hydration joins rows to a sibling endpoint and is charged **per row on top of the page**, so never quote the plain heading cost for a hydrated call; the ceilings are in [cost-gate.md](references/cost-gate.md#row-hydration-include) and the traps in [api-overview.md](references/api-overview.md#row-hydration-include).\n\n## Cost rule\n\nCache hits, idempotent replays, every `/v1/utility/*` endpoint except `utility/ai-detection` (1 credit), and `/v1/credits/*` cost 0 credits. Failed calls are refunded, and a request rejected for bad params, a page past the last page, or a rate limit never deducts. Metered endpoints hold an upfront ceiling and refund down to the work done, so the response `credits_used` is the real charge. A band that starts at 0 can settle at 0 (its legs bill only when they return rows), and the top of a wide band is a cap, not the expected charge: `prism/discover` never spends past its `max_credits`. Quote the total for the exact request, not the endpoint's base or unit cost. Scale the gate to the call:\n\n| Call | Gate |\n| --- | --- |\n| Flat price ≤ 5 credits, user asked for it | One line: `≈ N credits` |\n| Metered, multi-page, batch, monitor/cohort, or > 25 credits | Full preflight via `estimate.py` / `utility/estimate` |\n| Upfront hold (worst case) > 500 credits or over budget (the user's stated budget) | Ask before calling |\n\nAnything in between, or unsure of the price or params: quote first with the free `GET /v1/utility/estimate?id=<platform/resource>&<params>`. Any reply except a 404 means a current server (a 5xx or network failure is no reply: retry the estimate): use its quote, and `dry_run=1` is then free on any endpoint (validates, fetches nothing). A 404 or `ENDPOINT_NOT_FOUND` means an older server: do **not** send `dry_run=1` (it bills a normal call there, except the labelled dry run an endpoint documents); quote with `scripts/estimate.py` (offline, `assets/endpoints.json`) or the section's **Pricing** line. At every level, report `credits_used` after.\n\n**If the task needs a whole list, price the whole walk before the first page.** Paging to completion multiplies the page cost by the page count, and a heading only shows one page. `instagram/followers` and `instagram/following` are the common case: about 50 accounts a page. A plain walk (5 credits a page) usually ends within a few rows of the profile's count (large verified accounts stop at about 50 rows on every route); `coverage=full` (10 credits a page) is only for a walk that fell short of `data.total`, and at that rate a 2,600-account list is roughly 520 credits, half that on a plain walk. Quote the total and get agreement before starting ([Multi-page walks](references/cost-gate.md#multi-page-walks-coveragefull)).\n\nErrors: classify before retrying with [references/errors.md](references/errors.md), or paste the status and body into the free `GET /v1/utility/explain-error` for the fix. Never retry a 402 unchanged. Credits and balance: `GET /v1/credits/balance` (0 credits); the ledger is `GET /v1/credits/transactions?limit=50`; spend per API key per UTC day (up to 92 days) is `GET /v1/credits/usage?from=&to=&group_by=api_key,day` (both 0 credits).";
3
- export const ERRORS_GUIDE = "# Errors\n\nRead this when a call fails. The full code table (status, retryable, what to do) is generated in [api-overview.md](api-overview.md#error-codes); the `error.details` reasons are in [api-overview.md](api-overview.md#error-details-errordetails).\n\n**Fastest fix:** paste the failed status and body into the free `GET /v1/utility/explain-error?status=<code>&body=<error JSON>` (add `request=<the path and query you sent>` to get a corrected request back). It returns the fault in plain words, the steps that fix it, and whether retrying the same request can succeed. Nothing is fetched and it costs 0 credits.\n\n## Classify before retrying\n\nBranch on `error.retryable` first, then on `error.details`, never on the status alone.\n\n- **Fix before retrying (`retryable: false`):** `MISSING_API_KEY`, `INVALID_API_KEY`, `INSUFFICIENT_CREDITS`, `KEY_BUDGET_EXCEEDED`, `INVALID_REQUEST`, `METHOD_NOT_ALLOWED` (the `Allow` header names the right verb), `ENDPOINT_NOT_FOUND`, `PAYLOAD_TOO_LARGE`, `IDEMPOTENCY_KEY_CONFLICT`, `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH` (use a fresh key for the changed payload), `IDEMPOTENCY_REPLAY_UNAVAILABLE`, and every `COHORT_*` code. Explain the corrective action and do not repeat the same request.\n- **Wait, then retry the same request:** `RATE_LIMITED`, `CONCURRENCY_LIMIT` (`Retry-After: 1`), `SERVICE_UNAVAILABLE`, and `409 IDEMPOTENCY_IN_PROGRESS` (`Retry-After` 1-30 s; resend with the **same** `Idempotency-Key`). Honour `Retry-After`, then back off exponentially with jitter. A `Retry-After` longer than a minute (for example `3600` for a source that is down in one market) means stop and report, not wait in a loop.\n- **Transient upstream failure:** `UPSTREAM_ERROR` (502, or 504 on a timeout) and `INTERNAL_ERROR`, refunded. If `error.details.retry_with` is present, `retryable` is `false` and there is no `Retry-After`: the same request fails the same way, so resend once with exactly the params it names (for example `proxy=auto` on `web/scrape`). If `error.incident` is present, stop calling that platform and poll `GET /v1/status/{platform}` every few minutes. Otherwise retry at most once, then report the outage with the endpoint and `request_id`, never the credential.\n- **Not found:** `RESOURCE_NOT_FOUND` is a valid empty outcome, not a retry loop.\n- **Discover runs and the events feed:** `RUN_NOT_FOUND` / `SCHEDULE_NOT_FOUND` (wrong id, or another account's): list your runs or schedules, or start again. `RUN_STATE_CONFLICT` (409): read the run and do what `data.run.next_step` says (a completed run takes `more`, not `resume`). `RUN_EXPIRED` (410): retention passed, start a new run. `NEEDS_ASYNC` (422): drop `async=false` and follow the 202's `data.next.status_url`. `CURSOR_EXPIRED` (410): restart the feed from `details.oldest_cursor` (or `cursor=oldest`) and tell the user the events in `missed_from`..`missed_until` are gone (30-day retention).\n\n## Act on `error.details`\n\nEvery error carries `error.retryable`, and many carry `error.details.reason`; act on it rather than on the status alone:\n\n- **402** (`balance_too_low`, `key_budget_reached`) always says `retry_will_succeed: false`: **never retry a 402 unchanged**. The same request fails until the balance or that key's limit changes. Point the user at `top_up_url` or `key_settings_url`; `key_name`, `key_prefix` and `account_email_masked`, when present, say which key and account ran out. A key budget is a lifetime cap on that key's net spend (refunds give it back; it never resets on its own), so on `key_budget_reached` the `credits_remaining` is the healthy account balance: the user raises the limit or resets the key's usage in Dashboard → API Keys, or uses another key. On a metered call `pricing: \"ceiling\"` means the quoted credits are the maximum hold (unused credits are refunded) and `credits_typical` is what a call like it is usually charged; `pricing: \"exact\"` means it is charged what it holds. `lower_cost_options` lists each param that lowers the hold, with the `value` to send (`null`: leave it out) and the `credits_required` it gives, and `credits_required_cheapest` is the hold with all of them. When one of those fits `credits_remaining`, offer the user that smaller request, or a top-up for the full one.\n- **400 `page_limit`** (`max_page`, `narrow_with`): the source has no further pages for this query; stop paging and narrow the query instead. It is the end of the walk, not a failure.\n- **400 with `did_you_mean`**: a parameter or value was misnamed. `error.details.received_unknown` lists the names the endpoint did not recognise, `missing` the required one it did not get, and `did_you_mean` the name it takes (`You sent term; this endpoint takes query`). Resend under that name; it is free.\n- **400 `unsupported_date_filter`**: `since` / `until` (or a copied spelling such as `published_after`) on a list whose rows carry no date. Drop the date.\n- **404 `account_gone` / `account_private` / `handle_unresolved`**: follow `error.details.suggestion` once (for a YouTube handle, retry with the stored `channelId` to tell a rename from a removal), then report. `site_not_supported` on `web/scrape` is final; its `suggestion` names the SocialCrawl endpoint for a social link.\n- **404 `ENDPOINT_NOT_FOUND`** may carry `details.did_you_mean` (paths), `did_you_mean_platform` and `retry_with` (the whole corrected URL, for example for a bare `/search`); check the live registry (`GET /v1/utility/endpoints?search=`, free) before saying something is unsupported. On `/v1/web/jobs|monitors|sessions/{id}` it means the id is unknown for this key.\n- **5xx** carry `error.status_url` and, during an open incident, `error.incident` (`id`, `title`, `status`, `impact`, `url`).\n\n## Not errors: `data._warnings` and `meta.hint`\n\nA `200` can still carry advice. `data._warnings` reports a parameter that was ignored or cleaned (a `Query:` label stripped from a search term, a `fields=` path that does not exist, with the path it probably meant) and a handle that resolved to a different account. `meta.hint`, at the envelope root, names one other call that does the job in fewer steps; when that call costs more, its `message` says both prices, so follow it only within what the user authorised. It reaches a key at most once a day per pattern, never on an error; send `X-SocialCrawl-Hints: off` to stop it.\n\n## Retrying paid calls\n\nFor a retryable paid non-streaming request, send an `Idempotency-Key` before the first attempt and reuse it only for the identical payload (same params, same `fields`). A GET with `Accept: text/event-stream` cannot carry an `Idempotency-Key` (free 400); do not automatically retry streaming requests. Never exceed one automatic retry unless the user explicitly asks for continued retries.\n\n**Some POSTs ignore `Idempotency-Key`, so never auto-retry them:** `POST /v1/web/agent`, `/v1/web/sessions`, `/v1/web/monitors`, `/v1/web/parse`, `/v1/monitors` and `/v1/trustpilot/reviews/history`. A resend creates (and, where it bills, bills) a second run, session, monitor or job. Read the list route (`GET /v1/web/jobs`, `GET /v1/web/sessions`, `GET /v1/monitors`) to see whether the first one landed. On `POST /v1/web/crawl` and `/v1/web/batch-scrape` a repeated key returns the existing job (200, 0 credits) without comparing the body.\n\n**A client timeout does not cancel the call.** The server finishes it, charges it and writes it to the cache. Resend the identical request (same or new key) and, within the endpoint's cache TTL, it comes back free from cache (`X-Cache: HIT`). Size your timeout from `recommended_timeout_s` in `GET /v1/utility/endpoint?id=` (60 s is safe almost everywhere).\n\nFailed calls are refunded (upstream errors, circuit-breaker rejections, timeouts, not-found, empty results). `credits_used` on an error envelope is the committed net charge: 0 in almost every case, the kept legs on a partially failed composite. A request rejected for bad params, a page past the source's last page, or a rate limit never deducts at all.";
2
+ export const GUIDE = "# SocialCrawl API\n\nOne API key and one response envelope for social, commerce, and research data. Lists are `{ items, next_cursor?, total? }`; add `?format=raw` to skip the transform pipeline. Every file below lives in `references/`; open only the one the task needs.\n\n## API Key\n\nResolve the API key only when a live API call is needed. Documentation, capability, pricing, and code-generation questions do not need a key.\n\nCheck these sources in order without displaying their contents:\n\n1. **Environment variable:** use `SOCIALCRAWL_API_KEY` when it starts with `sc_` and is not an example placeholder.\n2. **Config file:** if the environment variable is absent, load `~/.config/socialcrawl/api_key` into `SOCIALCRAWL_API_KEY` in the current process. On POSIX shells, use `SOCIALCRAWL_API_KEY=\"$(<\"$HOME/.config/socialcrawl/api_key\")\"; export SOCIALCRAWL_API_KEY`. On PowerShell, use `$env:SOCIALCRAWL_API_KEY = (Get-Content -LiteralPath \"$HOME/.config/socialcrawl/api_key\" -Raw).Trim()`.\n3. **Missing key:** tell the user to create or rotate a key at https://socialcrawl.dev/dashboard and configure it as `SOCIALCRAWL_API_KEY` or in `~/.config/socialcrawl/api_key`. Do not ask them to paste a secret into chat. Stop before the live call until they say it is configured.\n\nNever print, paste, log, or return the key. Never place a literal key in generated code, a command, a URL, an error message, or a saved transcript. Keep `$SOCIALCRAWL_API_KEY` (POSIX) or `$env:SOCIALCRAWL_API_KEY` (PowerShell) as a variable reference in examples. If the key appeared in chat or output, advise the user to revoke it in the dashboard and create a replacement.\n\n## First Live Call\n\nBefore the first live call in a session:\n\n1. Resolve the API key using the steps above. If it is missing or a placeholder, stop before making the call.\n2. Verify it with the free balance endpoint (0 credits):\n ```bash\n curl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \"https://www.socialcrawl.dev/v1/credits/balance\"\n ```\n3. If successful, show the user `data.balance` (it equals `credits_remaining`) and continue with the user's request. Do not print the whole response: it also carries account links (`top_up_url`, `checkout_url`) that belong to the account owner and should stay out of transcripts and logs. Share `checkout_url` only with the account owner when `runway.days_left` is under 3; it opens checkout only after they sign in to the dashboard.\n4. If it fails, report the error without including request headers or the key, then follow [references/errors.md](references/errors.md).\n\n## Freshness Check (do this once per session)\n\nThis file is a snapshot of the registry with this fingerprint:\n\n<!-- BEGIN:GENERATED:FRESHNESS (auto-generated by generate-skills.ts - SK-08) -->\n```text\nregistry_fingerprint: 7ae238a672d167c1d9b41e01b19992ac5e988b23433fe43ee17d4ec209af9fa4\ngenerated_at: 2026-11-30\n```\n<!-- END:GENERATED:FRESHNESS -->\n\nBeside the balance check, make one free call:\n\n```bash\ncurl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \"https://www.socialcrawl.dev/v1/utility/endpoints?fingerprint=1\" | head -c 400\n```\n\n- **`data.fingerprint` equals `registry_fingerprint` above** - use the bundled files and move on.\n- **It differs** - this copy and the live API are out of sync (the skill or the server may be newer): a price, parameter or endpoint changed. Treat the live registry as the source of truth. For the section a task needs, read the current copy of this skill, published with every deploy and readable with no API key: https://www.socialcrawl.dev/skills/socialcrawl/references/<platform>.md (same file names and headings as here; https://www.socialcrawl.dev/skills/socialcrawl/SKILL.md for this file), and resolve exact prices and params through `/v1/utility/*` (all free except `utility/ai-detection`, 1 credit). Tell the user **once**, briefly: \"this SocialCrawl skill does not match the live API; run `npx skills update socialcrawl --yes` to refresh it.\" When it was installed as a Claude Code plugin, the command is `claude plugin update socialcrawl@socialcrawl` instead. If you can run shell commands, offer once to run that update for them and run it only on a yes, then re-read this file. A copy uploaded to claude.ai is refreshed by uploading the latest package, https://github.com/socialcrawl/skills/raw/main/socialcrawl.skill. Then answer their actual question. Do not repeat it.\n- **No `data.fingerprint`** (a 404, or an older server that answers with the plain list) - fall back to counts: compare `data.stats.platforms` and `data.stats.endpoints` from `/v1/utility/endpoints` with the totals at the top of [references/index.md](references/index.md). Live numbers HIGHER means behind, as above.\n- **The call fails** (no key yet, offline, non-200) - skip it silently. This check must never block the request.\n\n## Workflow\n\n1. **Find the call first (free, 0 credits, runs nothing).** `GET /v1/utility/find?task=<the job in plain words>` ranks the endpoints for the job, each with `method`, `path`, `params_filled` (taken from your words), `missing`, `estimated_credits` (the most that call can cost with the params shown) and `credits_ceiling` (the most it can cost once the params in `ceiling_params` are added too, such as `coverage=full` or a higher `limit`). Call `results[0]` directly when `uncertain` is false: its method, path and params are the ready call (add any `missing` param, then apply the Cost rule). Before you add a param the row did not fill, gate on `credits_ceiling`, not `estimated_credits`. Check `params_filled` against the task: a search value should be the product or topic name only, and `country`/`language` filled from Hangul (KR, ko) are marked in `inferred_params`. When `uncertain` is true, show the options. For a job that needs several calls (a profile, then posts, then comments; a brand watch), `GET /v1/utility/plan?query=<the job>` returns the calls in order with params, price, and which step feeds which. Write or billing requests return no results. `find` and `plan` share a limit of 30 calls a minute and 1,000 a day per key; past it they still answer 200 but with `uncertain: true` keyword guesses, so in a loop over many tasks route from the bundled files.\n2. **Fall back to the bundled files** when offline, when `find` or `plan` answers 404 (an older server: fall back to the existing flow), or when `uncertain` is true. Route with [Common jobs](#common-jobs) below, or grep [references/index.md](references/index.md): its Job to recipe table, then one line per endpoint (`grep -i transcript references/index.md`). For a recipe, read only its section: `grep -n '^## ' references/recipes.md` gives the line numbers; do not open the whole file. For an endpoint, read the platform file's TOC (from the top until the first `## `), then only its section: `grep -nE '^## (GET|POST|PUT|PATCH|DELETE) /v1/<platform>/<resource> - ' references/<platform>.md`, and read from that line to the next `## `. The section carries the exact cost, cache TTL, pagination, every parameter, the response fields, and the constraints checked before billing.\n3. **Estimate.** Build the exact request and apply the cost gate below (one line for a small flat call, the full preflight in [references/cost-gate.md](references/cost-gate.md) for anything metered or large). A heading's number can be a per-row or per-page unit, not the request total. **When an endpoint's heading price is a range** (`1-178 credits`), its price depends on its params: read `GET /v1/utility/endpoint?id=<platform/resource>` (free) for the live price rule before calling, then quote the exact request with `utility/estimate`, even when this copy of the skill matches the live fingerprint.\n4. **Call.** Resolve the key, then run the request exactly as the section shows it, keeping its HTTP method and body shape. If the user already asked to run this exact paid request, the cost disclosure is enough, except the Ask level: always ask (see the gate in the Cost rule); otherwise ask only before a paid call or wider scope they did not authorise.\n5. **Report.** Return the data, then `credits_used` and `credits_remaining`. For an async job report the hold at submission and the settled charge on completion.\n\n## Common jobs\n\nThe first call for the asks agents meet most, generated from the registry recipes (`{x}` is yours to fill). `find` gives the same answer with your values filled in.\n\n<!-- BEGIN:GENERATED:COMMON_JOBS (auto-generated by generate-skills.ts from registry recipes) -->\n| Job | First call | Then |\n|-----|------------|------|\n| Comments on a post to CSV | `GET /v1/tiktok/post/comments?url={url}&sort=recent&scan_pages=3` | `paginate.py` piped to `to_csv.py --archetype Comment`; any platform's `<platform>/post/comments`; [recipe](references/recipes.md#export-the-latest-n-comments-on-a-tiktok-video) |\n| Creators or influencers by niche, size or country | `GET /v1/prism/creators?keywords={niche}&country={country}&min_followers={min_followers}` | a `202` continues in the background (follow `data.next.status_url`); a product to promote goes in `campaign`, creators you already have in `handles` with `purpose`; [guide](https://www.socialcrawl.dev/docs/prism/creators) |\n| A product's reviews across retailers | `GET /v1/prism/product-reviews?query={product}` | covers Amazon, Google Shopping and Trustpilot reviews; Walmart, Target, Home Depot: `<retailer>/reviews`; [recipe](references/recipes.md#one-report-on-a-products-reviews-across-marketplaces) |\n| Stock price and news | `GET /v1/finance/ticker-search?keyword={company}` | then `finance/quote` (`quote.price.current`) and `finance/news`; [recipe](references/recipes.md#a-stocks-current-price-and-latest-headlines) |\n| YouTube transcript | `GET /v1/youtube/video/transcript?url={url}` | [recipe](references/recipes.md#transcribe-a-video) |\n| Alert on new posts or changes | `POST /v1/monitors` (body `recipe: instagram/profile/posts`) | only when `GET /v1/utility/estimate?id=monitors` returns 200, send `?dry_run=1` first to validate and price without creating; otherwise describe the request and create nothing until the user agrees; for a recurring digest of what is new about a topic, keyword or brand, every 1h or slower, call `POST /v1/search/everywhere` with `schedule` (every `1h` or slower, `dry_run` first), at 20 credits a search per fire and only rows that watch has not delivered, read through `GET /v1/events`, a webhook endpoint or the watch's own `last_fire`; a page: `web/monitors`; [recipe](references/recipes.md#track-a-creators-new-posts-every-day) |\n| Stats for a list of post URLs | `POST /v1/prism/post-stats` (JSON body `urls`) | a file of URLs: `batch.py --urls`; [recipe](references/recipes.md#engagement-stats-for-a-list-of-post-urls) |\n| Korean / Naver search | `GET /v1/naver/brief?query={keyword}&corpora=news,blog,cafearticle,kin` | one corpus: `naver/blog/search`, `naver/news/search`; [recipe](references/recipes.md#what-korean-consumers-say-about-a-product-and-search-interest) |\n| Profile lookup | `GET /v1/tiktok/profile?handle={handle}` | any `<platform>/profile`; many handles: `prism/profiles`; [recipe](references/recipes.md#a-creators-profile-recent-posts-and-the-comments-on-them) |\n| Scrape a web page | `GET /v1/web/scrape?url={url}` | structured fields: `web/extract`; a whole site: `web/crawl` |\n| One topic on several platforms | `GET /v1/search/multi?query={topic}&platforms=tiktok,instagram,youtube&relevance=filter` | [recipe](references/recipes.md#search-a-topic-on-several-platforms-at-once) |\n<!-- END:GENERATED:COMMON_JOBS -->\n\n## Helpers\n\nBundled scripts in `scripts/` (Python 3). They read the key from `SOCIALCRAWL_API_KEY` or `~/.config/socialcrawl/api_key` and never print it; `--help` on each gives the rest.\n\n```bash\npython3 scripts/sc.py tiktok/profile handle=nike # one call; JSON to stdout, credits_used to stderr\npython3 scripts/paginate.py tiktok/post/comments --items 500 --max-credits 20 url=<post_url> > rows.jsonl # page to N rows within a budget\npython3 scripts/to_csv.py --archetype Comment --in rows.jsonl --out comments.csv # rows to CSV with stable columns\npython3 scripts/batch.py --urls links.txt > stats.jsonl # stats for a file of post URLs (prism/post-stats, or one prism/jobs job past 500)\npython3 scripts/estimate.py tiktok/post/comments --items 500 --offline url=<post_url> # quote offline from assets/endpoints.json\n```\n\n**Code requests:** read the section and cost-gate, write a snippet that reads `SOCIALCRAWL_API_KEY` from the environment with a comment stating the billing unit, and present it without running it.\n\n**Capability and pricing questions:** answer from the index and [references/pricing.md](references/pricing.md) (cost, tiers, packs, refunds, the free-endpoint list). Auth, envelope, pagination, labels, caching, idempotency: [references/api-overview.md](references/api-overview.md). The free `/v1/utility/*` calls answer from the live registry: `endpoints` (filter `?platform=`, `?search=`), `endpoint?id=tiktok/profile` (one endpoint, with measured field fill rates and production latency), `explain-error` (paste a failed response, get the fix), `plan?query=`, `resolve?input=<url or @handle>` (platform and every endpoint that takes it), `capabilities` (cross-cutting params and where each works), `docs-search?query=`, `recipes`, `quickstart`. `utility/ai-detection` is the one paid utility (1 credit a text).\n\n**Ambiguous platform:** if the user says \"get @nike's profile\" with no platform, ask which one.\n\n## Where to look\n\n| Need | Open |\n|------|------|\n| Any single platform (social, commerce, reviews and places, app stores, search/news/finance, research and dev, link-in-bio) | [index.md](references/index.md) lists every platform file with its endpoint count; open `references/<platform>.md` |\n| One call over many platforms: Prism composites, `search/multi`, `search/everywhere` | [prism.md](references/prism.md), [search.md](references/search.md) |\n| A watch on a known account or post, with webhook delivery (Monitors); a keyword or topic digest is a discover schedule | [monitors.md](references/monitors.md); [discover schedules](references/api-overview.md#discover-schedules-v1prismdiscoverschedules) |\n| Follow, resume, extend or schedule a `prism/discover` run (all free) | [api-overview.md](references/api-overview.md#discover-runs-v1prismdiscoverruns), [schedules](references/api-overview.md#discover-schedules-v1prismdiscoverschedules) |\n| Be told when a discover run or schedule produces something: event feed or signed push | [api-overview.md](references/api-overview.md#account-event-feed-v1events), [webhook endpoints](references/api-overview.md#webhook-endpoints-v1webhook-endpoints) |\n| \"Which of MY list of accounts posted about X\" (Cohorts, not listening) | [cohorts.md](references/cohorts.md) |\n| Cost of a request or a whole paged walk; spend per API key | [cost-gate.md](references/cost-gate.md), [pricing.md](references/pricing.md), [credits usage](references/api-overview.md#credit-balance) |\n| A failed call | [errors.md](references/errors.md) |\n\n> **Never answer \"not supported\" from this table alone.** It is only as new as this file, and a missing row is far more often a stale copy than a real gap. Before telling a user a platform, endpoint or capability does not exist, check the live registry - it is free:\n>\n> ```bash\n> curl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \\\n> \"https://www.socialcrawl.dev/v1/utility/endpoints?search=douyin\"\n> ```\n>\n> Each row carries `path`, `method`, `credits_label`, `required_params`, `one_of`, `optional_params`, `paginated` and `cache_ttl_seconds`: enough to make the call without this file. Only say it is unsupported when the search returns `total: 0`.\n\n**Comparing products across retailers:** Amazon, Walmart, Target, eBay and Home Depot share the canonical Product / Review / Seller schemas, so rows line up. Resolve each retailer's product id (ASIN, item id, TCIN, ...) with its own search, then fetch detail and reviews per retailer. `/v1/prism/product-reviews` is one composite over Amazon, Google Shopping and Trustpilot reviews only; for Walmart, Target or Home Depot call `<retailer>/reviews`.\n\n**Several platforms at once:** To search one platform, call that platform's own search. To search several platforms over a date window with every row judged and de-duplicated, call `/v1/prism/discover`. For a quick fused sweep at a flat 20 credits, call `/v1/search/everywhere`, which drops rows outside `from_date`, `to_date`, `since` or `until` but reads one page per source, so a past window can come back thin. `/v1/prism/discover` answers in the call, or answers `202` with a run you follow at `data.next.status_url` (never resubmit a running request); put 2 to 6 topic words in `keywords` and the user's question in `context` ([guide](https://www.socialcrawl.dev/docs/prism/discover)). `/v1/search/multi` runs one query over several platforms' own search, one page per platform, with an optional `since`/`until` window and no background run (each platform's page price, charged only for those that returned rows). Many profiles or post URLs go to `POST /v1/prism/profiles` / `POST /v1/prism/post-stats`, or the background job `POST /v1/prism/jobs`.\n\n**One fused search:** For one fused, ranked search across the platforms it covers at a flat 20 credits a search, call `/v1/search/everywhere`; for a collection of more than 100 rows or more than one page per platform, call `/v1/prism/discover`; for creators, `/v1/prism/creators`; to be told what is new, send `since_watermark` with the `data.next.watermark` of your last answer, or turn the search into a watch with its `data.next.watch`. ([guide](https://www.socialcrawl.dev/docs/search/everywhere)).\n\n**Creators or influencers:** To find creators or influencers (by topic, market, size, or a product to promote), lookalikes of creators, or to measure and rank a list of creators you already have, call `/v1/prism/creators`. For shops, businesses and sellers, call `/v1/prism/discover` with `view=accounts`. It answers in the call or answers `202` with a run you follow at `data.next.status_url`; put 2 to 6 topic words in `keywords` and what the creators post about in `context`, a product to promote in `campaign`, or creators you already have in `handles` with `purpose` ([guide](https://www.socialcrawl.dev/docs/prism/creators)).\n\n\n**Alerts and recurring watches:** To be told when something new appears, match the ask to its job: for a recurring digest of what is new about a topic, keyword or brand, every 1h or slower, call `POST /v1/search/everywhere` with `schedule` (every `1h` or slower, `dry_run` first), at 20 credits a search per fire and only rows that watch has not delivered, read through `GET /v1/events`, a webhook endpoint or the watch's own `last_fire`; for the new posts or comments of an account or post you already know, call `POST /v1/monitors` with `webhook_rows: \"new\"`; for a one-off check of what is new since your last check, on an endpoint that takes `since` or `since_id`, call the endpoint's own `since` or `since_id` (for example `GET /v1/twitter/tweet/replies` with `since_id`, which returns an empty list and costs nothing when nothing is new); for metric snapshots of accounts you name (followers, views, likes), taken on a schedule, call `POST /v1/monitors` with a `track` metric; for reading what your watches produced, from a feed you poll or an endpoint that receives a signed push, call `GET /v1/events` with a named `consumer` for reading, and `/v1/webhook-endpoints` for push; a keyword or topic alert is never a Monitor.\n\n## Making calls\n\nBase URL `https://www.socialcrawl.dev`. Most endpoints are GET with query parameters (URL-encode values):\n\n```\ncurl -s -H \"x-api-key: $SOCIALCRAWL_API_KEY\" \\\n \"https://www.socialcrawl.dev/v1/{platform}/{resource}?{param}={value}\"\n```\n\n**Never assume the method.** Each endpoint section is headed by its real verb with a runnable curl. Batch reads, Prism jobs, web jobs, monitors, and cohorts use POST, PATCH, PUT, or DELETE with `content-type: application/json` (`web/parse` is multipart); the list, plus streaming (`Accept: text/event-stream`) and two-step endpoints that need an id from an earlier call, is in [api-overview.md](references/api-overview.md#non-get-routes-streaming-and-two-step-endpoints). Rate limits: 600 requests per minute and 50 concurrent per key; both return 429 with `Retry-After` and are never billed. Many endpoints take 10-45 s (task-polled sources, social profiles on a slow day): use a 60 s client timeout, or the endpoint's `recommended_timeout_s` from `GET /v1/utility/endpoint?id=` (free). Never time out early and resend a different request: an aborted JSON call still runs, is charged and is cached, so resend the **identical** request and it comes back from cache at 0 credits. A streamed call (`Accept: text/event-stream`) that you abort is refunded and is not cached, so its resend is billed as a new call. A 429 body repeats the wait as `error.details.retry_after_s`; a 504 with `error.details.reason: \"task_queued\"` is picked up by the identical request within the hour, or send it with `Prefer: respond-async` for a job to poll at `data.next.status_url`. `POST` to `web/agent`, `web/sessions`, `web/monitors`, `web/parse`, `monitors` and `trustpilot/reviews/history` ignores `Idempotency-Key`: never auto-retry those, or you create (and pay for) a second one.\n\n## Reading a response\n\nDetails are in [api-overview.md](references/api-overview.md). Seven rules before the first call:\n\n- **Placement.** `pagination` (`next_cursor`, `has_more`, `page_size`) and the optional `meta.hint` sit at the envelope root. `dropped`, `_warnings` and every page report (`labels`, `relevance`, `label_share`, `hydration`, `walk`, ...) sit inside `data`. Read `data._warnings`: a parameter applied under the endpoint's own name (`sort was applied as sort_by, this endpoint's name for it.`), an ignored one (`limit was ignored: this endpoint's page size is fixed. ...`) or a handle that resolved to a different account (`resolved_to_different_handle`) is reported there, not as an error.\n- **Paging.** Send `pagination.next_cursor` back as `cursor` and stop on `has_more: false`, not on a short page or on `total`. A page with no rows and `has_more: true` is not the end, so call again with `next_cursor`. A page the source returned empty costs nothing; a page your `since` or `until` emptied costs what a page costs. A zero-match list is `200` with `items: []` at 0 credits.\n- **Get more in one call; do not loop.** Most list endpoints take `max_items=N` (walk pages until N rows), `max_credits=N` (never spend past it) and `max_pages` (1-50); check the endpoint's parameters first, because self-walking endpoints, the `-full` lanes, job reads and `prism/discover` do not. Each page is billed as one call, `data.walk.stopped` says why it ended (`end`, `max_items`, `max_credits`, `time_budget`, ...) and `pagination.next_cursor` resumes ([details](references/api-overview.md#get-more-in-one-call-max_items-max_credits-max_pages)).\n- **Empty lists say why.** Every `items: []` carries `data.empty_reason` and a one-sentence `data.empty_reason_note`: `no_matches`, `end_of_list`, `nothing_new_since` (your `since` / `stop_at_id` poll found nothing new), `window_filtered`, `relevance_filtered`, `row_filtered`, `already_seen`, or `source_empty_unverified`, the only one worth a retry. Tell the user which it is instead of reporting \"no data\" ([codes](references/api-overview.md#empty-lists-empty_reason)).\n- **Default judgments are free.** Comment, post, review and keyword-search rows carry labels (`computed.labels`) and search rows a relevance score (`computed.relevance`) at no extra cost; `judgments=off` returns the raw page. Opt-in presets (`label=spam|toxic|low_quality|quality|ai_style|ai_written|injection|mention|reports|incentivized`, `relevant_to=`) add **1 credit per started 25 freshly judged rows**, held as `ceil(row cap / 25)` and refunded to the rows actually judged. `relevance=filter` against the query itself is free.\n- **Date windows.** `since` / `until` (`YYYY-MM-DD` or a timestamp) work on about 155 dated lists and on `search/everywhere`. On 25 newest-first lists (the creator feeds and some comment, review and search lists) sending `since` sets their recency sort and the page that reaches the date ends the walk (`pagination.stopped_at`); every other list filters each page, keeps its cursor and bills every page walked, so an empty page that still has `next_cursor` is normal: keep paging. `published_after`, `start_date`, `from_date`, `publish_time=this-week` and `max_age_days` are read as `since`; `published_before`, `end_date` and `to_date` as `until` ([date window](references/api-overview.md#date-window-since-until)). A date on a list whose rows carry none is a free 400 (`unsupported_date_filter`).\n- **Spend controls.** Creator post lists also take `stop_at_id`, so a poll pays only for new pages. Keyword searches take `min_views`, `country` / `exclude_country`, `sort_rows=views`, `seen=<id>` (repeats refunded) on top of the walk (**each page billed**).\n- **`meta.hint`** names one other call that does the job in fewer steps. Its message states the price when that call costs more; follow it only within what the user authorised.\n\n`include=` hydration joins rows to a sibling endpoint and is charged **per row on top of the page**, so never quote the plain heading cost for a hydrated call; the ceilings are in [cost-gate.md](references/cost-gate.md#row-hydration-include) and the traps in [api-overview.md](references/api-overview.md#row-hydration-include).\n\n## Cost rule\n\nCache hits, idempotent replays, every `/v1/utility/*` endpoint except `utility/ai-detection` (1 credit), and `/v1/credits/*` cost 0 credits. Failed calls are refunded, and a request rejected for bad params, a page past the last page, or a rate limit never deducts. Metered endpoints hold an upfront ceiling and refund down to the work done, so the response `credits_used` is the real charge. A band that starts at 0 can settle at 0 (its legs bill only when they return rows), and the top of a wide band is a cap, not the expected charge: `prism/discover` never spends past its `max_credits`. Quote the total for the exact request, not the endpoint's base or unit cost. Scale the gate to the call:\n\n| Call | Gate |\n| --- | --- |\n| Flat price ≤ 5 credits, user asked for it | One line: `≈ N credits` |\n| Metered, multi-page, batch, monitor/cohort, or > 25 credits | Full preflight via `estimate.py` / `utility/estimate` |\n| Upfront hold (worst case) > 500 credits or over budget (the user's stated budget) | Ask before calling |\n\nAnything in between, or unsure of the price or params: quote first with the free `GET /v1/utility/estimate?id=<platform/resource>&<params>`. Any reply except a 404 means a current server (a 5xx or network failure is no reply: retry the estimate): use its quote and gate on `hold`, which is the most the request can bill (every page of a `max_pages` or `max_items` walk, and the legs a composite bills itself); `upfront_hold` is only what is deducted when the call starts, and `quote_basis` names the params that were priced, so check it matches the request you will send. `dry_run=1` is then free on any endpoint (validates, fetches nothing). A 404 or `ENDPOINT_NOT_FOUND` means an older server: do **not** send `dry_run=1` (it bills a normal call there, except the labelled dry run an endpoint documents); quote with `scripts/estimate.py` (offline, `assets/endpoints.json`) or the section's **Pricing** line. At every level, report `credits_used` after.\n\n**If the task needs a whole list, price the whole walk before the first page.** Paging to completion multiplies the page cost by the page count, and a heading only shows one page. `instagram/followers` and `instagram/following` are the common case: about 50 accounts a page. A plain walk (5 credits a page) usually ends within a few rows of the profile's count (large verified accounts stop at about 50 rows on every route); `coverage=full` (10 credits a page) is only for a walk that fell short of `data.total`, and at that rate a 2,600-account list is roughly 520 credits, half that on a plain walk. Quote the total and get agreement before starting ([Multi-page walks](references/cost-gate.md#multi-page-walks-coveragefull)).\n\nErrors: classify before retrying with [references/errors.md](references/errors.md), or paste the status and body into the free `GET /v1/utility/explain-error` for the fix. Never retry a 402 unchanged. Credits and balance: `GET /v1/credits/balance` (0 credits); the ledger is `GET /v1/credits/transactions?limit=50`; spend per API key per UTC day (up to 92 days) is `GET /v1/credits/usage?from=&to=&group_by=api_key,day` (both 0 credits). When several agents share one key, have each send `x-client-tag: <name>` (1 to 64 letters, digits, `.`, `_`, `:` or `-`); `GET /v1/credits/usage?group_by=tag` then splits the spend per agent and `GET /v1/credits/transactions?tag=<name>` lists one agent's rows.";
3
+ export const ERRORS_GUIDE = "# Errors\n\nRead this when a call fails. The full code table (status, retryable, what to do) is generated in [api-overview.md](api-overview.md#error-codes); the `error.details` reasons are in [api-overview.md](api-overview.md#error-details-errordetails).\n\n**Fastest fix:** paste the failed status and body into the free `GET /v1/utility/explain-error?status=<code>&body=<error JSON>` (add `request=<the path and query you sent>` to get a corrected request back). It returns the fault in plain words, the steps that fix it, and whether retrying the same request can succeed. Nothing is fetched and it costs 0 credits.\n\n## Classify before retrying\n\nBranch on `error.retryable` first, then on `error.details`, never on the status alone.\n\n- **Fix before retrying (`retryable: false`):** `MISSING_API_KEY`, `INVALID_API_KEY`, `INSUFFICIENT_CREDITS`, `KEY_BUDGET_EXCEEDED`, `INVALID_REQUEST`, `METHOD_NOT_ALLOWED` (the `Allow` header names the right verb), `ENDPOINT_NOT_FOUND`, `PAYLOAD_TOO_LARGE`, `IDEMPOTENCY_KEY_CONFLICT`, `IDEMPOTENCY_KEY_PAYLOAD_MISMATCH` (use a fresh key for the changed payload), `IDEMPOTENCY_REPLAY_UNAVAILABLE`, and every `COHORT_*` code. Explain the corrective action and do not repeat the same request.\n- **Wait, then retry the same request:** `RATE_LIMITED`, `CONCURRENCY_LIMIT` (`Retry-After: 1`), `SERVICE_UNAVAILABLE`, and `409 IDEMPOTENCY_IN_PROGRESS` (`Retry-After` 1-30 s; resend with the **same** `Idempotency-Key`). Honour `Retry-After`, then back off exponentially with jitter. A `Retry-After` longer than a minute (for example `3600` for a source that is down in one market) means stop and report, not wait in a loop.\n- **Transient upstream failure:** `UPSTREAM_ERROR` (502, or 504 on a timeout) and `INTERNAL_ERROR`, refunded. If `error.details.retry_with` is present, `retryable` is `false` and there is no `Retry-After`: the same request fails the same way, so resend once with exactly the params it names (for example `proxy=auto` on `web/scrape`). If `error.incident` is present, stop calling that platform and poll `GET /v1/status/{platform}` every few minutes. Otherwise retry at most once, then report the outage with the endpoint and `request_id`, never the credential.\n- **Out of time on our side:** a request still unanswered at 54 s gets the standard error envelope with a request id and `Retry-After`, not the hosting platform's bare 504. A request with under 500 ms of its time left answers a refunded 503 with `Retry-After: 5` instead of starting a source call it cannot finish, and a busy database answers a free `503 SERVICE_UNAVAILABLE` with `Retry-After: 5` within about 3 to 11 s. Wait the `Retry-After`, then resend the identical request once.\n- **Not found:** `RESOURCE_NOT_FOUND` is a valid empty outcome, not a retry loop.\n- **Discover runs and the events feed:** `RUN_NOT_FOUND` / `SCHEDULE_NOT_FOUND` (wrong id, or another account's): list your runs or schedules, or start again. `RUN_STATE_CONFLICT` (409): read the run and do what `data.run.next_step` says (a completed run takes `more`, not `resume`). `RUN_EXPIRED` (410): retention passed, start a new run. `NEEDS_ASYNC` (422): drop `async=false` and follow the 202's `data.next.status_url`. `CURSOR_EXPIRED` (410): restart the feed from `details.oldest_cursor` (or `cursor=oldest`) and tell the user the events in `missed_from`..`missed_until` are gone (30-day retention).\n\n## Act on `error.details`\n\nEvery error carries `error.retryable`, and many carry `error.details.reason`; act on it rather than on the status alone:\n\n- **402** (`balance_too_low`, `key_budget_reached`) always says `retry_will_succeed: false`: **never retry a 402 unchanged**. The same request fails until the balance or that key's limit changes. Point the user at `top_up_url` or `key_settings_url`; `key_name`, `key_prefix` and `account_email_masked`, when present, say which key and account ran out. A key budget is a lifetime cap on that key's net spend (refunds give it back; it never resets on its own), so on `key_budget_reached` the `credits_remaining` is the healthy account balance: the user raises the limit or resets the key's usage in Dashboard → API Keys, or uses another key. On a metered call `pricing: \"ceiling\"` means the quoted credits are the maximum hold (unused credits are refunded) and `credits_typical` is what a call like it is usually charged; `pricing: \"exact\"` means it is charged what it holds. `lower_cost_options` lists each param that lowers the hold, with the `value` to send (`null`: leave it out) and the `credits_required` it gives, and `credits_required_cheapest` is the hold with all of them. When one of those fits `credits_remaining`, offer the user that smaller request, or a top-up for the full one.\n- **400 `page_limit`** (`max_page`, `narrow_with`): the source has no further pages for this query; stop paging and narrow the query instead. It is the end of the walk, not a failure.\n- **400 with `did_you_mean`**: a parameter or value was misnamed. `error.details.received_unknown` lists the names the endpoint did not recognise, `missing` the required one it did not get, and `did_you_mean` the name it takes (`You sent term; this endpoint takes query`). Resend under that name; it is free.\n- **400 `INVALID_REQUEST` naming a param on a single-source lane** (for example `weibo/profile`, `goodreads/quotes`, `airbnb/search`, `airbnb/listing/availability`): the value you sent is wrong for that source (an id or URL it cannot read, a date it refuses). It is free and final; fix the param named in `error.details.param` and resend. These lanes used to answer a refunded, retryable 502 for the same input, so do not retry one unchanged.\n- **400 `unsupported_date_filter`**: `since` / `until` (or a copied spelling such as `published_after`) on a list whose rows carry no date. Drop the date.\n- **404 `account_gone` / `account_private` / `handle_unresolved`**: follow `error.details.suggestion` once (for a YouTube handle, retry with the stored `channelId` to tell a rename from a removal), then report. `site_not_supported` on `web/scrape` is final; its `suggestion` names the SocialCrawl endpoint for a social link.\n- **404 `ENDPOINT_NOT_FOUND`** may carry `details.did_you_mean` (paths), `did_you_mean_platform` and `retry_with` (the whole corrected URL, for example for a bare `/search`); check the live registry (`GET /v1/utility/endpoints?search=`, free) before saying something is unsupported. On `/v1/web/jobs|monitors|sessions/{id}` it means the id is unknown for this key.\n- **404 `url_unreachable`** on `web/scrape` and `web/extract`: the address is dead or does not resolve. Free and final; check the URL with the user. `site_not_supported` answers the same way on `web/extract` as on `web/scrape`.\n- **503 `breaker_open`**: that source is paused. The request was refused without being sent and was not billed. Until the time the message states, the same request fails the same way; the same request **without the option the message names** works now. With no stated time, wait for `Retry-After`.\n- **503 \"retry the same cursor\"** on a later search page (`facebook/search/posts`, and `not_found_unconfirmed` on `tiktok/search`): refunded. Resend the **same** cursor once later. When that cursor answers empty again on a later request (`facebook/search/posts`: at least 10 minutes after its first empty answer), the answer is a free `200` with `items: []` and `has_more: false`: the walk has ended.\n- **502 `profile_lookup_timeout`** on `tiktok/user/live`: TikTok did not return the account in time. Refunded; retry later.\n- **5xx** carry `error.status_url` and, during an open incident, `error.incident` (`id`, `title`, `status`, `impact`, `url`). A refunded **504** carries `Retry-After: 30`: wait that long before the one automatic retry.\n- **429** bodies carry `error.details` as well as the headers (`reason`, for example `concurrency`, `limit`, `current`, `remaining`, `retry_after_s`), for clients that drop headers.\n\n## Not errors: `data._warnings` and `meta.hint`\n\nA `200` can still carry advice. `data._warnings` reports a parameter that was ignored or cleaned (a `Query:` label stripped from a search term, a `fields=` path that does not exist, with the path it probably meant) and a handle that resolved to a different account. `meta.hint`, at the envelope root, names one other call that does the job in fewer steps; when that call costs more, its `message` says both prices, so follow it only within what the user authorised. It reaches a key at most once a day per pattern, never on an error; send `X-SocialCrawl-Hints: off` to stop it.\n\n## Retrying paid calls\n\nFor a retryable paid non-streaming request, send an `Idempotency-Key` before the first attempt and reuse it only for the identical payload (same params, same `fields`). A GET with `Accept: text/event-stream` cannot carry an `Idempotency-Key` (free 400); do not automatically retry streaming requests. Never exceed one automatic retry unless the user explicitly asks for continued retries.\n\n**Some POSTs ignore `Idempotency-Key`, so never auto-retry them:** `POST /v1/web/agent`, `/v1/web/sessions`, `/v1/web/monitors`, `/v1/web/parse`, `/v1/monitors` and `/v1/trustpilot/reviews/history`. A resend creates (and, where it bills, bills) a second run, session, monitor or job. Read the list route (`GET /v1/web/jobs`, `GET /v1/web/sessions`, `GET /v1/monitors`) to see whether the first one landed. On `POST /v1/web/crawl` and `/v1/web/batch-scrape` a repeated key returns the existing job (200, 0 credits) without comparing the body.\n\n**A client timeout does not cancel the call.** The server finishes it, charges it and writes it to the cache. Resend the identical request (same or new key) and, within the endpoint's cache TTL, it comes back free from cache (`X-Cache: HIT`). Size your timeout from `recommended_timeout_s` in `GET /v1/utility/endpoint?id=` (60 s is safe almost everywhere).\n\nFailed calls are refunded (upstream errors, circuit-breaker rejections, timeouts, not-found, empty results). `credits_used` on an error envelope is the committed net charge: 0 in almost every case, the kept legs on a partially failed composite. A request rejected for bad params, a page past the source's last page, or a rate limit never deducts at all.";
4
4
  //# sourceMappingURL=guide.js.map