hey, how to log the openai reponses if using strea...
# ask-ai
c
hey, how to log the openai reponses if using streaming in livekit. like how to see what openai is sending back after a request?
t
Thanks for reaching out, Clovis. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To log OpenAI responses when using streaming in LiveKit, you can use the following methods: 1. Enable Debug Logging The simplest way is to enable debug logging using the
LK_OPENAI_DEBUG
environment variable:
Copy code
export LK_OPENAI_DEBUG=1
When enabled, this will automatically log all OpenAI API events, including streaming responses. The logs will include outgoing messages (e.g.,
>>> {msg}
) and incoming events (e.g.,
<<< {event}
). 2. Built-in Event Logging The LiveKit OpenAI plugin automatically logs various streaming events, such as: •
response.text.delta
- Text streaming chunks •
response.audio.delta
- Audio streaming chunks •
response.audio_transcript.delta
- Audio transcript streaming •
response.content_part.done
- When content parts complete •
response.done
- When the entire response completes For audio delta events, the actual audio data is replaced with
"..."
in the logs to avoid logging large binary data. 3. Custom Logging You can implement custom logging by accessing the logger directly:
Copy code
from livekit.plugins.openai.log import logger

# Log with additional context
logger.debug("Custom log message", extra={"custom_data": "value"})
4. Event Emission The realtime model emits raw events that you can listen to for custom logging:
Copy code
# The raw JSON event is emitted
self.emit("openai_server_event_received", event)
Using
LK_OPENAI_DEBUG=1
is the most straightforward way to log all OpenAI streaming responses without requiring code changes. Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | plugins/openai/src/realtime/realtime_model.ts
c
hey I only see the DEBUG livekit.plugins.openai - chat.completions.create, do you know how I can see the responses also?
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
c
and what if I put the LK_OPENAI_DEBUG to 2 instead of 1?