Skip to main content

Authentication

The SDK authenticates with your Custodian Labs API key, sent as an X-API-Key header. You can provide it with an environment variable or a constructor option.

Environment variables

VariableDefaultPurpose
CUSTODIAN_SDK_API_KEYAPI key for assistant / agent calls
CUSTODIAN_SDK_BASE_URLhttps://platform.custodianlabs.io/v1Override the Platform API host
CUSTODIAN_MASKING_BASE_URLhttps://privacy.custodianlabs.ioOverride the Guardian Layer host

Legacy aliases AI_SDK_API_KEY and AI_SDK_BASE_URL are still read for backwards compatibility.

export CUSTODIAN_SDK_API_KEY="custodian_labs_xxxxxxxx"
import { createCustodian } from "@custodianlabs/sdk";

// Key picked up from CUSTODIAN_SDK_API_KEY
const app = await createCustodian({ model: "gpt-4o", prompt: "You are helpful." });

Constructor options

Any of the values above can be passed explicitly instead:

import { Custodian } from "@custodianlabs/sdk";

const custodian = new Custodian({
model: "gpt-4o",
systemPrompt: "You are a helpful assistant",
apiKey: process.env.MY_KEY,
baseUrl: "https://platform.custodianlabs.io/v1",
timeout: 30, // seconds
maxRetries: 2,
});

Keep your key server-side

Do not ship your API key to the browser. Call the SDK from a backend, serverless function, or edge handler, and expose only the results to your frontend.

Next step

Continue to Create your first Custodian.