# Export Credit Risk by Country — ECGC & OECD Grades + Alerts — API reference

The detail an integrator needs and a buyer does not, linked from the README's Input and Integrations sections.

## Which mode runs

No `countries` and no `itemsList` → the free demo (`{}` included, whatever `sourceMode` says — the schema's `default: live` only applies once you name countries); `countries` → the live read; `itemsList` / `datasetId` with `sourceMode` `list` / `dataset` → your rows. `OUTPUT.mode` returns which one ran (`demo`, `live`, `list`, `dataset`).

AI fields (`fitScore`, `scoreReasons`, `summary`) are `null` on a rule-scored row; `assessedBy` says why (`rules`, `sample`, `ai`).

## Tested combinations

Every row is an input the test suite and the review runs start.

| Call | What runs | Input |
|---|---|---|
| Daily test / first agent call | the free demo on 5 sample countries, nothing charged | `{}` |
| Demo, as the form opens | the same free demo | `storage-example/INPUT.json` |
| Live read, capped | ECGC's and the OECD's own lists read by the Actor (no Store Actor), 5 countries, AI off | `storage-example/INPUT.live.json` |
| AI on | the sample countries with the AI verdict | `storage-example/INPUT.ai.json` |
| AI with your own key | the AI through your provider key | `{"enableAi": true, "llmProvider": "byok", "llmModel": "google:gemini-3.5-flash-lite", "llmApiKey": "…"}` + countries |
| Changes only, scheduled | only what moved since your last run of this search | `{"sourceMode": "live", "countries": ["ALL"], "changesOnly": true}` |
| Your own list | your rows, no read of ECGC | `{"sourceMode": "list", "itemsList": [ … ]}` (fields below) |
| A dataset you have | a dataset's items | `{"sourceMode": "dataset", "datasetId": "<id>"}` |

## One dataset item

A real row of a live run (2026-11-23, Egypt, AI off):

```json
{"itemId": "fad291f9ab00", "name": "Egypt",
 "url": "https://main.ecgc.in/english/wp-content/uploads/2026/10/ECGC-Country-Risk-Classification-List-ST-w.e.f.-14.10.2026.pdf#page=3&search=%22Egypt%22",
 "country": "EG", "stRating": "B2", "coverCategory": "Open Cover", "mltRating": "C1",
 "stRatingLabel": "Moderate Risk", "mltRatingLabel": "Moderately High Risk", "coverCategoryLabel": "Open Cover",
 "ecgcRatingDate": "2026-10-14", "mltRatingDate": "2026-10-14", "previousStRating": "C1",
 "previousCoverCategory": "RCC-I", "previousMltRating": "C1", "previousEdition": "2026-10-01",
 "change": "cover_eased", "changeDetail": "ST C1 → B2; cover RCC-I → Open Cover", "changedOn": "2026-10-14",
 "history": [], "ecgcNote": null,
 "stListUrl": "https://main.ecgc.in/english/wp-content/uploads/2026/10/ECGC-Country-Risk-Classification-List-ST-w.e.f.-14.10.2026.pdf",
 "mltListUrl": "https://main.ecgc.in/english/wp-content/uploads/2026/10/ECGC-Country-Risk-Classification-List-MLT-w.e.f.-14.10.2026.pdf",
 "feedUrl": "https://main.ecgc.in/english/circular/",
 "oecdRating": 6, "previousOecdRating": 6, "oecdChange": "unchanged", "oecdRatingDate": "2026-10-16",
 "oecdListUrl": "https://www.oecd.org/content/dam/oecd/en/topics/policy-sub-issues/country-risk-classification/cre-crc-current-english.pdf",
 "oecdNote": null, "flags": ["upgraded", "st_mlt_differ", "changed", "ecgc_oecd_differ"], "targetFlagsMatched": [],
 "ruleScore": 50, "score": 50, "tier": "warm", "fitScore": null, "scoreReasons": null, "summary": null,
 "generatedText": "Open Cover. ST B2 (Moderate Risk), MLT C1 on ECGC's list of 14 Oct 2026; OECD grade 6 of 7 — changed since 1 Oct 2026: ST C1 → B2; cover RCC-I → Open Cover.",
 "paymentTerms": "DP, or DA within an ECGC buyer limit; an LC for a new buyer.",
 "changeNote": "ST C1 → B2; cover RCC-I → Open Cover on ECGC's list of 14 Oct 2026 (previous list 1 Oct 2026).",
 "recommendedNextStep": "Re-check open quotes and limits: check the buyer's ECGC credit limit before quoting credit terms to Egypt. List: https://main.ecgc.in/english/wp-content/uploads/2026/10/ECGC-Country-Risk-Classification-List-ST-w.e.f.-14.10.2026.pdf",
 "nextStepActorUrl": "https://console.apify.com/actors/rich_minds~importer-list-extractor-ai?input=%7B%22countries%22%3A%20%5B%22EG%22%5D%7D",
 "aiModel": null, "assessedBy": "rules", "chargedEvent": "qualified-country-basic", "billedAs": "qualified-country-basic",
 "dedupeKey": "ecgc:EG:B2|OpenCover|C1", "source": "ecgc", "rowId": "EG:B2|OpenCover|C1",
 "fetchedAt": "2026-11-23T22:02:43+00:00",
 "sourceRun": {"mode": "live", "reader": "main.ecgc.in + oecd.org (built-in reader of the official country risk lists)"},
 "sample": null, "scrapedAt": "2026-11-23T22:02:43+00:00"}
```

Ids: `country` = stable per country across editions and runs; `dedupeKey` (and `itemId`, its hash) = one per ECGC
state, new when an edition moves the country; `rowId` and `scrapedAt` are deprecated aliases (removed in 0.3.0,
2027-01-31). Dates: `ecgcRatingDate` / `mltRatingDate` / `oecdRatingDate` are the authorities' publication dates of the
files read in this run, downloaded at `fetchedAt`.

## `OUTPUT` record keys

Merged from a list-mode AI run, a scheduled Changes-only run and a failed read.

- `ok` — bool: `false` only when the source failed / was refused and nothing loaded
- `outcome` — str: `ok` · `empty` · `source_refused` · `source_failed` · `error`
- `mode` — str: `demo` · `live` · `list` · `dataset`
- `qualified`, `rows`, `candidates` — int, e.g. `239`
- `editions` — object: `st`, `mlt`, `previousSt`, `previousMlt` (`{kind, effectiveDate, url, countries, cacheHit}`),
  `history[]`, `oecd` (`{validAsOf, url, countries, matched}`)
- `countries` — int (read from ECGC's newest lists) · `changed` — int (delivered countries that moved) ·
  `changedInEdition` — int
- `baseline` — object | null: `{st, mlt, at}` — the lists your last Changes-only run read · `baselineSaved` — bool | null
- `refused` — array: `{source, reason, detail}`; `reason` `failed` = a list that could not be read today (alert on it),
  `not_supported` = a country you asked for that ECGC's lists do not name (never an outage)
- `queries` — array: `{country, matched}` per country asked for
- `costUsd` — number: what this run charged by us
- `stats` — object: `discovered`, `skipped_<reason>`, `ai_assessed`, `ai_skipped_unchanged`, `capped_by_max_qualified`
- `chargedEvents` — object `{"<event>": n}` · `chargeSplit` — object: `demo`, `free`, `basic`, `ai`, `freeKeptForAi`
- `aiCoverage` — object | null: `aiAssessed`, `ruleScored`, `model`, `secondPass`, `overloadRetries`,
  `fallbackReasons` (e.g. `{"unchanged — rule note": 228}`) · `aiError` — str | null · `aiTrial` — object | null
- `aiTokens` — object | null: `inputPerUnit`, `outputPerUnit`, `model`
- `sourceStatus` — object: `reader`, `status`, `partial`, `editions`, `refused`, `requests`, `cacheHits`
- `sourceError` — str | null · `sourceRefused` — `"plan"` | null · `sampleFallback` — bool | null
- `webhook` — object | null: `sent`, `failed`, `failedKeys`, `redelivered`, `pendingNextRun`, `signed`
- `trend` — object | null: `qualified: {from, to}`, `hot: {from, to}` · `history` — array | null (per run of this search)
- `dedupeStore` — object | null: `name`, `scope`, `remembered`
- `scheduleInput`, `scheduleTaskUrl`, `reportUrl` — the saved search, its Task and the REPORT link
- `timing` — object: `sourceSecs`, `aiSecs`, `aiSecsPerUnit`, `aiBackoffSecs`, `aiPaceSecs`, `totalSecs`
- `nextSteps` — array | null: the status steps that did not fit

`RUN_SUMMARY` is a deprecated alias of `OUTPUT` (same record), removed in 0.3.0 (2027-01-31) — read `OUTPUT`.

## API-only inputs

Hidden on the form, accepted over the API.

| Field | Default | Effect on cost and time |
|---|---|---|
| `aiScope` | `changed` | `all` = the AI writes for every country: ≈ 20 × the AI time and tokens on an All-countries run (239 vs 11) |
| `aiCandidateMultiplier` | `2` | how many of the best rule-scored countries the AI may take, × `maxQualified` |
| `allowList` | — | countries no free filter may drop (they still pay when delivered) |
| `dedupeAcrossRuns` | `true` | `false` = every run delivers and charges every country again |
| `dedupeTtlDays` | `0` | > 0 = an unchanged country is delivered and charged again after N days |
| `dedupeStoreName` | per search | one name per client keeps separate memories |
| `maxToProcess` | 3 × `maxQualified` | rows scored per run (no cost effect for ≤ 239 countries) |
| `failOnSourceError` | `false` | `true` = an unreadable ECGC page ends FAILED (your failed-run alert fires) |
| `autoSwitchToLive` | `true` | Console only: countries typed next to the sample start the live read |
| `webhookHeaders`, `webhookSecret`, `webhookBatchSize` | — / — / `1` | headers, HMAC signature, rows per POST |
| `slackWebhookUrl`, `teamsWebhookUrl`, `googleChatWebhookUrl`, `discordWebhookUrl`, `telegramUrl` | — | the digest to one service (`sendAlertsTo` takes them all) |
| `maxDiscoveryChargeUsd`, `discoveryTimeoutSecs` | `0.5`, `3600` | unused by the built-in reader (no Store Actor runs) |

## Run outcomes — what your integration sees

| Outcome | Run status | `OUTPUT` | Charged? | What to do |
|---|---|---|---|---|
| Free demo | SUCCEEDED | `mode: demo` | no | pick countries |
| Success | SUCCEEDED | `rows`, `changed` | per country | — |
| Nothing new | SUCCEEDED | `qualified: 0` | no | wait for the next list |
| Invalid input | FAILED | — | no | fix the named field |
| Source failed | FAILED | `ok: false`, `outcome: source_failed` | no | retry in an hour |
| Plan refused (dataset mode) | SUCCEEDED¹ | `outcome: source_refused` | no | Console: the free sample scored on your brief; schedule / API: channels alerted |
| Source partial (MLT / OECD unread) | SUCCEEDED | `refused[].reason: failed` | per country | alert on it |
| AI unavailable | SUCCEEDED | `aiError` | basic | your own key |
| Run time limit reached during the AI pass | SUCCEEDED, never TIMED-OUT | `fallbackReasons`: `run budget` | rule rows at basic | raise the timeout or lower `maxQualified` |

¹ FAILED with `failOnSourceError`.

## Which delivery field wins

Every URL is posted once. A per-service field (`slackWebhookUrl` …) wins for its service over a URL of the same service
in `sendAlertsTo`. `webhookUrl` (and any non-chat URL in `sendAlertsTo`) gets the rows as JSON; Slack, Teams, Google
Chat, Discord, Telegram and `notifyEmail` get the digest.

## Webhook body

Per country (`webhookBatchSize` 1):

```json
{"event": "country.qualified", "runId": "KzVRxNcpzH9hbOyN2",
 "country": {"name": "Egypt", "country": "EG", "stRating": "B2", "coverCategory": "Open Cover", "oecdRating": 6,
             "change": "cover_eased", "dedupeKey": "ecgc:EG:B2|OpenCover|C1", "...": "every dataset field"}}
```

Batched (`webhookBatchSize` > 1): `{"event": "countries.qualified", "runId": "…", "countries": [ … ]}`. A failed POST
is re-sent on the next run with `"redelivery": true`, never charged twice. With `webhookSecret` every POST carries
`X-Signature: sha256=<HMAC-SHA256 of the raw body>`.

## List-mode rows — every field

| Field (aliases) | Needed? | What it enables |
|---|---|---|
| `name` (`countryName`, `title`) | required | the row's country; the ISO-2 code is derived from it |
| `stRating` (`ecgcRating`, `rating`) | required | score, flags, payment terms |
| `country` (`iso2`, `countryCode`) | optional | the country filter, the next-step link |
| `coverCategory` (`cover`), `mltRating` | optional | cover flags, ST / MLT differ |
| `oecdRating`, `previousOecdRating`, `oecdChange` | optional | the OECD columns and flags |
| `previousStRating`, `previousCoverCategory`, `previousMltRating`, `previousEdition`, `change`, `changeDetail`, `changedOn` | optional | the change view, Changes only |
| `ecgcRatingDate`, `mltRatingDate`, `stListUrl`, `mltListUrl`, `url`, `ecgcNote`, `history` | optional | dates, links, notes |

## Flags

| Flag | Meaning |
|---|---|
| `restricted_cover` | RCC-I (revolving buyer limits) or RCC-II (case-by-case approval) |
| `off_cover` | ECGC gives no cover |
| `high_risk` | ST rating C2 or D |
| `downgraded` / `upgraded` | ST or MLT rating got worse / better in the newest list |
| `st_mlt_differ` | ST and MLT ratings differ |
| `changed` | anything moved since the list compared with, or new on it |
| `ecgc_oecd_differ` | ECGC's ST rating and the OECD grade are 2+ grades apart (62 countries on 14 / 16 Oct 2026) |
| `oecd_downgraded` | the OECD moved the country to a riskier grade at its latest meeting |

## Run time per mode

| Mode | Measured | `timeoutSecs` |
|---|---|---|
| Free demo | 2 s | 120 |
| Live read, all countries, AI off (6 PDFs: 4 ECGC + OECD) | 17 s platform (2026-11-22); 15 s local with the OECD list (2026-11-24) | 300 |
| AI, own free key (google:gemini-3.5-flash-lite) | measured ≈ 0.8–46 s per country: 0.8 s (2026-11-24), 2.6 s (2026-11-22), 4.7 s (2026-11-23), 46 s rate-limited (2026-11-23) | 2480 per 50 countries |
| AI via Apify's model access (anthropic/claude-haiku-4.5) | not measured on the platform yet | 1500 |
| AI, free own key, rate-limited | ≤ 60 s of waits, the rest rule-scored | 900 |
