Skip to main content

Part 4: Monitoring and verifying data

LaunchDarkly provides monitoring for AI Configs. Next, ensure your data flows correctly. To learn more about monitoring capabilities, read Monitor AI Configs.

Step 4.1: Understanding AI metrics

LaunchDarkly AI SDKs provide comprehensive metrics tracking to help you monitor and optimize your AI model performance. The SDK includes both individual track* methods and provider-specific convenience methods for recording metrics. Available metrics include:
  • Duration: Time taken for AI model generation, including network latency
  • Token Usage: Input, output, and total tokens consumed (critical for cost management)
  • Generation Success: Successful completion of AI generation
  • Generation Error: Failed generations with error tracking
  • Time to First Token: Latency until the first response token (important for streaming)
  • Output Satisfaction: User feedback (positive/negative ratings)

Tracking Methods

The AI SDKs provide two approaches to recording metrics:
  • Provider-Specific Methods: Convenience methods like track_openai_metrics() or track_duration_of() that automatically record duration, token usage, and success/error in one call
  • Individual Track Methods: Granular methods like track_duration(), track_tokens(), track_success(), track_error(), and track_feedback() for manual metric recording
The tracker object is returned from your completion_config() call and is specific to that AI Config variation. Always call config() again each time you generate content to ensure metrics are correctly associated with the right variation. For delayed feedback, such as user ratings that arrive after generation, use tracker.get_track_data() to persist the tracking metadata. Then, send feedback events later using ldclient.track() with the original context and metadata. To learn more about tracking AI metrics, read Tracking AI metrics.

Step 4.2: Add comprehensive tracking

Create a file called simple_chatbot_with_targeting_and_tracking.py:

Step 4.3: Testing complete monitoring flow

To test the monitoring flow:

Step 4.4: Verify data in Launch

Darkly After running the monitored chatbot:
  1. Navigate to AI Configs.
  2. Select simple-chatbot-config.
  3. View the Monitoring tab.
The monitoring dashboard provides real-time insights into your AI Config’s performance:
AI Config monitoring dashboard overview

AI Config monitoring dashboard overview

In the dashboard, you see several key sections:
  • Usage Overview: Displays the total number of requests served by your AI Config, broken down by variation. This helps you understand which configurations are used most frequently.
  • Performance Metrics: Shows response times and success rates for each interaction. A healthy AI Config should maintain high success rates (typically 95%+) and consistent response times.
  • Cost Analysis: Tracks token usage across different models and providers, helping you optimize spending. Token tracking is essential for cost management and performance optimization. You can see both input and output token counts, which directly correlate to your AI provider costs.
Detailed token usage and cost tracking metrics

Detailed token usage and cost tracking metrics

The token metrics include:
  • Input Tokens: The number of tokens sent to the model, including prompt and context. Longer conversations accumulate more input tokens as history grows.
  • Output Tokens: The number of tokens generated by the model in responses. This varies based on your max_tokens parameter and the model’s verbosity.
  • Total Token Usage: Combined input and output tokens, which determines your provider billing. Monitor this to predict costs and identify optimization opportunities.
  • Tokens by Variation: Compare token usage across different variations to identify which configurations are most efficient for your use case.
To learn more about monitoring and metrics, read Monitor AI Configs.