Skip to content

[Bug] /v1/chat/completions defaults to streaming when stream is omitted #5047

Description

@lipchev

Summary

When calling the OpenAI-compatible /v1/chat/completions endpoint without explicitly specifying the stream parameter, the server appears to default to stream: true.

This behavior is not aligned with the OpenAI API convention, where omitting stream defaults to non-streaming (false).

As a result, OpenAI-compatible clients (e.g. .NET SDKs) that omit the stream field receive SSE (data:) responses instead of JSON, causing deserialization failures.


Steps to reproduce

  1. Load a model via:
POST /api/inference/load
  1. Call:
POST /v1/chat/completions

with body:

{
  "messages": [
    { "role": "user", "content": "Hello" }
  ]
}

(note: no stream field)


Expected behavior

  • Response is standard JSON:
{
  "choices": [...]
}
  • Equivalent to:
"stream": false

Actual behavior

  • Response is streamed using SSE format:
{"id":"chatcmpl-bec20bc3c001","object":"chat.completion.chunk" ...}
{"id":"chatcmpl-bec20bc3c001","object":"chat.completion.chunk" ...}
  • This causes failures in clients expecting JSON (e.g. System.Text.Json errors like):
'd' is an invalid start of a value

Additional context

  • Explicitly setting:
"stream": false

produces correct JSON output.

  • Explicitly setting:
"stream": true

produces expected streaming output.

  • The issue only occurs when the stream field is omitted.

Impact

  • Breaks compatibility with OpenAI SDKs and abstractions (e.g. Microsoft .NET clients), which omit stream when non-streaming is intended.
  • Requires consumers to always explicitly set "stream": false, which is not expected behavior.

Suggested fix

Default stream to false when the field is not provided, to match OpenAI API behavior.


Environment

  • Unsloth Studio (local)
  • Endpoint: http://localhost:8888/v1/chat/completions
  • Tested via Postman and .NET OpenAI client

Thanks for the great work on the OpenAI-compatible API — this small fix would significantly improve interoperability.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions