Observability for DSPy with Opik
DSPy is the framework for programming—rather than prompting—language models.
In this guide, we will showcase how to integrate Opik with DSPy so that all the DSPy calls are logged as traces in Opik.
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 dspy
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 DSPy
In order to configure DSPy, you will need to have your LLM provider API key. For this example, we’ll use OpenAI. You can find or create your OpenAI API Key in this page.
You can set it as an environment variable:
Or set it programmatically:
Logging DSPy calls
In order to log traces to Opik, you will need to set the opik
callback:
The trace is now logged to the Opik platform:

If you set log_graph
to True
in the OpikCallback
, then each module graph is also displayed in the “Agent graph” tab:
