# Buy Leads: AI Lead Scoring for go4WorldBusiness & Alibaba RFQ — API reference

The detail an integrator needs and a buyer does not: linked from the README's Integrations section. `/actor-deploy
--assets` hosts this file next to the images (any other repo file 404s on the Store).

## Tested combinations

Every row is an input the test suite and the review runs start — the combinations that are supported. An input
outside this table is accepted by the schema but not tested; keep the table in sync with `storage-example/` and
`tests/` (gate `check_tested_combinations`, 2026-10-23 company-contact-finder-ai V-27).

| Call | What runs | Input |
|---|---|---|
| Daily test / first agent call | the free demo on the five sample leads, nothing charged | `{}` |
| Demo, as the form opens | the same free demo | `storage-example/INPUT.json` |
| Live search, capped | go4WorldBusiness + ExportersIndia read by the Actor, AI off, 5 rows | `storage-example/INPUT.live.json` |
| AI on | the same sample leads with the AI verdict | `storage-example/INPUT.ai.json` |
| AI with your own key | the AI through your provider key | `{"products": ["rice"], "enableAi": true, "llmProvider": "byok", "llmModel": "google:gemini-3.5-flash-lite", "llmApiKey": "…"}` |
| A preset | one ready search | `{"preset": "rice-gulf"}` (`spices-europe`, `pulses-lentils`, `cashew-nuts`, `india-buyers`) |
| Alibaba keyword search via the Store fallback | blueskyscraper/alibaba-rfq-scraper on your account, capped | `{"products": ["rice"], "useStoreFallback": true, "maxDiscoveryChargeUsd": 0.1}` |
| Your own list | your rows, no board read | `{"sourceMode": "list", "itemsList": [ … ]}` (fields: README → List-mode rows) |
| A dataset you have | a dataset's items, no board read | `{"sourceMode": "dataset", "datasetId": "<id>"}` |

## One dataset item

A go4WorldBusiness lead from the live AI run of 2026-11-23 (rice + spices, own Gemini key), every field:

```json
{
 "itemId": "da267cc7276c",
 "name": "Rice Like Basmati Rice 1121, Golden Rice — Oman, 25 Tons",
 "url": "https://www.go4worldbusiness.com/buylead/view/1336183/wanted-:-rice-like-basmati-rice-1121-golden-rice.html",
 "board": "go4worldbusiness",
 "boardLeadId": "1336183",
 "product": "Rice Like Basmati Rice 1121, Golden Rice",
 "description": "Please quote for the following wholesale product requirement - · Product Name : Rice · Specifications: · Type : White Sella Basmati Rice 1121, Golden · Quantity Required : 25 Ton/Tons · Shipping Terms : FOB/CIF · HS Code : 100630 · Destination Port : Sohar, Oman · Payment Terms : LC · Looking for suppliers from : Worldwide",
 "country": "OM",
 "countryName": "Oman",
 "quantity": 25.0,
 "unit": "Tons",
 "quantityMt": 25.0,
 "incoterm": "FOB/CIF",
 "paymentTerms": "LC",
 "destination": "Sohar, Oman",
 "postedOn": "2026-11-23",
 "postedOnText": "Nov-23-26",
 "deadline": null,
 "buyerName": null,
 "companyKey": null,
 "contactShown": "premium members",
 "canReplyFree": false,
 "howToReply": "premium board membership only",
 "quotesLeft": null,
 "sourcingCountries": "Worldwide",
 "feedUrl": "https://www.go4worldbusiness.com/buyers/rice.html",
 "fetchedAt": "2026-11-23",
 "alsoOn": [],
 "contactRoute": "go4WorldBusiness inquiry form (premium members): https://www.go4worldbusiness.com/buylead/view/1336183/wanted-:-rice-like-basmati-rice-1121-golden-rice.html",
 "matchedProduct": "rice",
 "flags": [
  "unverified_lead",
  "fresh",
  "bulk",
  "has_destination",
  "has_incoterm",
  "premium_only"
 ],
 "targetFlagsMatched": [],
 "ruleScore": 83,
 "score": 90,
 "label": "hot",
 "fitScore": 90,
 "scoreReasons": [
  "Requests 25 tonnes of White Sella Basmati Rice 1121 and Golden Rice, which matches the exporter's product line and bulk volume.",
  "Specifies destination port as Sohar, Oman, aligning with target markets in the Gulf.",
  "Provides clear commercial terms including FOB/CIF and LC payment."
 ],
 "summary": "The buyer is seeking 25 tonnes of White Sella Basmati Rice 1121 and Golden Rice delivered to Sohar, Oman under FOB/CIF terms with LC payment.",
 "buyerType": "importer_distributor",
 "wantedSpec": "White Sella Basmati Rice 1121, Golden Rice; 25 Ton/Tons; Destination: Sohar, Oman; Terms: FOB/CIF; Payment: LC",
 "questionsToAsk": [
  "What specific packaging and bag sizes do you require?",
  "Is the destination port Sohar, Oman, and do you prefer FOB or CIF terms?",
  "What is your target delivery schedule?"
 ],
 "generatedText": "We can supply White Sella Basmati Rice 1121 and Golden Rice for shipment to Sohar, Oman on FOB or CIF terms with LC payment. Please let us know your required packaging and target delivery timeline so we can send our best quotation.",
 "recommendedNextStep": "Verify the buyer's company details on go4worldbusiness before sending a formal quotation.",
 "aiModel": "google:gemini-3.5-flash-lite",
 "assessedBy": "ai",
 "chargedEvent": "qualified-buy-lead-ai",
 "billedAs": "qualified-buy-lead-ai",
 "dedupeKey": "lead:go4worldbusiness:1336183",
 "source": {
  "mode": "live",
  "reader": "built-in reader of Alibaba RFQ, go4WorldBusiness, ExportersIndia and TradeKey",
  "query": "rice"
 },
 "scrapedAt": "2026-11-23T11:39:03+00:00"
}
```

## `OUTPUT` record keys

Merged from a live run, the AI example and a run where every board refused. One line per key: type and example.

- `ok` — bool: `false` only when every board refused / failed and nothing loaded
- `outcome` — str, one of `ok` · `empty` · `source_refused` · `source_failed` · `error`
- `mode` — str: `demo` · `live` · `list` · `dataset`
- `qualified`, `rows` — int, e.g. `100` (FR-10: `rows` = rows delivered)
- `refused` — array: `{"board": "alibaba", "product": null, "reason": "not_supported" | "failed" | "fallback_failed", "detail": "…"}` — `not_supported` is permanent (Alibaba's robots-disallowed keyword search): never alert on it; alert on `failed`
- `queries` — array: `{"board", "product", "pagesRead", "leads", "found", "url"}` per (board, product) read
- `costUsd` — number: what this Actor charged in this run (the Store fallback bills separately)
- `boards` — object: `{"go4worldbusiness": {"pagesRead": 4, "leadsFound": 200, "kept": 97, "oldest": "2026-07-09", "newest": "2026-11-23", "keywordSearch": true, "state": "ok"}, …}` — `state`: `ok` · `empty` (read fine, nothing on your products) · `parse_drift` (pages read, 0 parsed — the page changed: alert on it) · `refused` (+ `refusedReason`)
- `products` — object: `{"rice": {"go4worldbusiness": 40, …}, …}` — leads kept per product and board
- `mergedAcrossBoards` — int | null: requests found on two boards, merged into one row (`alsoOn`)
- `storeFallback` — object | null: `{"board": "alibaba", "actorId", "leads", "status"}`
- `termsFromBrief` — array | null: products read from the brief when `products` was empty
- `stats` — object: `discovered`, `skipped_off_product`, `skipped_outside_countries`, `skipped_too_old`, `skipped_below_min_quantity`, `skipped_below_min_score`, `ai_assessed`, `capped_by_max_qualified`
- `skips` — object | null: `{"too_old": ["<lead name>", …]}` — the leads each free filter dropped
- `chargedEvents` — object: `{"<event>": <count>}`; `chargeSplit` — object: `demo`, `free`, `basic`, `ai`, `freeKeptForAi`
- `sourceStatus` — object | null: `reader`, `status`, `partial`, `perBoard`, `perQuery`, `robots` (`read` / `none` / `builtin` per host)
- `sourceError` — str | null · `sourceRefused` — `"plan"` | null · `sampleFallback` — bool | null
- `aiCoverage` — object | null: `aiAssessed`, `ruleScored`, `aiRejected`, `fallbackReasons`, `sampleVerdicts`; `aiError` — str | null
- `aiTokens` — object | null: `{"model": "google:gemini-3.5-flash-lite", "inputPerUnit": 1447, "outputPerUnit": 248}` (review 2026-11-24-2)
- `webhook` — object | null: `sent`, `failed`, `failedKeys`, `redelivered`, `pendingNextRun`, `signed`
- `trend` — object | null (second run on): `qualified: {prev, now}`, `hot: {prev, now}`
- `history` — array | null: one `{at, qualified, hot, bulk}` per run of this search, oldest first
- `scheduledSizing`, `firstRunBackfill`, `scanCapHit` — object | null: what a scheduled / first run resized, the page cap a board filled
- `digestEmailed` — bool | null; `scheduleTaskUrl` — str | null; `reportUrl` — str | null
- `timing` — object: `sourceSecs`, `aiSecs`, `aiSecsPerUnit`, `aiBackoffSecs`, `aiPaceSecs`, `totalSecs`
- `nextSteps` — array | null: the status steps that did not fit the 200-character status

`RUN_SUMMARY` holds the same record under the old name — deprecated, removed in 0.3 (2027-03-01); read `OUTPUT`.

## Webhook payload

One POST per row (`webhookBatchSize` 1): `{"event": "buy_lead.qualified", "item": {…the dataset row…}, "buy_lead": {…the same row…}, "runId": "…"}`;
batches: `{"event": "buy_leads.qualified", "items": [ … ], "buy_leads": [ … ], "runId": "…"}`. Read the generic `item` /
`items` (one receiver serves every Actor of this developer); `buy_lead` / `buy_leads` stay until 2027-03-01. Retried once on 429 / 5xx; rows that still
failed are listed in `OUTPUT.webhook.failedKeys` and re-POSTed first on the next run (`"redelivery": true`, never charged
again).

**Signature (`webhookSecret`)** — every POST then carries `X-Signature: sha256=<hex HMAC-SHA256 of the exact raw body>`,
keyed with your secret. Verify it on the raw bytes, before parsing the JSON:

```python
import hashlib, hmac
expected = "sha256=" + hmac.new(SECRET.encode(), raw_body, hashlib.sha256).hexdigest()
assert hmac.compare_digest(expected, request.headers["X-Signature"])
```

## API-only inputs

Hidden on the form; an API call may send them. Each one's default and its effect on cost and time.

| Field | Default | Effect on cost and time |
|---|---|---|
| `maxDiscoveryChargeUsd` | 0.5 | caps the opt-in Alibaba Store fallback's bill on your account; the built-in read never spends it |
| `aiCandidateMultiplier` | 2 | AI-assesses `maxQualified` × this many leads: × 2 = twice the AI time and tokens of × 1 |
| `maxToProcess` | 3 × `maxQualified` | upper bound on leads scored per run — more = longer runs, no extra charge |
| `discoveryTimeoutSecs` | 3600 | how long the Store fallback may run (never more than 60 % of the run's time left) |
| `historyDatasetName` | empty | appends each run's new leads to a named dataset on your account (storage, no charge) |
| `dedupeStoreName` | `buy-leads-ai-seen` | one memory per name — one per client keeps clients apart |
| `suppressionList` / `allowList` | empty | leads never output / never dropped by a free rule — no cost effect |
| `autoSwitchToLive` | true | Console only: typed products next to the sample start the paid live read |
| `llmModel` | provider default | another model: changes AI time and token cost |
| `webhookHeaders` / `webhookSecret` / `webhookBatchSize` | — / — / 1 | webhook delivery details — no cost effect |
| `discoveryActorId` / `discoveryInput` | blueskyscraper/alibaba-rfq-scraper / — | the Store fallback's Actor and extra input |
| `slackWebhookUrl` / `teamsWebhookUrl` / `googleChatWebhookUrl` / `discordWebhookUrl` / `telegramUrl` | — | per-service aliases of **Send alerts to** — no cost effect |

**Merge rule — which wins:** `sendAlertsTo` and the per-service aliases are a union: every URL is posted once; for one
service an explicit alias sent over the API wins over the URL `sendAlertsTo` detected for it. `webhookUrl` gets the rows,
the others the digest. `suppressionList` wins over `allowList` (exclude wins).
