豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Error when sending base64 image with type: image_url to Chat Completions API #2797

@YemaoLuo

Description

@YemaoLuo

Please read this first

  • Have you read the docs?Agents SDK docs
  • Have you searched for related issues? Others may have faced similar issues.

Describe the bug

Although I set to use completion api instead of response api. SDK still reject "type": "image_url". Only accept "input_image".
But for completion API, it should allow us to use image_url as type.

Debug information

  • Agents SDK version:
    openai 2.29.0
    openai-agents 0.13.0
  • Python version 3.11

Repro steps

Here are my code:

  async def run_agent():
            import base64
            import os
            # get test.png abs path
            abs_path = os.path.dirname(os.path.abspath(__file__)) + '/test.png'
            with open(abs_path, "rb") as img_file:
                encoded_string = base64.b64encode(img_file.read()).decode('utf-8')
                img_url = f"data:image/png;base64,{encoded_string}"
            messages = [
                {
                    "role": "user",
                    "content": [
                        {
                            "type": "image_url",
                            "image_url": {
                                "url": img_url
                            }
                        }
                    ]
                },
            ]
            result = await Runner.run(agent, input=messages)
            self.assertIsNotNone(result)

        import asyncio
        asyncio.run(run_agent())

And I use Azure OpenAI(completion api) with below settings:


 set_tracing_disabled(disabled=True)
 set_default_openai_api('chat_completions')

The request never goes to my Azure OpenAI. But if i change message to:

 messages = [
                {
                    "role": "user",
                    "content": [
                        {
                            "type": "input_image",
                            "image_url": {
                                "url": img_url
                            }
                        }
                    ]
                },
            ]

The request will go to my Azure OpenAI. But looks like completion API does not support this kind of input.

Ideally provide a minimal python script that can be run to reproduce the bug.

Expected behavior

A clear and concise description of what you expected to happen.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions