Skip to main content
Both SDKs include convenience helpers for common tasks. These are custom modules that ship alongside the generated SDK code.

Format amounts

Format a numeric amount as a localized currency string:
import { formatAmount } from "@yoshi-ai/sdk/lib/helpers";

formatAmount(1234.5, "USD");         // "$1,234.50"
formatAmount(1234.5, "EUR", "de-DE"); // "1.234,50 €"
formatAmount(999, "JPY");            // "¥999"
The TypeScript helper uses Intl.NumberFormat for locale-aware formatting. The Python helper uses a built-in currency symbol map and is thread-safe.

Supported currencies

The Python helper includes built-in formatting for: USD, EUR, GBP, JPY, CAD, AUD, MXN, BRL, CNY, INR, KRW, and CHF. The TypeScript helper supports any currency code recognized by Intl.NumberFormat.

Generate idempotency keys

Generate a unique key for POST requests to prevent duplicate operations:
import { generateIdempotencyKey } from "@yoshi-ai/sdk/lib/helpers";

const key = generateIdempotencyKey();
// "idk_a1b2c3d4e5f67890a1b2c3d4e5f67890"
Keys are prefixed with idk_ followed by 32 random hex characters. Pass the key in the Idempotency-Key header or the idempotency_key field on supported endpoints like POST /actions:
import Yoshi from "@yoshi-ai/sdk";
import { generateIdempotencyKey } from "@yoshi-ai/sdk/lib/helpers";

const yoshi = new Yoshi();

// The SDK sends the key in the Idempotency-Key header automatically
const action = await yoshi.actions.create({
  action_type: "paper_trade",
  idempotency_key: generateIdempotencyKey(),
  proposal_data: { /* ... */ },
});
If a duplicate key is detected for the same user, the API returns a 409 Conflict response.

Convert between cents and dollars

import { centsToDollars, dollarsToCents } from "@yoshi-ai/sdk/lib/helpers";

centsToDollars(1050);   // 10.5
dollarsToCents(10.5);   // 1050
dollarsToCents(19.99);  // 1999
dollarsToCents / dollars_to_cents rounds the result to avoid floating-point precision issues.
Last modified on April 17, 2026