This example demonstrates how to use the LaunchDarkly observability SDK plugin to monitor AI chat operations. For more details, see the Python SDK observability reference.
The observability plugin automatically captures and sends data to LaunchDarkly:
- Observability tab: SDK operations, flag evaluations, error monitoring, logging, and distributed tracing
- AI Config Monitoring tab: Token usage, duration, success/error rates, and custom metadata for filtering and analysis
View your data in the LaunchDarkly dashboard under Observability tabs.
- Python 3.10 or higher
- Poetry installed
- A LaunchDarkly account and SDK key
- An API key for your AI provider (e.g., OpenAI)
-
Create the following config in your LaunchDarkly project. You can use a different key by setting the environment variable in your
.env.- Create an AI Config with a model and a system message. Default key:
sample-completion-config.
- Create an AI Config with a model and a system message. Default key:
-
Create a
.envfile in this directory with the following variables:LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key LAUNCHDARKLY_AI_CONFIG_KEY=sample-completion-config OPENAI_API_KEY=your-openai-api-keyOptionally, set service identification:
SERVICE_NAME=my-ai-service SERVICE_VERSION=1.0.0 -
Install the required dependencies:
poetry install
poetry run chat