API and SDK Access for Safety Configuration
Safety settings can be configured through the Gemini API using REST calls or through Google's official SDKs for Python, Node.js, Java, Go, and C#. Each SDK provides methods to set harm category thresholds programmatically. For example, in Python, developers use the SafetySetting class with HarmCategory and HarmBlockThreshold enumerations. The API supports both the SEVERITY and PROBABILITY blocking methods, with SEVERITY being the default. When a response is blocked due to safety filters, the finishReason field returns SAFETY, and the candidate's content field is cleared. The API also provides detailed safety ratings in the response, including category, probability level, probability score, severity level, and severity score for each harm category. This granular feedback allows developers to understand exactly why content was blocked and adjust their settings accordingly. The REST API endpoint supports streaming generate content calls with safety settings included in the request body.
Google Cloud Console Configuration
For developers who prefer a graphical interface, the Google Cloud Console provides a point-and-click method for configuring content filters. Within the Agent Platform section, developers can access Agent Studio and open the safety settings dialog from the prompt design page. The Cloud Console uses only probability scores for filtering, not severity scores. Available threshold values include: Off (default, no automatic blocking), Block a few (blocks HIGH probability content), Block some (blocks MEDIUM or HIGH probability), and Block most (blocks LOW, MEDIUM, or HIGH probability). Each harm category can be configured independently, allowing fine-grained control over different types of potentially harmful content. This console-based approach is particularly useful for non-developer stakeholders who need to review or adjust safety settings without writing code. The settings are applied to the specific prompt configuration being edited and can be saved for repeated use.