Skip to main content
The Docent SDK authenticates via API keys. You can provide your key in several ways, listed here in order of precedence.

API Key

1. Direct Parameter

from docent import Docent

client = Docent(api_key="your-api-key")

2. Environment Variable

export DOCENT_API_KEY="your-api-key"
from docent import Docent

client = Docent()  # Reads DOCENT_API_KEY from environment

3. Config File

Create a docent.env file in your project directory:
DOCENT_API_KEY=your-api-key
DOCENT_COLLECTION_ID=my-default-collection
The SDK searches for docent.env starting from the current working directory and traversing up the directory tree. You can also specify an explicit path:
client = Docent(config_file="/path/to/my-config.env")

Configuration Priority

The SDK resolves each setting using a priority order. The exact order varies slightly by setting:
SettingPriority (highest to lowest)
api_keyDirect parameter → config file → DOCENT_API_KEY env var
api_url / frontend_urlDirect parameter → DOCENT_API_URL / DOCENT_FRONTEND_URL env var → config file
domainDirect parameter → DOCENT_DOMAIN env var → config file → "docent.transluce.org"
collection_idDirect parameter → config file
collection_id is not read from environment variables — set it via a direct parameter or in your docent.env config file.

Environment Variables

VariableDescriptionDefault
DOCENT_API_KEYAPI key for authenticationRequired
DOCENT_API_URLDirect API server URLDerived from domain
DOCENT_FRONTEND_URLDirect frontend URLDerived from domain
DOCENT_DOMAINDocent instance domaindocent.transluce.org

Config File Format

The config file uses dotenv format. Supported keys:
DOCENT_API_KEY=your-api-key
DOCENT_API_URL=https://api.docent.transluce.org
DOCENT_FRONTEND_URL=https://docent.transluce.org
DOCENT_DOMAIN=docent.transluce.org
DOCENT_COLLECTION_ID=my-collection

Self-Hosted Instances

For self-hosted Docent instances, set both the API and frontend URLs:
client = Docent(
    api_key="your-api-key",
    api_url="https://api.my-docent.example.com",
    frontend_url="https://my-docent.example.com",
)
Or via environment variables:
export DOCENT_API_URL="https://api.my-docent.example.com"
export DOCENT_FRONTEND_URL="https://my-docent.example.com"
Local domains (localhost, 127.0.0.1) require explicit api_url and frontend_url. The SDK cannot derive URLs from local domains automatically.
For more on self-hosted deployments, see Self-Host Docent.