Skip to main content
This guide shows you how to use W&B Weave with Serverless Inference to learn Weave fundamentals. Use Serverless Inference to build and trace LLM applications using live open source models without setting up your own infrastructure or managing API keys from multiple providers. With your W&B API key, you can interact with all models hosted by Serverless Inference. By the end of this guide, you’ll have traced LLM calls, compared models, and run an evaluation that you can review in the Weave UI.

What you’ll learn

This guide shows you how to:
  • Set up Weave and Serverless Inference.
  • Build a basic LLM application with automatic tracing.
  • Compare multiple models.
  • Evaluate model performance on a dataset.
  • View your results in the Weave UI.

Prerequisites

  • A W&B account
  • Python 3.10+ or Node.js 18+
  • Required packages installed:
    • Python: pip install weave openai
    • TypeScript: npm install weave openai
  • An OpenAI API key set as an environment variable.

Trace your first LLM call

This section shows you how to make a single LLM call and have Weave trace it automatically, so you can confirm your setup is working before moving on to more complex examples. To begin, copy and paste the following code example. The code example uses Llama 3.1-8B from Serverless Inference. When you run this code, Weave:
  • Traces your LLM call automatically.
  • Logs inputs, outputs, latency, and token usage.
  • Provides a link to view your trace in the Weave UI.

Build a text summarization application

Now that you’ve traced a single LLM call, this section shows how Weave traces nested operations across multiple functions, so you can see how a real multi-step LLM application is captured in the UI. Next, run this code, which is a basic summarization app that shows how Weave traces nested operations:

Compare multiple models

A common use case for Weave is comparing how different models respond to the same prompt. Serverless Inference provides access to multiple models. Use the following code to compare the performance of Llama and DeepSeek’s respective responses:

Evaluate model performance

Going beyond ad-hoc comparisons, this section shows you how to run a structured evaluation across a dataset so you can systematically measure and compare model quality. Evaluate how well a model performs on a Q&A task using Weave’s built-in EvaluationLogger. This provides structured evaluation tracking with automatic aggregation, token usage capture, and rich comparison features in the UI. Append the following code to the script you used in the prior section:
After you run these examples, you have traced LLM calls, a nested summarization pipeline, a model comparison, and a full evaluation logged to Weave. Running these examples returns links to the traces in the terminal. Click any link to view traces in the Weave UI. In the Weave UI, you can:
  • Review a timeline of all your LLM calls.
  • Inspect inputs and outputs for each operation.
  • View token usage and estimated costs (automatically captured by EvaluationLogger).
  • Analyze latency and performance metrics.
  • Navigate to the Evals tab to see aggregated evaluation results.
  • Use the Compare feature to analyze performance across different models.
  • Page through specific examples to see how different models performed on the same inputs.

Available models

For a complete list of available models, see the Available Models section in the Serverless Inference documentation.

Next steps

With the basics in place, the following resources help you go deeper with Weave and Serverless Inference:

Troubleshooting