Skip to main content
This is an interactive notebook. You can run it locally or use the links below:

🔑 Prerequisites

Before you can begin tracing in Weave, complete the following prerequisites.
  1. Install the W&B Weave SDK and log in with your API key.
  2. Install the OpenAI SDK and log in with your API key.
  3. Initialize your W&B project.

🐝 Run your first trace

The following code sample shows how to capture and visualize a trace in Weave using the @weave.op decorator. It defines a function called extract_fruit that sends a prompt to OpenAI’s GPT-4o to extract structured data (fruit, color, and flavor) from a sentence. By decorating the function with @weave.op, Weave automatically tracks the function execution, including inputs, outputs, and intermediate steps. When the function is called with a sample sentence, the full trace is saved and viewable in the Weave UI.

🚀 Looking for more examples?