Issue with Vision Chat when inputting image URL

AdityaSa 801 Reputation points
2023-12-14T07:16:15.2566667+00:00

I am following the "Chat with Vision" example but encountering an error when inputting an image URL. The error message I receive is:

{"error":{"code":"BadRequest","message":"Invalid image (base64) data.","param":null,"type":null}}

Inputting a base64 image string instead of a URL works properly. How can I troubleshoot and fix this issue?

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,564 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ramr-msft 17,826 Reputation points
    2023-12-14T09:01:49.6066667+00:00

    Thanks for the question, please follow the below quickstart sample for image url.

    Here is the document for the Use images in your AI chats.

    # Packages required:
    import requests 
    import json 
    
    api_base = '<your_azure_openai_endpoint>' 
    deployment_name = '<your_deployment_name>'
    API_KEY = '<your_azure_openai_key>'
    
    base_url = f"{api_base}openai/deployments/{deployment_name}" 
    headers = {   
        "Content-Type": "application/json",   
        "api-key": API_KEY 
    } 
    
    # Prepare endpoint, headers, and request body 
    endpoint = f"{base_url}/chat/completions?api-version=2023-12-01-preview" 
    data = { 
        "messages": [ 
            { "role": "system", "content": "You are a helpful assistant." }, 
            { "role": "user", "content": [ 
               { "type": "text", "text": "Describe this picture:" }, 
               { "type": "image_url", "url": "<URL or base-64-encoded image>" } 
           ] } 
        ], 
        "max_tokens": 100 
    }   
    
    # Make the API call   
    response = requests.post(endpoint, headers=headers, data=json.dumps(data))   
    
    print(f"Status Code: {response.status_code}")   
    print(response.text)
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Jhuze 0 Reputation points
    2023-12-21T01:53:00.1166667+00:00

    It works to me with the answer provided by Ramr-msft


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.