Authentication
Authenticate the SDK with your API key.
Naming during the transition
Environment variable names and the client class still use torale (TORALE_API_KEY, Torale). The rename to webwhen is a later phase.
Get an API key
- Log in to webwhen.ai
- Navigate to Settings → API Keys
- Generate a new key
- Copy and save it securely
Initialize the client
python
from torale import Torale
client = Torale(api_key="sk_...")API key resolution order
The client resolves the API key in this order:
api_keyparameter passed to the constructorTORALE_API_KEYenvironment variable~/.torale/config.jsonfile
If no key is found and TORALE_NOAUTH isn't set, an AuthenticationError is raised.
Environment variables
Store your API key in an environment variable:
bash
export TORALE_API_KEY=sk_...The client reads it automatically:
python
from torale import Torale
client = Torale() # Reads from TORALE_API_KEYUsing .env files
python
from dotenv import load_dotenv
from torale import Torale
load_dotenv()
client = Torale()Config file
The SDK reads from ~/.torale/config.json if it exists:
json
{
"api_key": "sk_...",
"api_url": "https://api.webwhen.ai"
}Local development
For local development without authentication:
python
import os
os.environ["TORALE_NOAUTH"] = "1"
from torale import Torale
client = Torale() # Connects to http://localhost:8000, no API key requiredFor local development with authentication:
python
import os
os.environ["TORALE_DEV"] = "1"
from torale import Torale
client = Torale(api_key="sk_...") # Connects to http://localhost:8000API URL resolution
The base URL is resolved in this order:
api_urlparameter passed to the constructorTORALE_API_URLenvironment variablehttp://localhost:8000ifTORALE_DEV=1orTORALE_NOAUTH=1api_urlfrom~/.torale/config.jsonhttps://api.webwhen.ai(default)
Error handling
python
from torale import Torale
from torale.sdk.exceptions import AuthenticationError
try:
client = Torale(api_key="sk_invalid")
tasks = client.tasks.list()
except AuthenticationError:
print("Invalid API key")Next steps
- Create watches with the Watches API
- Use the Async Client
- Read the Quickstart Guide