Using AgentSession with gpt-4o, my logs show Image...
# ask-ai
g
Using AgentSession with gpt-4o, my logs show ImageContent being attached to messages, but OpenAI debug logs show only text in the API request (no image_url). Using livekit-plugins-openai v1.2.6. Is there a known issue or configuration we’re missing? I have found the details about OpenAI Realtime API not yet supporting vision via the LiveKit abstraction of
ImageContent
, but does that issue prevent vision from working across all OpenAI’s endpoints and models as well?
t
Thanks for reaching out, Dan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! Just a quick heads-up: the limitation with the OpenAI Realtime API in LiveKit is only about that specific endpoint and doesn’t impact vision capabilities across all OpenAI models and endpoints. The Realtime API doesn’t support image input through the
ImageContent
class because image content gets filtered out during processing. So, this restriction is just for the Realtime API. But don’t worry! Other OpenAI model integrations in LiveKit, like the standard LLM integration, fully support vision features. For example, models like
gpt-4o
can handle image uploads and external URLs when you use them outside the Realtime API. If you’re looking to use vision functionality, I’d recommend trying out the standard OpenAI LLM integration instead of the Realtime API. Hope this helps! Sources: livekit-agents/livekit/agents/llm/_provider_format/openai.py | agents/src/llm/provider_format/openai.test.ts | Large language model (LLM) integrations | LiveKit Docs | OpenAI and LiveKit | LiveKit Docs | Vision | LiveKit Docs
g
# Follow-up Questions for LiveKit Slack ## Primary Question Thanks for the response! To clarify - I’m using the standard LLM integration (not Realtime) with
gpt-4o
via
AgentSession
, but images still aren’t reaching OpenAI. Here’s my setup:
Copy code
python
# Using AgentSession with standard LLM (not Realtime)
session = AgentSession(
    stt=deepgram.STT(),
    llm=openai.LLM(model="gpt-4o"),  # Standard LLM, not Realtime
    tts=openai.TTS()
)

# In on_user_turn_completed:
async def on_user_turn_completed(self, ctx: ChatContext, msg: ChatMessage):
    # msg contains ImageContent items
    logger.info(f"Message has {len([c for c in msg.content if isinstance(c, ImageContent)])} images")
    # Logs show: "Message has 1 images"
    
    # But OpenAI debug logs show no image_url in the actual API request
With
LK_OPENAI_DEBUG=1
, I can see the chat context being sent, but it only contains text content - no
image_url
fields. Is there a specific configuration or method I need to use to ensure ImageContent is preserved when using AgentSession? ## Additional Context Questions 1. Is there a difference between using
VoicePipelineAgent
vs
AgentSession
for vision?
The docs show vision examples with VoicePipelineAgent but not AgentSession. 2. Does the plugin version matter? Using livekit-plugins-openai v1.2.6. Should I try a different version? 3. Is there a working example of AgentSession + gpt-4o + vision that I could reference? ## Debug Info - livekit-agents==0.12.6 - livekit-plugins-openai==1.2.6 - OpenAI API logs confirm no images in request - Same code pattern works with Gemini (images are sent successfully)
t
Hey there! Just wanted to share some info about how LiveKit AgentSession supports
ImageContent
with OpenAI LLMs like
gpt-4o
. The framework actually takes care of formatting image data perfectly for OpenAI's API. Here are some helpful points and methods to make sure your images come through just right: • Image Sources: You’ve got options! You can use external URLs, base64-encoded data URLs, or even
VideoFrame
objects. The framework will convert these into formats that OpenAI expects. • Implementation Examples: Images can be added in different ways—through the initial chat context, uploaded from the frontend, or grabbed from live video tracks. For example, you might append an image to a message inside
on_user_turn_completed
like this:
Copy code
async def on_user_turn_completed(self, turn_ctx, new_message):
    if self._latest_frame:
        new_message.content.append(ImageContent(image=self._latest_frame))
        self._latest_frame = None
• Configuration: Just make sure your
ImageContent
object is set up properly. The framework handles all the serialization and formatting behind the scenes, so you don’t have to worry. • Validation: Supported image types include JPEG, PNG, WebP, and GIF. If you use something else, you’ll get an error—so keep an eye on that. Now, about the extra questions you had: 1. AgentSession vs. VoicePipelineAgent: Both support vision features! VoicePipelineAgent is often shown in examples because it covers more use cases, but your setup with AgentSession works great for vision too. 2. Plugin Version: Version 1.2.6 already supports vision, so no need to upgrade unless you run into a specific bug. 3. Working Example: The code snippets above follow the documented patterns for using AgentSession with vision, so you’re on the right track. If you’re still not seeing images reach OpenAI, double-check that your
ImageContent
objects are filled correctly and peek at the debug logs for any errors. I’m here if you want to troubleshoot more! Sources: Vision | LiveKit Docs | agents/src/llm/provider_format/google.test.ts | livekit-agents/livekit/agents/llm/utils.py
g
I’m suspecting I may have a race condition with
preemptive_generation
turned on, where my sampled frame is encoded and attached at turn end but the request to OpenAI has already been sent at that point. Is this plausible? And should it be possible to get vision working with
preemptive_generation
enabled for the agent?
t
Thank you for your question! I want to reassure you that the
preemptive_generation
parameter in
AgentSession
doesn’t interfere with including
ImageContent
in your OpenAI API requests, nor does it impact vision support. These features actually work independently, so you can feel confident using them together. Just to give you a bit more context,
preemptive_generation
helps reduce response latency by starting LLM and TTS inference as soon as a user transcript is available, even before the user’s turn finishes. Meanwhile, the inclusion of
ImageContent
is handled separately by the
ChatContext
, which makes sure your images are correctly formatted and included in the request payload. Vision support, which depends on the LLM provider and model (like
gpt-4o
), continues to work smoothly no matter if
preemptive_generation
is turned on or off. If you think there might be a race condition, a helpful step is to check the timing of when
ImageContent
is added to your message compared to when the request is sent. Making sure the image is appended before the request is finalized usually clears up the issue. Sources: Agent speech and audio | LiveKit Docs | agents/src/llm/provider_format/openai.test.ts | Vision | LiveKit Docs
g
Thanks! A few follow-ups: 1. With AgentSession(preemptive_generation=True), is the preemptive request guaranteed to be canceled and replaced with the updated ChatContext after on_user_turn_completed mutates new_message? Any known gaps in v1.2.6 where the replacement request can miss ImageContent? 2. Is there any difference in image handling between mutating new_message.content vs calling update_chat_ctx() from inside on_user_turn_completed? 3. Confirm provider-format expectations for OpenAI LLM: in v1.2.6, should ImageContent(image=rtc.VideoFrame) always serialize into an image_url or base64 image part for openai.LLM(model=“gpt-4o”)?
@alert-easter-19258