Experiment with OpenAI models on Weave without any setup using the LLM Playground.
Tracing
Storing traces of LLM applications in a central database is valuable both during development and in production. Use these traces for debugging and to help build a dataset of tricky examples to evaluate against while you improve your application. Weave can automatically capture traces for theopenai Python library.
To start capturing, call weave.init("[PROJECT_NAME]") with a project name of your choice. Weave automatically patches OpenAI regardless of when you import it, so all subsequent OpenAI calls are traced.
If you don’t specify a W&B team when you call weave.init(), Weave uses your default entity. To find or update your default entity, refer to User Settings in the W&B Models documentation.
Automatic patching
Weave automatically patches OpenAI whether you import it before or afterweave.init(). The following example shows the minimal setup you need to start tracing calls:
Optional: Explicit patching
For fine-grained control over when patching takes effect, patch OpenAI explicitly instead of relying on the automatic behavior:Structured outputs
Weave supports tracing OpenAI structured outputs, which are useful when you need to ensure your LLM responses follow a specific format. The following example traces a call that extracts a typedUserDetail object from a user message:
Async support
Weave supports tracing async OpenAI calls, so applications that useAsyncOpenAI get the same visibility as synchronous applications.
Streaming support
Weave supports tracing streaming responses from OpenAI. The captured trace reflects the full streamed completion, so you can review the final output alongside the request parameters.Tracing function calls
Weave traces function calls made by OpenAI when you use tools, which helps you understand how the model invoked each tool and with what arguments.Batch API
Weave supports the OpenAI Batch API, which lets you process multiple requests asynchronously while Weave still captures each request in your traces.Assistants API
Weave supports the OpenAI Assistants API, so you can trace conversational AI applications built around assistants, threads, and runs.Cost tracking
Weave automatically tracks the cost of your OpenAI API calls so that you can monitor spend alongside performance. You can view the cost breakdown in the Weave UI.Cost tracking is available for all OpenAI models, and Weave calculates costs based on OpenAI’s published pricing.
Tracing custom functions
To group OpenAI calls under your own application logic, trace custom functions that use OpenAI by applying the@weave.op decorator. This produces a parent trace for the function with the underlying OpenAI calls nested inside it.
Next steps
With tracing set up for OpenAI, your application’s calls are now visible in Weave. From here, you can:- View traces in the Weave UI: Go to your Weave project to see traces of your OpenAI calls.
- Create evaluations: Use your traces to build evaluation datasets.
- Monitor performance: Track latency, costs, and other metrics.
- Debug issues: Use traces to understand what’s happening in your LLM application.