Code Examples

Official SDKs

Official CurrencyCore clients for TypeScript, Python, Dart, Kotlin, and Swift, with install commands, error handling, retries, and compatibility notes.


CurrencyCore publishes official typed clients for five ecosystems. They wrap the same authenticated HTTP API, handle the base URL and API key, and return typed responses. The API is plain GET, so an SDK is optional; every endpoint page also shows raw cURL and fetch examples.

SDKPackagePlatformsRegistryCurrent line
TypeScript@currencycore/sdkNode, browser, React Nativenpm0.1.x
PythoncurrencycoreCPython 3.xPyPI0.1.x
DartcurrencycoreDart, Flutterpub.dev0.1.x
Kotlin / JVMcom.github.CurrencyCore:currencycore-kotlinAndroid, JVM (usable from Java)JitPack0.1.x
Swiftcurrencycore-swiftiOS, macOSSwift Package Manager0.1.x

These are the complete official set. There is no official Go, PHP, Ruby, .NET or separate Java SDK; the Kotlin/JVM client is usable from Java. Framework pages without an official client use raw HTTP, and the sample app patterns use the SDK where one exists.

Check the registry for the latest patch release before pinning a version. The package repositories are linked at the bottom of this page.

Install

npm install @currencycore/sdk

Quick start

Convert 100 USD to EUR. Pass the key explicitly, or set CURRENCYCORE_API_KEY and omit it.

import { createClient } from "@currencycore/sdk";

const api = createClient({ apiKey: "cc_live_..." });
const res = await api.convert({ from: "USD", to: "EUR", amount: 100 });
console.log(res.results[0]);

The Python from parameter is spelled var_from because from is a reserved word. The Kotlin client is usable from Java as well as Kotlin.

Public endpoints

/currencies and /countries need no key. Construct the client without one:

const api = createClient();
const currencies = await api.currencies();

Error handling

The API returns a consistent error envelope for every non-2xx response:

{
  "error": {
    "code": "rate_limited",
    "message": "Rate limit exceeded...",
    "details": {}
  }
}

When a client exposes the response or an error object, read both the HTTP status and the error.code value. Do not branch on the human-readable message; it can change without notice.

StatusWhat to do
400, 404, 413, 422Fix the request. Retrying unchanged will return the same error.
401Check the key and header format. See Authentication.
402Billing is past due. An owner or admin must clear payment.
403The key is valid but the plan, role, organization toggle, or history window blocks the request. Read the message.
429Per-minute limit or monthly quota. Honor Retry-After when present.
500, 502, 503Transient server or provider failure. Retry with exponential backoff and jitter.

The exact codes are listed in Errors. Error codes are stable enough to branch on; messages are not.

Retries and timeouts

The SDKs make plain HTTP calls. If your client or wrapper retries automatically, keep these rules:

  • Retry only on network errors, 429, and 5xx.
  • Do not retry 400, 401, 402, 403, 404, 413, or 422.
  • Respect Retry-After on 429; otherwise use exponential backoff with jitter.
  • Use a request timeout and cap the total attempts. A short conversion normally returns quickly, while historical analysis can take longer.
  • Make retries idempotent. All CurrencyCore data endpoints are GET, so a retry does not create duplicate records.

If a 429 comes from the monthly quota rather than the per-minute limiter, there may be no Retry-After; check the message and your dashboard usage. See Rate Limits and Plan Quotas.

API key and environment

Every client resolves the key in the same order: the explicit argument first, then CURRENCYCORE_API_KEY. See Authentication for key types, rotation, and 401 troubleshooting.

Never ship a secret key in a browser bundle, mobile app, or anything you distribute. It is extractable. For browser and mobile clients, proxy through your backend or use a key you control at request time. Test keys are still credentials and should not be published.

API version and compatibility

For the data API, the CORS policy only reflects CurrencyCore-owned origins, plus localhost in development. It does not allow arbitrary customer websites, so a browser call from your own origin is blocked even when the key is valid. Use a backend proxy or server-side runtime. Browser and mobile SDK builds are for trusted first-party surfaces, not for shipping a secret in a distributed app.

The base URL is https://api.currency-core.com/{version}, default v1. The version is a client option, so a future /v2 will not disturb an existing integration.

createClient({ version: "v1" });
createClient({ baseUrl: "https://api.currency-core.com/v1" });

The same options exist as create_client(version=...) in Python, createCurrencyCoreClient(version: ...) in Dart, CurrencyCore.client(version = ...) in Kotlin, and CurrencyCore.configure(version: ...) in Swift.

Each SDK is versioned independently from the API. A client 0.1.x release may add endpoints or fields without changing the v1 HTTP contract. Read the package changelog before a major upgrade, and pin a version in production.

Reference

If a package is unavailable for your runtime, use the raw HTTP examples. Need a language that is not covered? Email support.