Skip to main content
Open In Colab
Do you want to experiment with OpenAI models on Weave without any set up? Try the LLM Playground.

Tracing

It’s important to store traces of LLM applications in a central database, both during development and in production. You’ll use these traces for debugging and to help build a dataset of tricky examples to evaluate against while improving your application. Weave can automatically capture traces for the openai python library. Start capturing by calling weave.init(<project-name>) with a project name of your choice. OpenAI will be automatically patched regardless of when you import it. If you don’t specify a W&B team when you call weave.init(), your default entity is used. To find or update your default entity, refer to User Settings in the W&B Models documentation. Automatic Patching Weave automatically patches OpenAI whether imported before or after weave.init():
Explicit Patching (Optional) You can still explicitly patch if you want fine-grained control:
View a live trace
We capture the function calling tools for OpenAI Functions and OpenAI Assistants as well.

Structured Outputs

Weave also supports structured outputs with OpenAI. This is useful for ensuring that your LLM responses follow a specific format.

Async Support

Weave also supports async functions for OpenAI.

Streaming Support

Weave also supports streaming responses from OpenAI.

Tracing Function Calls

Weave also traces function calls made by OpenAI when using tools.

Batch API

Weave also supports the OpenAI Batch API for processing multiple requests.

Assistants API

Weave also supports the OpenAI Assistants API for building conversational AI applications.

Cost Tracking

Weave automatically tracks the cost of your OpenAI API calls. You can view the cost breakdown in the Weave UI.
Cost tracking is available for all OpenAI models and is calculated based on the latest OpenAI pricing.

Tracing Custom Functions

You can also trace custom functions that use OpenAI by using the @weave.op decorator.

Next Steps

Now that you’ve set up tracing for OpenAI, you can:
  1. View traces in the Weave UI: Go to your Weave project to see traces of your OpenAI calls
  2. Create evaluations: Use your traces to build evaluation datasets
  3. Monitor performance: Track latency, costs, and other metrics
  4. Debug issues: Use traces to understand what’s happening in your LLM application
For more information on these topics, check out our evaluation guide and monitoring guide.