Enviar prompt a AI Gemini desde Power Query

Buenas tardes, estoy intentando leer imagenes desde power query y llamar a la api de gemini para que me lea la imagen y me extraiga datos en json, pero aunque he revisado el codigo, siempre me dice que " no hemos podido autenticarle con las credenciales proporcionadas. Vuelva a intentarlo. En el código tengo :
// Definir la URL de la API de Gemini
apiUrl = “https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=apiKey”,
y
// Llamar a la API con el cuerpo de la solicitud y el encabezado de autorización
response = Web.Contents(apiUrl, [
Headers = [
#“Content-Type”=“application/json”,
#“Authorization” = "Bearer " & apiKey // Usamos apiKey (que contiene el valor de la consulta)
],
Content = jsonPayload
]),
Si alguien pudiera ayudarme, estoy muy estancada

1 Like

Hi @To_Pigra
Welcome to the community!
Please check if you are passing right API key.
I was unable to run the code snippet as it has many errors. However, below is the python code snippet to make a request:

import requests
import json

# Define the API URL and API Key
apiUrl = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key={gemini_api_key}"

# Define the request headers
headers = {
    "Content-Type": "application/json"
}

# Define the JSON payload
jsonPayload = payload = {
    "contents": [
        {
            "parts": [
                {
                    "text": "How does AI work?"
                }
            ]
        }
    ]
}

# Make the API request
response = requests.post(apiUrl, headers=headers, json=jsonPayload)

# Check the response status and print it
if response.status_code == 200:
    print("Response:", response.json())
else:
    print(f"Error {response.status_code}: {response.text}")

Please let us know if you need any help.
Thank you