Creating a client
Every call goes through a client, created once and reused:API key resolution
An argument passed to the client wins over the environment variable, which wins over the default. Prefer the environment variable, or a value read from your secrets manager at startup, over a key written in the code. Without a usable key, creating the client fails before any request:- no key at all, neither as an argument nor in
KARDINAL_API_KEY:MissingApiKeyError; - an empty string passed explicitly:
EmptyApiKeyError, rather than a silent fallback to the environment variable.
Keeping the key server-side
An API key gives full access to its agency’s plans, and is valid for 366 days. Use it from a server, a worker, or a script, never from code that runs in a browser or a mobile app:- Never put the key in a front-end bundle. Frameworks copy into the bundle every environment variable with a public prefix, such as
NEXT_PUBLIC_,VITE_, orPUBLIC_: name the variableKARDINAL_API_KEY, without such a prefix. - Don’t call the API from a browser at all. The TypeScript SDK targets Node.js only, and the API doesn’t answer cross-origin requests.
- If a front end needs routes, expose your own endpoint that calls Kardinal from your server.
Sandbox and production
Sandbox and production are two agencies of the same account, served by the same host: the key alone decides which agency a call applies to. Switching to production means switching the key, not the code — keep oneKARDINAL_API_KEY value per deployment environment.
You don’t need to set base_url / baseUrl or KARDINAL_BASE_URL: the default is the public API. See Moving from sandbox to production for what else differs between the two agencies.
Timeouts and retries
- Python
- TypeScript
timeout, in seconds, is passed to httpx, which applies it to each phase of a request separately (connecting, sending, each read of the response), not to the request as a whole.max_retries / maxRetries is how many times a read, update, delete, start, or stop is retried after a network error, a 429, or a 5xx. submit is never retried: see What the SDKs retry.
Closing the client
- Python
- TypeScript
The client holds an
httpx connection pool. Use it as a context manager, or close it when you’re done:Troubleshooting authentication
kardinal auth check reads the same environment variables as the client, so it diagnoses exactly the configuration your code runs with.
