Observability for TypeSafe AI (Python) with Opik
Observability for TypeSafe AI (Python) with Opik
TypeSafe AI provides System One models such as Jev: instead of generating text, they answer typed questions (yes/no, choice, score) about a piece of state and return calibrated probabilities that software can act on directly.
This guide explains how to integrate Opik with the TypeSafe AI Python SDK (typesafe-sdk). By using the track_typesafe method provided by Opik, you can easily track and evaluate your TypeSafe AI calls within your Opik projects as Opik will automatically log the questions you asked, the model used, token usage, and the answers returned.
TypeSafe AI is currently in early access. This integration targets typesafe-sdk version 0.7.0 or newer.
Account Setup
Comet provides a hosted version of the Opik platform, simply create an account and grab your API Key.
You can also run the Opik platform locally, see the installation guide for more information.
Getting Started
Installation
First, ensure you have both opik and typesafe-sdk packages installed:
Configuring Opik
Configure the Opik Python SDK for your deployment type. See the Python SDK Configuration guide for detailed instructions on:
- CLI configuration:
opik configure - Code configuration:
opik.configure() - Self-hosted vs Cloud vs Enterprise setup
- Configuration files and environment variables
Configuring TypeSafe AI
In order to configure TypeSafe AI, you will need to have your TypeSafe AI API key. You can create one in the TypeSafe AI console.
You can set it as an environment variable:
Or set it programmatically:
Logging TypeSafe AI calls
In order to log TypeSafe AI calls to Opik, wrap the TypeSafe client with track_typesafe. All calls made with the wrapped client will be logged to Opik. If the call is made inside a function decorated with @track, it is logged as part of that function’s trace, so you can see the decision in the context of the step that requested it:
The trace can now be viewed in the Opik UI, with the TypeSafe AI call nested under the triage_ticket step. Custom request headers are never logged, so credentials do not end up in your traces.
track_typesafe works the same way with the async client:
Tracking plain HTTP requests
If you call the TypeSafe AI REST API directly instead of using typesafe-sdk, you can still log the calls to Opik. Wrap the request in a function decorated with @track(type="llm") and, before returning, use opik_context.update_current_span to record the usage, provider and model:
The call then appears in Opik the same way as a call made through track_typesafe.
Supported Methods
track_typesafe logs calls to the following methods:
TypeSafeClient.system_one()AsyncTypeSafeClient.system_one()