Constaia

Authentication

Authenticate Constaia API calls with ck_live_ and ck_test_ Bearer keys, where to create and revoke them, and why they never go in the browser.

Esta página ainda não está traduzida para o seu idioma. Mostramos a versão em inglês.

Every call to https://api.constaia.com/v1 (except the public document type catalogue and the signed export downloads) is authenticated with a secret key in the Authorization header:

curl https://api.constaia.com/v1/balance \
  -H "Authorization: Bearer $CONSTAIA_API_KEY"

Key format

PrefixModeWhat it does
ck_test_…TestSimulated provider with deterministic responses based on the file name. Free, livemode: false. See Test mode.
ck_live_…LiveAnalyses documents for real and spends credits. livemode: true.

The prefix is followed by 24 to 64 alphanumeric characters. The key decides the mode, not a request parameter: the same code runs in test and live by changing only the environment variable.

Creating and revoking keys

Keys are managed in the dashboard, under API keys:

  • A test key is created when you sign up so you can start without any setup.
  • To create a live key you must have confirmed your email. Otherwise the dashboard answers with the email_not_verified error. If you signed up with Google or GitHub, your email is already verified.
  • Each key is shown only once, when it is created. Copy it to your secret manager at that moment.
  • Constaia stores only a SHA-256 hash of the key: we cannot recover it or show it again. If you lose it, create a new one and revoke the old one.
  • A revoked key stops working immediately and returns 401 invalid_api_key.

To rotate keys without downtime (create the new one, deploy, revoke the old one) follow the steps in Security.

Authentication errors

HTTPcodeWhen
401missing_api_keyThe Authorization: Bearer … header is missing or malformed.
401invalid_api_keyThe key does not match the ck_live_/ck_test_ format, does not exist or has been revoked.
401 response
{
  "error": {
    "type": "authentication",
    "code": "missing_api_key",
    "message": "Falta la cabecera Authorization: Bearer <api_key>.",
    "request_id": "req_01M3PD48ARCDHXGT0XECMARCPD"
  }
}

Every error follows this shape. See Errors.

The key lives on your server

Never in the browser or a mobile app

A ck_live_ or ck_test_ key gives access to your account and your credits. Do not put it in frontend code, a mobile app, a repository or NEXT_PUBLIC_*/VITE_* variables. Your frontend or app sends the file to your backend, and your backend calls Constaia.

The API has open CORS on /v1, but that does not change the rule: the JavaScript SDK throws secret_key_in_browser if it detects a key in a browser, and the widget rejects any attribute that looks like a key. Publishable browser keys do not exist yet.

Coming soon

Publishable (browser) keys with limited permissions.

CONSTAIA_API_KEY environment variable

Store the key in CONSTAIA_API_KEY. The JavaScript, PHP and Python SDKs and the MCP server read it automatically when you do not pass a key.

.env
CONSTAIA_API_KEY=ck_test_...

Minimal examples

They all call GET /v1/balance, which spends no credits.

curl https://api.constaia.com/v1/balance \
  -H "Authorization: Bearer $CONSTAIA_API_KEY"

Every response carries an X-Request-Id: req_… header. Keep it in your logs and include it if you contact us about a problem.

Next steps

Nesta página