API keys

The four kinds of Preczn API keys, their prefixes, and where each one goes.

Every request to Preczn carries an API key. A key's type decides where it goes, and its mode decides which data it reaches.


Key types

Each key is public or private, and belongs to Test mode or Live mode. The prefix shows both.

KeyPrefixWhere it goes
Private, Test modepriv_test_Your server, during development
Private, Live modepriv_Your server, in production
Public, Test modepub_test_Preczn's browser clients, during development
Public, Live modepub_Preczn's browser clients, in production

A key's mode is set when you create the key and never changes. A Test mode key reaches only Test mode data, and a Live mode key reaches only Live mode data. See Live vs. test mode.

Keys don't expire. A key works until you disable or delete it. See Manage API keys.


Private keys

Use a private key for every endpoint in the API reference. Send it in the x-api-key header of each request, from your server only.

❗️

Never expose a private key

Keep private keys out of browser code, HTML, mobile apps, and source repositories. Store them in environment variables or a secrets manager. If a private key might be exposed, generate a replacement, switch your integration to it, and disable the old key. See Manage API keys.


Public keys

Use a public key only in Preczn's browser clients, which collect payment details in the customer's browser and turn them into single-use tokens. Your server then sends the token with a private key. A public key can't call the endpoints in the API reference. See Choose an integration method.


Default keys

Each new platform starts with two Test mode keys, named Default Private Key and Default Public Key. You can use them for development right away.


Key errors

A request with a missing, unknown, or disabled key returns 401. A request with the wrong type of key, such as a public key on an endpoint that needs a private key, returns 403. See API key errors.


Did this page help you?