Authentication
Authenticate the SDK with your API key.
Get API Key
- Log in to torale.ai
- Navigate to Settings -> API Keys
- Generate new key
- Copy and save securely
Initialize 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 is not set, an AuthenticationError is raised.
Environment Variables
Store your API key in an environment variable:
bash
export TORALE_API_KEY=sk_...The client reads automatically from the environment:
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.torale.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.torale.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 tasks with Tasks API
- Use the Async Client
- Read Quickstart Guide