400 User location is not supported for the API use without a billing account linked, error

,
import google.generativeai as genai

genai.configure(api_key="AIzaSyCLk1qA0XMhNuiTiK2cBf3MpkLPzKo9l9g")

# Create the model
# See https://ai.google.dev/api/python/google/generativeai/GenerativeModel
generation_config = {
  "temperature": 1,
  "top_p": 0.95,
  "top_k": 64,
  "max_output_tokens": 8192,
  "response_mime_type": "text/plain",
}

model = genai.GenerativeModel(
  model_name="gemini-1.5-flash",
  generation_config=generation_config,
  # safety_settings = Adjust safety settings
  # See https://ai.google.dev/gemini-api/docs/safety-settings
)

chat_session = model.start_chat(
  history=[
  ]
)

response = chat_session.send_message("Hello")

print(response.text)

I’ve used this simple code, but every time I run it, I get an error.

PS D:\Projets spéciaux\Lumia (AI)> python chat.py
Traceback (most recent call last):
  File "D:\Projets spéciaux\Lumia (AI)\chat.py", line 27, in <module>
    response = chat_session.send_message("Salut")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\fab\AppData\Roaming\Python\Python312\site-packages\google\generativeai\generative_models.py", line 504, in send_message
    response = self.model.generate_content(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\fab\AppData\Roaming\Python\Python312\site-packages\google\generativeai\generative_models.py", line 258, in generate_content
    response = self._client.generate_content(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\fab\AppData\Roaming\Python\Python312\site-packages\google\ai\generativelanguage_v1beta\services\generative_service\client.py", line 812, in generate_content
    response = rpc(
               ^^^^
  File "C:\Users\fab\AppData\Roaming\Python\Python312\site-packages\google\api_core\gapic_v1\method.py", line 131, in __call__
    return wrapped_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\fab\AppData\Roaming\Python\Python312\site-packages\google\api_core\retry\retry_unary.py", line 293, in retry_wrapped_func
    return retry_target(
           ^^^^^^^^^^^^^
  File "C:\Users\fab\AppData\Roaming\Python\Python312\site-packages\google\api_core\retry\retry_unary.py", line 153, in retry_target
    _retry_error_helper(
  File "C:\Users\fab\AppData\Roaming\Python\Python312\site-packages\google\api_core\retry\retry_base.py", line 212, in _retry_error_helper
    raise final_exc from source_exc
  File "C:\Users\fab\AppData\Roaming\Python\Python312\site-packages\google\api_core\retry\retry_unary.py", line 144, in retry_target
    result = target()
             ^^^^^^^^
  File "C:\Users\fab\AppData\Roaming\Python\Python312\site-packages\google\api_core\timeout.py", line 120, in func_with_timeout
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\fab\AppData\Roaming\Python\Python312\site-packages\google\api_core\grpc_helpers.py", line 78, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.FailedPrecondition: 400 User location is not supported for the API use without a billing account linked.

PS: The API key is invalid in this message, but I put a real one in my code.

Welcome to the forum.

Access through the API key from the EU, UK and Switzerland requires a billing account as the message states. This question was previously answered here: 400 Bad Request] User location is not supported for the API use without a billing account linked