weave.init(). This guide explains how to use Weave with LiteLLM to capture traces, wrap calls in versioned ops, organize experiments with a Model, and track function-calling behavior. Use it when you’re building LLM applications and want observability across the multiple model providers that LiteLLM supports.
Traces
It’s important to store traces of LLM applications in a central database, both during development and in production. You use these traces for debugging and as a dataset that helps you improve your application.Note: When using LiteLLM, make sure to import the library usingWeave automatically captures traces for LiteLLM. Use the library as usual, and start by callingimport litellmand call the completion function withlitellm.completion()instead offrom litellm import completion. This ensures that all functions and parameters are correctly referenced.
weave.init():
Wrap with your own ops
Weave ops make results reproducible by automatically versioning code as you experiment, and they capture their inputs and outputs. Create a function decorated with@weave.op() that calls into LiteLLM’s completion function, and Weave tracks the inputs and outputs for you. Here’s an example:
Create a Model for easier experimentation
Organizing experimentation is difficult when many pieces move at once. By using the Model class, you can capture and organize the experimental details of your app, such as your system prompt or the model you’re using. This helps you organize and compare different iterations of your app.
In addition to versioning code and capturing inputs and outputs, Models capture structured parameters that control your application’s behavior, helping you find which parameters work best. You can also use Weave Models with serve and Evaluations.
In the following example, you can experiment with different models and temperatures:
Function calling
LiteLLM supports function calling for compatible models. Weave automatically tracks these function calls so you can inspect the functions, arguments, and responses alongside your other traces.