@@ -384,6 +384,90 @@ def __init__(self, completions: DummyCompletions) -> None:
384384 assert kwargs ["stream_options" ] is omit
385385
386386
387+ @pytest .mark .allow_call_model_methods
388+ @pytest .mark .asyncio
389+ async def test_get_response_accepts_raw_chat_completions_image_content () -> None :
390+ """
391+ Raw Chat Completions content parts should be accepted on the SDK input path
392+ when using the Chat Completions backend.
393+ """
394+
395+ class DummyCompletions :
396+ def __init__ (self ) -> None :
397+ self .kwargs : dict [str , Any ] = {}
398+
399+ async def create (self , ** kwargs : Any ) -> Any :
400+ self .kwargs = kwargs
401+ return chat
402+
403+ class DummyClient :
404+ def __init__ (self , completions : DummyCompletions ) -> None :
405+ self .chat = type ("_Chat" , (), {"completions" : completions })()
406+ self .base_url = httpx .URL ("https://api.openai.com/v1/" )
407+
408+ msg = ChatCompletionMessage (role = "assistant" , content = "ok" )
409+ choice = Choice (index = 0 , finish_reason = "stop" , message = msg )
410+ chat = ChatCompletion (
411+ id = "resp-id" ,
412+ created = 0 ,
413+ model = "fake" ,
414+ object = "chat.completion" ,
415+ choices = [choice ],
416+ usage = None ,
417+ )
418+ completions = DummyCompletions ()
419+ dummy_client = DummyClient (completions )
420+ model = OpenAIChatCompletionsModel (model = "gpt-4" , openai_client = dummy_client ) # type: ignore[arg-type]
421+
422+ await model .get_response (
423+ system_instructions = None ,
424+ input = [
425+ # Cast the fixture because the raw chat-style alias is intentionally outside the
426+ # canonical TypedDict shape that mypy expects for ordinary SDK inputs.
427+ cast (
428+ Any ,
429+ {
430+ "role" : "user" ,
431+ "content" : [
432+ {"type" : "text" , "text" : "What is in this image?" },
433+ {
434+ "type" : "image_url" ,
435+ "image_url" : {
436+ "url" : "data:image/png;base64,AAAA" ,
437+ "detail" : "high" ,
438+ },
439+ },
440+ ],
441+ },
442+ )
443+ ],
444+ model_settings = ModelSettings (),
445+ tools = [],
446+ output_schema = None ,
447+ handoffs = [],
448+ tracing = ModelTracing .DISABLED ,
449+ previous_response_id = None ,
450+ conversation_id = None ,
451+ prompt = None ,
452+ )
453+
454+ assert completions .kwargs ["messages" ] == [
455+ {
456+ "role" : "user" ,
457+ "content" : [
458+ {"type" : "text" , "text" : "What is in this image?" },
459+ {
460+ "type" : "image_url" ,
461+ "image_url" : {
462+ "url" : "data:image/png;base64,AAAA" ,
463+ "detail" : "high" ,
464+ },
465+ },
466+ ],
467+ }
468+ ]
469+
470+
387471@pytest .mark .asyncio
388472async def test_fetch_response_stream (monkeypatch ) -> None :
389473 """
0 commit comments