Skip to main content
W&B Weave makes it easy to track and evaluate your LLM applications. Follow these steps to track your first call.

Install Weave

First install the Weave library:
  • Python
  • TypeScript
pip install weave

Get your API key

Create a Weights & Biases (W&B) account and copy your API key. Your key allows you to authenticate with your W&B account. Once you have secured your API key, you can either set it as an environment variable or enter it when prompted as your code runs. As a best practice, we recommend setting it as the environment variable WANDB_API_KEY. Weave automatically searches for this variable upon execution.

Log a trace to a new project

To begin tracking your code and logging traces to Weave:
  1. Import the weave library into your code.
  2. Call weave.init('your_wb_team/project_name') in your code to send tracking information to your W&B team and project. If you do not set a team, the traces are sent to your default team. If the specified project does not exist in your team, Weave creates it.
  3. Add the @weave.op() decorator to specific functions you want to track. While Weave automatically tracks calls to supported LLMs, adding the Weave decorator allows you to track the inputs, outputs, and code of specific functions. The decorator uses the following syntax in TypeScript: weave.op(your_function)
The following example code sends a request to OpenAI (requires OpenAI API key) and Weave records the request’s tracing information. The request asks the OpenAI model to extract dinosaur names from the input and identify each dinosaur’s diet (herbivore or carnivore). Run the following example code to track your first project with Weave:
  • Python
  • TypeScript
# Imports the Weave library
import weave
from openai import OpenAI

client = OpenAI()

# Weave automatically tracks the inputs, outputs and code of this function
@weave.op()
def extract_dinos(sentence: str) -> dict:
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[
            {
                "role": "system",
                "content": """In JSON format extract a list of `dinosaurs`, with their `name`,
their `common_name`, and whether its `diet` is a herbivore or carnivore"""
            },
            {
                "role": "user",
                "content": sentence
            }
            ],
            response_format={ "type": "json_object" }
        )
    return response.choices[0].message.content

# Initializes Weave, and sets the team and project to log data to
weave.init('quickstart_team/jurassic-park')

sentence = """I watched as a Tyrannosaurus rex (T. rex) chased after a Triceratops (Trike), \
both carnivore and herbivore locked in an ancient dance. Meanwhile, a gentle giant \
Brachiosaurus (Brachi) calmly munched on treetops, blissfully unaware of the chaos below."""

result = extract_dinos(sentence)
print(result)
When you call the extract_dinos function, Weave outputs links to view your traces in the terminal.

See traces of your application in your project

Click the link in your terminal or paste it into your browser to open the Weave UI. In the Traces panel of the Weave UI, you can click on the trace to see its data, such as its input, output, latency, and token usage. Weave Trace Outputs 1

Learn more about Traces

Next Steps

Get started evaluating your app and then see how to evaluate a RAG application.