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?

Foundry Tools
Foundry Tools

Formerly known as Azure AI Services or Azure Cognitive Services is a unified collection of prebuilt AI capabilities within the Microsoft Foundry platform

0 comments No comments

Answer accepted by question author
Ramr-msft 17,836 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)

Was this answer helpful?

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

    Was this answer helpful?


Your answer

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