Manual Logger with Streaming
Learn how to use Helicone’s Manual Logger to track streaming LLM responses
Manual Logger with Streaming Support
Helicone’s Manual Logger provides powerful capabilities for tracking LLM requests and responses, including streaming responses. This guide will show you how to use the @helicone/helpers
package to log streaming responses from various LLM providers.
Installation
First, install the @helicone/helpers
package:
Basic Setup
Initialize the HeliconeManualLogger with your API key:
Streaming Methods
The HeliconeManualLogger provides three main methods for working with streams:
1. logStream
The most flexible method that gives you full control over stream handling:
2. logSingleStream
A simplified method for logging a single ReadableStream:
3. logSingleRequest
For logging a single request with a response body:
Examples with Different LLM Providers
OpenAI
Together AI
Anthropic
Next.js API Route Example
Here’s how to use the manual logger in a Next.js API route:
Next.js App Router with Vercel’s after
Function
For Next.js App Router, you can use Vercel’s after
function to log requests without blocking the response:
The after
function from Next.js allows you to perform operations after the response has been sent to the client, which is ideal for logging. This approach ensures that logging doesn’t delay the response to the user.
Logging Custom Events
You can also use the manual logger to log custom events:
Advanced Usage: Tracking Time to First Token
The logStream
method automatically tracks the time to first token, which is a valuable metric for understanding LLM response latency:
This timing information will be available in your Helicone dashboard, allowing you to monitor and optimize your LLM response times.
Conclusion
The HeliconeManualLogger provides powerful capabilities for tracking streaming LLM responses across different providers. By using the appropriate method for your use case, you can gain valuable insights into your LLM usage while maintaining the benefits of streaming responses.
Was this page helpful?