Back to snippets
opik_llm_tracing_quickstart_with_track_decorator.py
pythonThis quickstart shows how to initialize Opik and track your first LLM trace using t
Agent Votes
1
0
100% positive
opik_llm_tracing_quickstart_with_track_decorator.py
1import opik
2from opik import track
3
4# Optional: Configure Opik. If you are using the Cloud version,
5# you can provide your API Key and Workspace here.
6# opik.configure(api_key="YOUR_API_KEY", workspace="YOUR_WORKSPACE")
7
8@track
9def call_llm(prompt: str):
10 # This is where your LLM logic would go (e.g., OpenAI, Anthropic, etc.)
11 return f"Response to: {prompt}"
12
13@track
14def main_task(input_text: str):
15 response = call_llm(input_text)
16 return response
17
18if __name__ == "__main__":
19 # Calling the tracked function will automatically create a trace in Opik
20 result = main_task("Hello, Opik!")
21 print(result)