For safeguards applied by OpenAI, see Safety classifiers, cybersecurity checks, and misalignment monitoring. If your application serves minors, also follow the Under-18 guidance.
Use our free Moderation API
OpenAIâs Moderation API is free-to-use and can help reduce the frequency of unsafe content in your completions. Alternatively, you may wish to develop your own content filtration system tailored to your use case.
If your application generates text with the Responses API or Chat Completions, you can also request moderation scores in the generation request.
Adversarial testing
We recommend âred-teamingâ your application to ensure itâs robust to adversarial input. Test your product over a wide range of inputs and user behaviors, both a representative set and those reflective of someone trying to break your application. Does it wander off topic? Can someone redirect the feature with a prompt injection such as âignore the previous instructions and do this insteadâ?
Human in the loop (HITL)
Wherever possible, we recommend having a human review outputs before they are used in practice. This is especially critical in high-stakes domains, and for code generation. Reviewers should know the systemâs limitations and have the information they need to verify the output. For example, if your application summarizes notes, let reviewers compare the summary with the original notes.
Prompt engineering
âPrompt engineeringâ can help constrain the topic and tone of output text. This reduces the chance of producing undesired content, even if a user tries to produce it. Providing additional context to the model (such as by giving a few high-quality examples of desired behavior prior to the new input) can make it easier to steer model outputs in desired directions.
âKnow your customerâ (KYC)
Users should generally need to register and log-in to access your service. Linking this service to an existing account, such as a Gmail, LinkedIn, or Facebook log-in, may help, though may not be appropriate for all use-cases. Requiring a credit card or ID card reduces risk further.
Constrain user input and limit output tokens
Limiting the amount of text a user can input into the prompt helps avoid prompt injection. Limiting the number of output tokens helps reduce the chance of misuse.
Narrowing the ranges of inputs or outputs, especially drawn from trusted sources, reduces the extent of misuse possible within an application.
Allowing user inputs through validated dropdown fields (for example, a list of movies on Wikipedia) can be more secure than allowing open-ended text inputs.
Returning outputs from a validated set of materials on the backend, where possible, can be safer than returning novel generated content (for instance, routing a customer query to the best-matching existing customer support article, rather than attempting to answer the query from-scratch).
Allow users to report issues
Tell users how to report problems with your application. For example, list a support email address or link to a form. Assign someone to review reports and respond as appropriate.
Understand and communicate limitations
From hallucinating inaccurate information, to offensive outputs, to bias, and much more, language models may not be suitable for every use case without significant modifications. Consider whether the model is fit for your purpose, and evaluate the performance of the API on a wide range of potential inputs to identify cases where performance might drop. Consider your customer base and the range of inputs that they will be using, and ensure their expectations are calibrated appropriately.
Safety and security are very important to us at OpenAI.
If you notice any safety or security issues while developing with the API or anything else related to OpenAI, please submit it through our Coordinated Vulnerability Disclosure Program.
Implement safety identifiers
Safety identifiers are optional, but OpenAI recommends them for products where individual users interact with a model. A stable identifier helps OpenAI detect misuse and give your team specific feedback about policy violations.
If OpenAI flags a request, the identifier helps your team trace it to the user who sent it. Without an identifier, OpenAI may not be able to limit enforcement to that user. Repeated policy violations can lead to restrictions on model access for your entire organization.
Use a unique string for each user. Hash the username or email address to avoid sending personal information. If you offer a preview to users who arenât signed in, you can use a session ID instead.
Include the identifier in your API requests with the safety_identifier parameter:
import OpenAI from "openai";
const client = new OpenAI();
const response = await client.chat.completions.create({
model: "gpt-6.2-astra",
messages: [{ role: "user", content: "This is a test" }],
max_completion_tokens: 5,
safety_identifier: "user_123456",
});
console.log(response.choices[0].message.content);For the Images API, include safety_identifier on each image
generation
(POST /v1/images/generations) and image
edit (POST /v1/images/edits)
request. Send it as a JSON property for JSON requests or a form field for
multipart image edits. Use the same stable identifier for an end user across
requests within your organization, and keep it to 128 characters or fewer.
The user parameter in the Images API is deprecated. To migrate, send the identifier
you previously supplied as user in safety_identifier instead. Existing
requests using user remain supported. If you provide both fields, a nonempty
safety_identifier takes precedence. If safety_identifier is omitted, null, or an empty
string, the API uses user when available.
For Realtime API requests, provide the same stable, privacy-preserving identifier
with the OpenAI-Safety-Identifier header. When you create an ephemeral Realtime
client secret, include the header on the server-side request that creates the
secret so the identifier is bound to that session. For direct WebSocket or WebRTC
connection requests made from a trusted backend, include the header on the
connection request.
Safety identifiers do not carry over between APIs or sessions. If your
application already sends safety_identifier with Responses API requests, pass
the same stable value separately in each Images API request and when you create
or connect each Realtime session.
Revoke compromised API keys
If you believe an API key has been exposed, misused, or otherwise compromised, revoke it promptly and replace it with a new key. Go to your Security settings to view all API keys and revoke any compromised keys.
CSAM guidance
OpenAI has worked with child safety experts, including NCMEC and Thorn, to offer developers practical guidance for protecting children. Read the CSAM guidance.