Get Trade Flow Records
comtrade_get_trade_flowsFetch bilateral trade flow records — the primary data retrieval tool. Returns trade value in USD (primaryValue — FOB for exports, CIF for imports), quantity, net weight, and period/commodity/partner metadata for each row. Accepts multiple periods and commodity codes per call; pass partner_code 0 to get totals aggregated across all partners. Omit cmd_code or pass "TOTAL" to aggregate all commodities. Follow nextOffset for remaining records; each page repeats the upstream period requests. Keyless preview makes one request per served period, at least 4 seconds apart, with a 500-record cap per request. Use comtrade_lookup_countries to resolve reporter/partner codes and comtrade_search_commodities to resolve HS codes. For SITC, supply codes from the selected SITC revision.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"flow_code": "<flow_code>",
"period": "<period>"
},
"name": "comtrade_get_trade_flows"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| freq | No | Frequency: A=annual YYYY, M=monthly YYYYMM (01–12). Omit to infer it from the periods; an explicit value must match them. | |
| limit | No | Records per page (default 25). Larger requests are limited to 1000 with a notice. | |
| offset | No | Number of retrieved records to skip. | |
| period | Yes | One or more periods to query, all annual "YYYY" (e.g. ["2022", "2023"]) or all monthly "YYYYMM" (e.g. ["202201", "202202"]); mixed lengths are rejected. Serves the first 8 distinct periods keyless (12 with authenticated access); the rest, and any period whose request is rate limited, fails on a UN Comtrade server error or network failure, or runs out of time, are listed in unservedPeriods. Input ceiling 120. | |
| cmd_code | No | HS or SITC commodity codes to query. Serves the first 20 distinct codes and discloses the remainder; input ceiling 200. Pass ["TOTAL"] or omit to aggregate all commodities. Use comtrade_search_commodities for codes in the selected HS or SITC edition. | |
| flow_code | Yes | Trade flow direction: M=imports, X=exports, RX=re-exports, RM=re-imports. | |
| partner_code | No | M49 code of the trade partner. Use 0 to aggregate across all partners (World total). Omitting it can return World alongside the partner breakdown. | |
| reporter_code | No | M49 reporter code or nonempty array (input ceiling 200). Deduplicates and serves the first 20 reporters, disclosing the remainder; served codes of an array that return no records are listed in reportersWithoutRecords. Some codes are partners only (0 World, 250 Metropolitan France, 158 Taiwan, Province of China): France reports as 251, and UN Comtrade publishes the trade of 158 under 490 (Other Asia, nes). Omit only with an explicit partner_code to query all reporters. | |
| classification | No | Goods classification: HS as reported, H0–H6 with authenticated access, or SITC S1–S4/SS. | HS |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| error | No | Present when the call failed. Absent on success. | |
| shown | No | Number of records on this page. | |
| notice | No | World overlap warnings, commodity edition guidance, period failures, and recovery for empty results, including counterpart codes for reporter or partner filters. | |
| offset | No | Number of retrieved records skipped for this page. | |
| records | No | Trade flow records. | |
| truncated | No | True when any preview response reached 500 and may be incomplete. | |
| limitClamp | No | Requested and applied page sizes when the limit was clamped. | |
| nextOffset | No | Offset for the next page when more records remain. | |
| totalCount | No | Sum of upstream response counts before local filtering; not a full match count when capped. | |
| truncationHint | No | Query narrowing and authenticated access guidance when possibly incomplete. | |
| referenceNotice | No | Notice when reference descriptions could not be loaded; codes and trade values remain available. | |
| unservedPeriods | No | Periods not served: past the period cap (8 keyless, 12 authenticated) or whose requests were rate limited, failed on a UN Comtrade server error or network failure, or ran out of time; query them separately. | |
| unservedCmdCodes | No | Commodity codes beyond the 20-code work cap; query them separately. | |
| unservedReporters | No | Reporter codes beyond the 20-reporter work cap; query them separately. | |
| cmdCodesWithoutRecords | No | Served commodity selectors without records in any completed period. Omitted when the result is truncated. | |
| reportersWithoutRecords | No | Served codes from a reporter_code array with no records in any served period. Omitted when truncated, since a capped response can hide a reporter’s rows. |