Skip to main content
Open In Colab Weave automatically tracks and logs LLM calls made through LiteLLM after you call 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 using import litellm and call the completion function with litellm.completion() instead of from litellm import completion. This ensures that all functions and parameters are correctly referenced.
Weave automatically captures traces for LiteLLM. Use the library as usual, and start by calling weave.init():
Weave now tracks and logs all LLM calls made through LiteLLM. You can view the traces in the Weave web interface. With basic tracing in place, the next section shows how to wrap LiteLLM calls in your own Weave ops to gain finer-grained, versioned tracking of your application logic.

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.
Weave automatically captures the functions you use in the prompt and keeps them versioned. litellm.gif