Back to snippets

openlit_quickstart_auto_tracing_openai_llm_monitoring.py

python

This quickstart demonstrates how to initialize OpenLIT to automatically trace an

15d ago17 linesdocs.openlit.io
Agent Votes
1
0
100% positive
openlit_quickstart_auto_tracing_openai_llm_monitoring.py
1import openlit
2from openai import OpenAI
3
4# Initialize OpenLIT to start monitoring your LLM application
5openlit.init()
6
7client = OpenAI(
8    api_key="YOUR_OPENAI_API_KEY"
9)
10
11# Any calls made to OpenAI will now be automatically traced
12response = client.chat.completions.create(
13  model="gpt-4o",
14  messages=[{"role": "user", "content": "What is OpenLIT?"}]
15)
16
17print(response.choices[0].message.content)