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 Assistant 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 Assistant API URL

The SDK also needs the Assistant API base URL. If your team provides a hosted Assistant API URL, set it with CUSTODIAN_SDK_BASE_URL. If your project already provides the API environment, use the value configured for that environment.

On macOS or Linux:

export CUSTODIAN_SDK_BASE_URL="https://your-assistant-api.example.com/v1"

On Windows PowerShell:

$env:CUSTODIAN_SDK_BASE_URL="https://your-assistant-api.example.com/v1"

Advanced Configuration

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

from custodian_labs import create_assistant

app = create_assistant(
model="gpt-4o",
prompt="You are a helpful assistant.",
api_key="custodian_labs_xxx...",
base_url="https://your-assistant-api.example.com/v1",
)

Explicitly passed values take priority over environment variables.

note

AssistantBuilder 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 Assistant.