Api connection -ConnectionError

have a problem with Api connection to my app, in py. turned off firewall, testet and nothing no respose, Someone know whats going on ?

import requests
import os

# my API
api_key = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxx”

# example “prompt” (zastąp swoim tekstem)
prompt = “Napisz krótki wiersz o wiośnie.”

url = “https://api.gemini.google.com/v1/generateText
headers = {
** “Authorization”: f"Bearer {api_key}"**
}
data = {
** “prompt”: prompt,**
** # Dodaj inne parametry żądania, jeśli są wymagane (sprawdź dokumentację)**
}

response = requests.post(url, headers=headers, json=data)

if response.status_code == 200:
** print(“Sukces! Odpowiedź od API Gemini:”)**
** print(response.json()[‘generated_text’])**
else:
** print(f"Błąd: {response.status_code}")**
** print(response.text)**

Terminal:

File “C:\Users\User\anaconda3\Lib\site-packages\requests\adapters.py”, line 519, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘api.gemini.google.com’, port=443): Max retries exceeded with url: /v1/generateText (Caused by NewConnectionError(‘<urllib3.connection.HTTPSConnection object at 0x000001A0E87930D0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed’))
PS C:\Users\User\Desktop\Projekt-ARC>

For starters api key is not a bearer token.

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY" \ -H 'Content-Type: application/json' \ -X POST \ -d '{ "contents": [{ "parts":[{"text": "Write a story about a magic backpack."}] }] }' 2> /dev/null

Second why not use the python client libary.

that is true [LindaLawton], thank You for advice, I think also the problem is that: Gemini API free tier is not currently available in your country. Please enable billing via Settings once your API key has been created. Read more here. :slight_smile: latter I’LL check that,

As an aside, if you did want the API Key in the header for whatever reason, you should use the header

   X-Goog-Api-Key

with the API key as the value.