Return HTTP 400 for streaming validation errors (#21900)

This commit is contained in:
Liangsheng Yin
2026-04-01 21:58:12 -07:00
committed by GitHub
parent 153359b4dd
commit 269589ad71
3 changed files with 59 additions and 4 deletions
@@ -67,6 +67,23 @@ class TestRequestLengthValidation(CustomTestCase):
self.assertIn("is longer than the model's context length", str(cm.exception))
def test_input_length_longer_than_context_length_streaming(self):
client = openai.Client(api_key=self.api_key, base_url=f"{self.base_url}/v1")
long_text = "hello " * 1200
with self.assertRaises(openai.BadRequestError) as cm:
client.chat.completions.create(
model=DEFAULT_SMALL_MODEL_NAME_FOR_TEST,
messages=[
{"role": "user", "content": long_text},
],
temperature=0,
stream=True,
)
self.assertIn("is longer than the model's context length", str(cm.exception))
def test_max_tokens_validation(self):
client = openai.Client(api_key=self.api_key, base_url=f"{self.base_url}/v1")