Installation
The Foil Python SDK provides automatic OpenAI instrumentation and logging for Python applications.
Requirements
Install via pip
Or with poetry:
Configuration
API Key
Get your API key from the Foil Dashboard under Settings > API Keys.
Never hardcode API keys in your source code. Use environment variables instead.
# .env or shell
export FOIL_API_KEY=sk_live_xxx_yyy
Initialize the Client
import os
from foil import Foil
foil = Foil(api_key=os.environ['FOIL_API_KEY'])
Configuration Options
| Option | Type | Required | Default | Description |
|---|
api_key | str | Yes | - | Your Foil API key |
base_url | str | No | https://api.getfoil.ai | API endpoint URL |
Custom Base URL
For self-hosted deployments:
foil = Foil(
api_key=os.environ['FOIL_API_KEY'],
base_url='https://your-foil-instance.com/api'
)
Verify Installation
from foil import Foil
import os
foil = Foil(api_key=os.environ['FOIL_API_KEY'])
# Test with a simple log
foil.log({
'model': 'test',
'input': 'Hello',
'output': 'World'
})
print('Foil SDK installed successfully!')
Next Steps