Skip to content

stream=true requests cause "Object of type Stream is not JSON serializable" error #117

@doublefx

Description

@doublefx

When sending a stream=true request to optiLLM, the service encounters the following error:

{"error":"Object of type Stream is not JSON serializable"}

This error suggests that optiLLM is not properly handling streamed responses from liteLLM or OpenAI GPT-4o. Instead of processing the stream incrementally, it attempts to serialize the raw stream object directly into JSON, which causes the serialization failure.

Steps to Reproduce:
Send a POST request to optiLLM with the following payload:

{
    "model": "gpt-4o",
    "messages": [
        { "role": "system", "content": "You are a helpful assistant." },
        { "role": "user", "content": "Write a Python program to build an RL model using only numpy." }
    ],
    "max_tokens": 1000,
    "stream": true
}

Observe the error response:
{"error":"Object of type Stream is not JSON serializable"}

Expected Behavior:
The optiLLM service should handle streamed responses by:

  • Iterating through the stream of chunks from liteLLM or OpenAI.
  • Processing each chunk incrementally and forwarding it to the next layer (e.g., AnythingLLM).

Additional Context:

  • The following pipeline works properly: User -> AnythingLLM -> liteLLM -> openai/gpt-4o
  • The problem seems specific to how optiLLM handles the streamed response from liteLLM.

Severity:
High - This issue blocks the usage of stream=true functionality, which is critical for incremental responses in real-time applications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions