Plan the exchange rate API calls for one report
An expense report needs three kinds of call, and the first example lists their request bodies in order. The empty object goes to currencies when the form opens; its code-to-name map fills the currency picker, so a user can only choose codes the service knows. The second body goes to convert for each receipt: 100 USD dated Saturday 2024-01-06, converted to EUR.
The third goes to historical for the same day with base EUR and symbols USD,GBP, which shows the reviewer the other rates of that reference day in one call instead of one conversion per currency. Each body is posted to its own action with its own Idempotency-Key, and none of the three is a range operation, so each is billed at the lower per-call price.
Keep the receipt and the conversion apart
Store the receipt amount and its original currency once and never overwrite them. Next to them, keep the converted amount, the target currency, the rate and the reference day as separate fields of the preview, so that a reviewer can see which rate produced which figure.
The second example builds such a record from one convert reply: it copies amount and from as the original values, result and to as the converted ones, and keeps rate unchanged. Rounding happens only for display: its display field formats result with Intl.NumberFormat and the target currency, which prints 90 as €90.00, while the stored convertedAmount stays 90.
Show the weekend fallback instead of hiding it
Receipts are often dated on days without a publication. For a Saturday receipt, convert answers with the Friday rate: date holds 2024-01-05, and requested_date keeps 2024-01-06.
The second example derives requestedDate from requested_date when it is present and from date otherwise, then sets a rolledBack flag when the two days differ. Show both days in the preview, for example as "rate of Fri 5 Jan for a receipt of Sat 6 Jan", and let your accounting policy decide whether that substitution is acceptable.
Use one request identity for one intent
Generate one Idempotency-Key of 8 to 128 characters per conversion intent, for example from the receipt identifier and a version number, and store it together with the request body. Sending the identical body again with that key within 24 hours returns the stored reply and does not charge again; sending a different body with it returns IDEMPOTENCY_CONFLICT. After OPERATION_TIMEOUT or another uncertain outcome, resend the unchanged request with the same key: it answers REQUEST_PENDING until the 900-second hold ends and then OUTCOME_UNKNOWN_RELEASED, with nothing charged.
Only then does a new key make sense, because the first attempt may already have run. Input the operation rejects costs nothing, and the corrected request needs a new key. The server-side request template further down sends a latest body with the headers every call in this plan needs: Content-Type, x-api-key and Idempotency-Key.
Pace a long report and react to 429
A report with many receipts sends one convert call per receipt, and those calls share limits. RATE_LIMITED (429) means a rate limit was reached: either your account's own, which every API key and live playground request of the account draw from, or one shared with other customers for this operation or a group of operations. CONCURRENCY_LIMIT (429) means too many requests to the operation are in progress at once.
Both are refused before anything runs, so nothing is charged and the Idempotency-Key stays unused. Read Retry-After, wait that many seconds, and resend the same body with the same key instead of retrying in a tight loop.
Chart a short period without inventing days
timeseries returns one entry per working day inside a range, and the third example reads such a reply for Thursday 2024-01-04 to Monday 2024-01-08. It takes the range from start and end, or from start_date and end_date when those are the labels present. It then turns rates into sorted points, walks every calendar day of the range and collects the days without an entry: here 6 and 7 January, the weekend.
Draw those days as gaps, not as zero or as a copied value. Finally it checks stop_reason; a non-null value means the series ended early and the chart needs a visible note. When only the first and last rates matter, fluctuation gives them directly.
[
{},
{
"from": "USD",
"to": "EUR",
"amount": 100,
"date": "2024-01-06"
},
{
"date": "2024-01-06",
"base": "EUR",
"symbols": "USD,GBP"
}
]// Example convert response: 100 USD requested for Saturday 2024-01-06 uses the Friday 2024-01-05 reference rate.
const response = { ok: true, data: { from: 'USD', to: 'EUR', amount: 100,
rate: 0.9, result: 90, date: '2024-01-05', requested_date: '2024-01-06' } };
if (!response.ok || !Number.isFinite(response.data.result)) throw new Error('No usable conversion');
const d = response.data;
const preview = {
originalAmount: d.amount, originalCurrency: d.from,
convertedAmount: d.result, targetCurrency: d.to, rate: d.rate,
requestedDate: d.requested_date ?? d.date, referenceDate: d.date,
rolledBack: d.requested_date !== undefined && d.requested_date !== d.date,
display: new Intl.NumberFormat('en', { style: 'currency', currency: d.to }).format(d.result),
};
console.log(preview); // Both dates, rolledBack: true and the display string '€90.00'.
// Example timeseries response for EUR to USD from Thursday 2024-01-04 to Monday 2024-01-08.
const response = { ok: true, data: { base: 'EUR', start: '2024-01-04', end: '2024-01-08',
rates: { '2024-01-04': { USD: 1.09 }, '2024-01-05': { USD: 1.1 }, '2024-01-08': { USD: 1.09 } } } };
const d = response.data;
const start = d.start ?? d.start_date, end = d.end ?? d.end_date;
const points = Object.keys(d.rates).sort().map((day) => ({ day, usd: d.rates[day].USD ?? null }));
const noPublication = [];
for (let t = Date.parse(start); t <= Date.parse(end); t += 86_400_000) {
const day = new Date(t).toISOString().slice(0, 10);
if (!(day in d.rates)) noPublication.push(day);
}
console.log({ points, noPublication, stoppedEarly: d.stop_reason != null });
// Three points, noPublication: ['2024-01-06', '2024-01-07'], stoppedEarly: false.
Server-side request template
This server-side template shows authentication and request identity using the first operation of this API. Choose the operation for your use case and check its current availability and price on the API page. After a timeout, resend the unchanged request with the same Idempotency-Key.
The gateway request is always POST.
Use the documented flat JSON object. Keep the fields at the top level; do not wrap them in body.
# Server-side only. Set KAKIAPI_API_KEY in your secret manager.
# Every gateway operation is called with POST.
# Only operations shown as enabled on the API page can be called.
# Generate once per intent; retain the same value on status checks.
REQUEST_ID="$(uuidgen)"
curl --request POST 'https://kakiapi.com/api/v1/currency/latest' \
--header "Content-Type: application/json" \
--header "x-api-key: $KAKIAPI_API_KEY" \
--header "Idempotency-Key: $REQUEST_ID" \
--data '{"base":"EUR","symbols":"USD,GBP,JPY"}'Integration checklist
- The API key is stored in a server-side secret manager and never sent to a browser.
- Each request carries its own Idempotency-Key, kept until the request has a final answer.
- The integration reads ok and error.code and handles each error code as the error table describes.
- An uncertain POST is inspected using its original identity, never blindly repeated with a new one.
- The operation’s current availability and price have been checked on its API page.
Currency reference rates overview and prices · Read the API reference · Try it in the playground