Openlayer Python SDK

raw JSON →
0.24.0 verified Mon Apr 27 auth: no python

The official Python SDK for the Openlayer API. Provides tools to monitor, debug, and improve AI models with tracing, observability, and data management. Current version: 0.24.0. Release cadence: weekly to multiple times per week.

pip install openlayer
error ModuleNotFoundError: No module named 'openlayer'
cause The package is not installed, or installed in a different environment.
fix
Run: pip install openlayer
error TypeError: create() missing 2 required positional arguments: 'project_id' and 'model_id'
cause Using old positional argument style with new SDK version (>=0.19.0).
fix
Use: client.traces.create(project_id='...', model_id='...')
error openlayer.OpenlayerError: Authentication failed. Invalid API key.
cause Missing or incorrect API key. The OPENLAYER_API_KEY environment variable is not set, or the key is wrong.
fix
Set OPENLAYER_API_KEY in your environment or pass api_key explicitly.
breaking In v0.20.0, client initialization changed: the `api_key` parameter is now required (previously optional). Code that relied on environment variable auto-detection without passing it explicitly may break.
fix Always pass api_key=os.environ.get('OPENLAYER_API_KEY') explicitly.
deprecated The `openlayer.traces.create` method signature changed in v0.19.0: `project_id` and `model_id` became mandatory keyword-only arguments. Passing them as positional arguments will raise TypeError.
fix Use named arguments: client.traces.create(project_id='...', model_id='...').
gotcha Pydantic 2.10+ compatibility fix in v0.20.1: if you use Pydantic v2.10+ without updating openlayer, you may see AttributeError regarding 'by_alias'. Upgrade openlayer to >=0.20.1.
fix Run: pip install 'openlayer>=0.20.1'

Initialize the client and create a trace.

from openlayer import Openlayer

client = Openlayer(api_key=os.environ.get('OPENLAYER_API_KEY', ''))
# Example: create a trace
trace = client.traces.create(
    project_id='your-project-id',
    model_id='your-model-id',
    input='What is the capital of France?',
    output='Paris'
)
print(trace.id)