How to avoid refusals in Gemini API requests?

How to avoid refusals in Gemini API requests?

My API was obtained via https://aistudio.google.com/app/apikey

{
  "error": {
    "code": 400,
    "message": "* GenerateContentRequest.safety_settings[4]: element predicate failed: $.category in (HarmCategory.HARM_CATEGORY_HATE_SPEECH, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, HarmCategory.HARM_CATEGORY_HARASSMENT, HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY)\n",
    "status": "INVALID_ARGUMENT"
  }
}

This is a false positive because my code shouldn’t trigger any of these filters.

8 Likes

Did you find a solution?
I started getting this and it’s all i’m getting from google today.

I got exactly the same issue hours ago… Then I tried to use the same key(and the same project /files) in VS Code instead (ClaudeDev), and it works. So far…

I also generate a new key and it didn’t work in Cursor as well(maybe I need to delete any cache?!). Anyway, I didn’t find a straightforward solution. :frowning:

1 Like

Are we the only 2 people in the world having this issue :smiley:

anybody from cursor want to chip in? :smiley:

Same issue here with my own API key on Cursor. No luck so far. Anyone figured out a fix? :confused:

Update (from my perspective): the refusals stopped about 12-15 hours ago.