Skip to main content

Installation

The Foil Python SDK provides automatic OpenAI instrumentation and logging for Python applications.

Requirements

  • Python 3.8 or higher
  • pip

Install via pip

pip install foil-sdk
Or with poetry:
poetry add foil-sdk

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

OptionTypeRequiredDefaultDescription
api_keystrYes-Your Foil API key
base_urlstrNohttps://api.getfoil.aiAPI 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