Getting "Unauthorized User API key" with Custom Gemini Key - Must I be a Pro User?

I tested my Gemini API key and the model using the following code:

import google.generativeai as genai
import os
from google.api_core import exceptions

API_KEY = "MY_API_KEY"
genai.configure(api_key=API_KEY)

model_name = "gemini-2.5-flash-preview-04-17"

try:
    # Check if the model exists and is accessible
    model = genai.get_model(model_name)
    print(f"Successfully accessed model info for: {model.name}")

    # Try generating content
    print(f"Attempting to generate content using {model_name}...")
    model = genai.GenerativeModel(model_name)
    response = model.generate_content("Tell me a short story.")

    # Print the response if successful
    print("\n--- API Response ---")
    print(response.text)
    print("--------------------")

except exceptions.PermissionDenied as e:
    print(f"\n--- Error: Permission Denied ---")
    print(f"Your API key is not authorized for model '{model_name}'.")
    print(f"Details: {e}")
    print("This indicates an issue with your API key's access on Google's side.")

except exceptions.ResourceExhausted as e:
     print(f"\n--- Error: Resource Exhausted ---")
     print(f"You have exceeded your quota or rate limits for model '{model_name}'.")
     print(f"Details: {e}")
     print("This indicates a quota/limit issue on Google's side.")

except exceptions.NotFound as e:
    print(f"\n--- Error: Model Not Found ---")
    print(f"The model '{model_name}' was not found or is not available to your key.")
    print(f"Details: {e}")
    print("This indicates the model name is wrong or it's not available to your key.")

except Exception as e:
    print(f"\n--- An unexpected error occurred ---")
    print(f"Error type: {type(e).__name__}")
    print(f"Details: {e}")
    print("This might be an API issue or another problem.")

The response came back without error.

I can confirm also that other Gemini models, such as “gemini-2.5-pro-exp” works fine with Cursor under my API.