Gemini API returned 400 with code safety. Adjust filters or rewrite the input—don’t retry blind
A safety, jailbreak, prohibited_content, or blocklist block returns HTTP 400 and no text. Read the code, ease filters when allowed, then rewrite—don’t retry. Short answer: 5 steps. 1) Read error.code before you change the prompt; 2) Don’t confuse it with 429 RESOURCE_EXHAUSTED or an invalid key; 3) Inspect which category you tightened—and what you can actually change; 4) Rewrite or shrink the input when the code is jailbreak / prohibited_content / blocklist; 5) Handle 400 safety in code as non-retryable until the request changes.
Last updated: · This page is the decision checklist; the tools list for “Fix a Gemini API 400 safety / content block” is a separate URL.
How do I adjust filters or rewrite the input when Gemini returns 400 safety?
Read error.code before you change the prompt
On the Gemini Interactions API, a safety filter that blocks the input or the response fails the call with HTTP 400 and does not return the blocked content. `code: "safety"` means an adjustable safety filter fired; `jailbreak`, `prohibited_content`, or `blocklist` mean the input was blocked for that reason (messages often start with “Input blocked:”). Docs: https://ai.google.dev/gemini-api/docs/safety-settings
Don’t confuse it with 429 RESOURCE_EXHAUSTED or an invalid key
A safety 400 is a content decision, not a quota or auth failure. Pace and quota errors are covered separately (for example RESOURCE_EXHAUSTED). If the key itself is wrong you get a different invalid-key path—fix billing/auth first only when the status and message say so. Quota errors: https://ai.google.dev/gemini-api/docs/quota-error-codes
Inspect which category you tightened—and what you can actually change
Pass `safety_settings` with one threshold per category (`harassment`, `hate_speech`, `sexually_explicit`, `dangerous_content`, `jailbreak`). Categories you omit default to Off on Gemini 2.5 and later. Built-in blocks for core harms (such as child-safety endangerment) cannot be relaxed. Looser settings may be subject to Google’s Terms review.
Rewrite or shrink the input when the code is jailbreak / prohibited_content / blocklist
Those codes point at the prompt, not a tunable threshold you should crank to Off. Remove jailbreak-style instructions, prohibited material, and blocklisted terms; then retry once. Blind retries with the same payload keep returning 400 and burn quota.
Handle 400 safety in code as non-retryable until the request changes
Branch on HTTP 400 + `error.code` in `safety` / `jailbreak` / `prohibited_content` / `blocklist`. Surface the message to the user or logs, adjust `safety_settings` only for legitimate product needs, and only then send a modified request. For background interactions, check `status: failed` and the same codes in `errors`; on streams, watch for an `error` event.
Which tools are best to fix a Gemini API 400 safety / content block?
Gemini safety settings
Categories, thresholds, and how blocked interactions return HTTP 400.
Gemini troubleshooting
General API failure patterns and next steps.
Quota and error codes
Keep RESOURCE_EXHAUSTED and related quota errors separate from safety 400s.
Google AI Studio API keys
Confirm you’re testing with a valid project key after content blocks are fixed.
Open: 1 spot per week
One labeled sponsor for this topic each week; this week's spot is open. See open weeks →
All tools for “Fix a Gemini API 400 safety / content block” →
Related fixes
- Stop a Cursor agent loopHow to fix a Cursor agent loop (same edit, or work after Stop)Fix →
- Claude Code vs Codex vs Cursor ~$20 plansClaude Code vs Codex vs Cursor $20 plan limits: how to pick without burning the weekFix →
- Scan a vibe-coded app for leaked API keysCheck a vibe-coded app for leaked API keys before you share itFix →
- Add an MCP server to Claude Code, Cursor, or CodexHow to add an MCP server to Claude Code, Cursor, or CodexFix →
See also AI tools launched today on the daily board.
NewAIToolsToday Daily
Top 3 AI launches, one model or news item that matters, and one simple fix. A 5-minute read, every weekday.