# KRA's Customs Tax Calculator API, read on 26-10-2026

Read on 26-10-2026 from Kenya's API portal, [developer.go.ke/apis/CustomsTaxCalculator](https://developer.go.ke/apis/CustomsTaxCalculator): the page's developer reference and its Postman collection, as the portal's `getAPI` query returns them. The portal's certificate had expired that day. Author: KRA, category "Customs". Only the sandbox, `sbx.kra.go.ke`, is described. The sandbox was called the same day from melux's account: eighteen calls, kept in [their answers](2026-10-26-kra-sandbox-answers.json). Kept as written; the specifications carry what follows from it.

## Five operations

| # | Method | Path | What it does |
|---|---|---|---|
| 1 | `GET` | `/v1/token/generate?grant_type=client_credentials` | A time-limited token, from the consumer key and secret sent as Basic authentication |
| 2 | `POST` | `/api/v1/taxCalculator/searchByHSCode` | Commodities whose code starts with `HSCode`, at least 4 digits |
| 3 | `POST` | `/api/v1/taxCalculator/searchByDesc` | Commodities whose description matches `desc` |
| 4 | `GET` documented, `POST` in the collection | `/api/v1/taxCalculator/details` | One commodity, `nmctcode`, with every tax rate on it |
| 5 | `POST` | `/api/v1/taxCalculator/calculate` | The customs tax on one commodity |

Every call but the token carries `Authorization: Bearer`. A 401 is a missing or expired token; a 400 is a code under 4 digits or a `movement` not in uppercase.

## The commodity

`nmctcode` (code), `nmctdesc` (description, English), `stmucode` (unit: `KG`, `KGM`, `UNT`, `GRM`), `categoryHeading`, `taxDetails`. Searches return `success` (1 found, 0 none) and `hscodesList`; their `taxDetails` are `null` in the collection's answers.

Each line of `taxDetails`: `taxType`, `taxDesc`, `taxRate`, `calcMethod`, `calcCurrency`, `movementType` (true for export, false for import).

## The estimate

Request: `value`, `quantity`, `currency` (ISO 4217), `movement` (`IM` or `EX`), `nmctcode`, and an optional `complementary` object, "additional data required by certain commodity types", with no list of what it holds.

Answer, in KES: `CustomsValueKes`, `CurrencyValue` (the exchange rate against KES), `Tax` (the total), and optionally `Levies`, `IDF` (import declaration fee) and `RDL` (railway development levy). The documented example: 5 000 USD at 130.00 gives 650 000.00, `Tax` 97 500.00, `IDF` 22 750.00 (3.5 %), `RDL` 3 250.00 (0.5 %), `Levies` 26 000.00.

## How it differs from the calculator's contract and from OBR

| # | KRA | OBR (ASYCUDA) | The contract |
|---|---|---|---|
| A | One `value` in one currency; no freight, insurance or delivery terms | Invoice, external and internal freight, insurance, one currency for all four | An amount per box, each with its currency (D23) |
| B | No origin, regime, treatment, package or weight | All of them | All of them |
| C | `Tax` as one figure, with IDF and RDL beside it; no base or rate per charge | Each charge with its base, rate and amount | Each charge with its base, rate and amount (module 3) |
| D | Rates come apart from the estimate, from `details` | Rates come in the estimate | Rates in the estimate |
| E | No reference tables; the rate appears only in the estimate's answer | Eleven tables, exchange rates among them | Six reference lists |
| F | Numbers as JSON numbers | Numbers as JSON numbers | Exact decimals as strings |
| G | Token through client credentials, server to server | `api-id` and `api-key` | The provider's own, held on the server |
| H | Search by code prefix and by words, from customs | Search by code and by words, from customs | Search on the calculator's own copy of the catalogue (D34) |

## What the documentation and its examples disagree on

1. `taxRate` is documented as a number; the example answer gives strings padded with spaces: `"    .00%"`, `"  16.00%"`, `"0"`.
2. `calcMethod` is documented as `per unit` or `percentage`; the example gives `Percentage` and `Per UNT`.
3. `calcCurrency` reads `KSH`, not the ISO code `KES`; the export specific rate reads `USD`.
4. Asked for `8471900000`, the code search and the details both answer the eight-digit `84719000`; the word search answers ten-digit codes (`2842900000`).
5. `quantity` is documented as required; the collection's estimate sends 0.
6. `details` is documented as a `GET` with a JSON body; the collection sends a `POST`.
7. The example answer's `taxType` values are the system's own names: `P_DUTY_RATE`, `P_DUTY_SPEC_RATE`, `P_VAT_RATE`, `P_EXCISE_RATE`, `P_EXCISE_SPEC_RATE`, `P_EXPORT_DUTY_RATE`, `P_EXPORT_SPEC_RATE_USD`. IDF and RDL, which the estimate returns, are not among them.

