Error: Expected delta with content

Has anyone encountered this error before?
I have my agent working with open ai’s api but when I try to use a model from open router I run into this error

 assert choice.delta.content is not None, f'Expected delta with content, invalid chunk: {chunk!r}'
streamlit-1  | AssertionError: Expected delta with content, invalid chunk:
1 Like

I have had this happen before! It seems that streaming doesn’t work with OpenRouter for some reason. So if you change your agent to use the “run” function instead of “run_stream” and make the whole process synchronous instead of async, it will work.

Pretty unfortunate since it’s nice to have the output in realtime from the model, but yeah something is wrong with OpenRouter specifically for streaming.

1 Like

Dang that’s unfortunate. Ok thanks Cole

1 Like

Yeah sorry it really is. You’re welcome! Sorry I don’t have a better answer!