Skip to main content

Authenticate the Python SDK

The Python SDK authenticates requests with your Custodian Labs API key. The SDK sends the key to the Platform API using the X-API-Key header.

Before You Begin

Generate an API key from your Custodian Labs Dashboard. For details, see Get Your API Key.

Treat your API key like a password:

  • Do not commit it to Git.
  • Do not include it in client-side code.
  • Do not share it in screenshots, messages, or public documentation.
  • Rotate it if it is exposed.

Use a placeholder in examples:

custodian_labs_xxx...

Set Your API Key

Store your API key in the CUSTODIAN_SDK_API_KEY environment variable.

On macOS or Linux:

export CUSTODIAN_SDK_API_KEY="custodian_labs_xxx..."

On Windows PowerShell:

$env:CUSTODIAN_SDK_API_KEY="custodian_labs_xxx..."

Once the variable is set, SDK objects read it automatically:

You do not need to include the API key in your Python code.

You can also store the same variable in a .env file if your application loads environment variables from one:

CUSTODIAN_SDK_API_KEY="custodian_labs_xxx..."

Make sure the .env file is loaded before creating SDK objects. The SDK reads from the environment; it does not load .env files automatically.

Configure the Platform API URL

The SDK talks to the Custodian Labs Platform API. By default it uses https://platform.custodianlabs.io/v1. If you need to override it, set CUSTODIAN_SDK_BASE_URL.

On macOS or Linux:

export CUSTODIAN_SDK_BASE_URL="https://platform.custodianlabs.io/v1"

On Windows PowerShell:

$env:CUSTODIAN_SDK_BASE_URL="https://platform.custodianlabs.io/v1"

Advanced Configuration

If your application manages multiple keys or API environments in the same process, pass api_key and base_url directly to Custodian:

from custodian_labs import Custodian

custodian = Custodian(
model="gpt-4o",
system_prompt="You are a helpful assistant.",
api_key="custodian_labs_xxx...",
base_url="https://platform.custodianlabs.io/v1",
)
app = custodian.deploy()

Explicitly passed values take priority over environment variables.

note

CustodianBuilder currently reads the API key and API URL from environment variables. It does not accept api_key or base_url arguments directly.

Next Step

Continue to Create Your First Custodian.