## What the sandbox answered, 26-10-2026

| Case | Sent | Answer |
|---|---|---|
| Token | Basic, client credentials | 200, valid 3 599 s |
| Code search `0101` | 4 digits | 200, six eight-digit codes, `taxDetails` null |
| Code search `8471900000` | 10 digits | 200, one code, `84719000` |
| Code search `010` | 3 digits | 400, plain text: "Code param is too short. Must be at least 4 digits." |
| Word search "rice" | – | 200, six ten-digit codes; one description starts with spaces and ends with `\r\n`; an extra key `"soursuccessce":"cache"` |
| Details `1006300000` | `POST` | 200, `success` 1, code `10063000`, seven rates: duty 35 %, duty "200" `USD` "Per KGM" described "IN USD PER MT", VAT, excise, export |
| Details `1006300000` | `GET`, as documented | 404 "Resource Not Found" |
| Details `8703239000` | `POST` | 200, code `87032390`, duty 35 %, VAT 16 %, excise 25 % |
| Estimate, the documentation's own example | `complementary: {}` | 500 "Internal Server Error" |
| The same without `complementary` | 8 or 10 digits | 200, value 649 450.00, `Tax` 29 226.00, levies only |
| Rice, 10 000 USD, 25 000 kg | `IM` | 200, rate 129.89, value 1 298 900.00, `Tax` 707 901.00, `Levies` 58 451 |
| The same, 1 000 000 KES | `IM` | 200, rate 1, `Tax` 694 450.00, `Levies` 45 000 |
| The same in `KSH` | `IM` | 500 |
| Car, 8703 23 90, 15 000 USD | `IM`, no engine size or age | 200, value 1 948 350.00, `Tax` 1 953 223.00, `Levies` 87 676 |
| Computer, 1 000 USD | `EX` | 200, `Tax` 0.00, no levy fields |
| Movement `im` | lowercase | 400, plain text: "Incorrect movement format" |
| Code `9999999999` | does not exist | 200, `Tax` 5 846.00: the levies, as if the code were real |

What the figures show:

1. **`IDF` and `RDL` are rates, not amounts:** 2.5 and 2 on every import, though documented as amounts in KES. `Levies` is the amount: 4.5 % of the customs value, rounded up (5 845.05 gives 5 846).
2. **`Tax` includes the levies:** rice in USD is the specific duty, 25 t × 200 USD × 129.89 = 649 450, higher than 35 % of the value, plus 58 451 of levies; 707 901 to the shilling. In KES, the same 649 450 plus 45 000 gives 694 450.
3. **The car:** duty 35 %, excise 25 % on value and duty, VAT 16 % on value, duty and excise, plus levies, comes to 1 953 222; KRA answers 1 953 223. The one shilling is not explained. Neither engine size nor age was asked.
4. **Amounts are text with thousands separators:** `Tax` and `CustomsValueKes` arrive as `"707,901.00"`, `Levies` and `CurrencyValue` as numbers. Errors arrive as plain text (400) or as a JSON envelope with `requestId` (404, 500).
5. **The documented example fails:** `complementary: {}` gives a 500; without it, the same request answers. `GET` on `details` gives 404; `POST` works.
6. **The rate list's currency is not accepted as a currency:** `KSH` gives a 500; `KES` works.
7. **Answers took 0.7 to 2.1 seconds.**

## Lessons for the calculator

1. A customs service may answer a total and no lines: the result must say which figures are customs' and show no line it did not give (D4, D56). KRA's total includes its levies.
2. Rates and amounts may come from two calls, at two moments; a rate shown beside an amount needs both times.
3. A rate may arrive as text with a percent sign and spaces; the adapter reads it, and refuses what it cannot read rather than taking it as zero.
4. Currency codes are not always ISO (`KSH`, as `UGS` at RRA).
5. A code may come back shorter than asked; the result must show the code customs used.
6. The token expires after an hour; the adapter renews it before the call, never on the trader's error.
7. An unknown code is answered with a figure: the adapter checks the code with `details` before it asks for an estimate, and refuses one `details` does not find.
8. Field names cannot be trusted to say what they hold (`IDF`, `RDL`); each field is read from measured answers, not from the documentation.

## Not verified

- Which system computes behind the API, and whether a production service is open; the portal names only the sandbox and a "go live" step with a demonstration.
- What `complementary` holds and which commodities need it; whether a car's engine size and age change the figure; the one shilling on the car.
- Whether IDF 2.5 % and RDL 2 % match Kenya's law today; whether the sandbox's rates and tariff are production's.
- The service's limits per minute and its terms of use.
