diff --git a/.castiron.stats.yml b/.castiron.stats.yml index de3f450dca..39b4f0ac4e 100644 --- a/.castiron.stats.yml +++ b/.castiron.stats.yml @@ -1,8 +1,8 @@ schema_version: 1 -generation_id: 87b7588c-bf2a-41c6-9369-25b7fac9406c -openapi_spec_hash: 5dc81283fba93dcfeaeca3da5226d157 -openapi_transformed_spec_hash: 42319a087893dfea0fdd818494eb2a8d +generation_id: 45bb4cff-9dc4-4216-966d-b79c11bebfda +openapi_spec_hash: 635c031247109fd4cd1b4b3015290a04 +openapi_transformed_spec_hash: e37900bf3b6f760c1ac154667fb4a5d3 config_hash: c1867d38e1fb20037598907749312f81 -codegen_sha: 0312112d44322208df3d1587c5b6eac1867be196 -codegen_hash: c6efe506a6d3c692825695e888a088db61e9f7c1115801a7138ba4b3ec8b1d00 -public_codegen_sha: 54359420e01e63cc0b61838459b07fcf8cc3a7bd +codegen_sha: d4d98934542b730bc6d1cbd3a2b059402846d750 +codegen_hash: 5a2c6ec20bd11650a52f85637e5c6687a634a4b6139160b98e9c33af31f449bb +public_codegen_sha: 3bd55cae20dba1704ed6d324c2dbc53cbd0090c7 diff --git a/api_reference/openapi.transformed.yml b/api_reference/openapi.transformed.yml index bb4e956d40..a0d3b8bbc0 100644 --- a/api_reference/openapi.transformed.yml +++ b/api_reference/openapi.transformed.yml @@ -43282,8 +43282,8 @@ components: user: type: string example: user-1234 - description: | - A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + description: 'Deprecated: use `safety_identifier` instead. This parameter remains accepted for backward compatibility and is used when `safety_identifier` is omitted, null, or empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers).' + deprecated: true input_fidelity: anyOf: - $ref: '#/components/schemas/InputFidelity' @@ -43318,6 +43318,13 @@ components: example: high description: | The quality of the image that will be generated for GPT image models. The GPT image models support `low`, `medium`, and `high`. `gpt-image-2.5-sunburst` and `gpt-image-2.5-flare`, including their `2026-09-08` snapshots, also support `xhigh` and `max`. Defaults to `auto`. + safety_identifier: + type: + - string + - 'null' + maxLength: 128 + example: user-1234 + description: A stable identifier for an end user in your organization, used for safety monitoring and abuse detection. Hash a username or email address to avoid sending identifying information. A non-empty value takes precedence over the deprecated `user` parameter. If omitted, null, or empty, the API uses `user` when available. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). required: - prompt - image @@ -43502,8 +43509,15 @@ components: user: type: string example: user-1234 - description: | - A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + description: 'Deprecated: use `safety_identifier` instead. This parameter remains accepted for backward compatibility and is used when `safety_identifier` is omitted, null, or empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers).' + deprecated: true + safety_identifier: + type: + - string + - 'null' + maxLength: 128 + example: user-1234 + description: A stable identifier for an end user in your organization, used for safety monitoring and abuse detection. Hash a username or email address to avoid sending identifying information. A non-empty value takes precedence over the deprecated `user` parameter. If omitted, null, or empty, the API uses `user` when available. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). required: - prompt CreateImageVariationRequest: @@ -45727,9 +45741,8 @@ components: user: type: string example: user-1234 - description: | - A unique identifier representing your end-user, which can help OpenAI - monitor and detect abuse. + description: 'Deprecated: use `safety_identifier` instead. This parameter remains accepted for backward compatibility and is used when `safety_identifier` is omitted, null, or empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers).' + deprecated: true output_format: anyOf: - type: string @@ -45779,6 +45792,13 @@ components: description: Stream partial image results as events. partial_images: $ref: '#/components/schemas/PartialImages' + safety_identifier: + type: + - string + - 'null' + maxLength: 128 + example: user-1234 + description: A stable identifier for an end user in your organization, used for safety monitoring and abuse detection. Hash a username or email address to avoid sending identifying information. A non-empty value takes precedence over the deprecated `user` parameter. If omitted, null, or empty, the API uses `user` when available. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). required: - images - prompt @@ -49074,6 +49094,11 @@ components: - jpeg usage: $ref: '#/components/schemas/ImagesUsage' + safety_identifier: + type: + - string + - 'null' + description: The effective safety identifier used for safety monitoring and abuse detection. This is the non-empty `safety_identifier` from the request, or the deprecated `user` value when `safety_identifier` is omitted, null, or empty. required: - type - b64_json @@ -49258,6 +49283,11 @@ components: - jpeg usage: $ref: '#/components/schemas/ImagesUsage' + safety_identifier: + type: + - string + - 'null' + description: The effective safety identifier used for safety monitoring and abuse detection. This is the non-empty `safety_identifier` from the request, or the deprecated `user` value when `safety_identifier` is omitted, null, or empty. required: - type - b64_json @@ -49593,6 +49623,11 @@ components: - max usage: $ref: '#/components/schemas/ImageGenUsage' + safety_identifier: + type: + - string + - 'null' + description: The effective safety identifier used for safety monitoring and abuse detection. This is the non-empty `safety_identifier` from the request, or the deprecated `user` value when `safety_identifier` is omitted, null, or empty. required: - created x-oaiMeta: diff --git a/scripts/castiron/generated-files.json b/scripts/castiron/generated-files.json index 61062e1ff7..9b816537ec 100644 --- a/scripts/castiron/generated-files.json +++ b/scripts/castiron/generated-files.json @@ -579,7 +579,7 @@ }, "src/openai/resources/images.py": { "mode": "100644", - "sha256": "f487a91fa0a826fb25249ae85d9357350253ee79c40e09ea7c6820be8e23d171" + "sha256": "dfbe5ceeda53fd272b99583eaa1f684adf46183b71529c78324e3f2c926fb971" }, "src/openai/resources/live/__init__.py": { "mode": "100644", @@ -4459,11 +4459,11 @@ }, "src/openai/types/image_edit_completed_event.py": { "mode": "100644", - "sha256": "bd2f2d492c1db3bd37cea445b9cd1122181e3bcb60a74201962348f1fef36325" + "sha256": "8d288f7293dadacb3617c3dd90e3edfba15a04604910318ae4e4cab1f788ddb1" }, "src/openai/types/image_edit_params.py": { "mode": "100644", - "sha256": "c790b739d4c387faf43ea11576b33fcc3d382d914115f33fa14ec3077012df66" + "sha256": "f3182c188012e2905ef4e2f192ee368d7ad1199e930698eb6ee1c2e69c5b2887" }, "src/openai/types/image_edit_partial_image_event.py": { "mode": "100644", @@ -4475,7 +4475,7 @@ }, "src/openai/types/image_gen_completed_event.py": { "mode": "100644", - "sha256": "88fc97c451571487171d858a0fc4a73fd6420051df424638fa0d01ac039c9e60" + "sha256": "422fc133a90e049156c0bc20fdbdfc9010e5ac5a861ae38f27f6ba988c0250ac" }, "src/openai/types/image_gen_partial_image_event.py": { "mode": "100644", @@ -4487,7 +4487,7 @@ }, "src/openai/types/image_generate_params.py": { "mode": "100644", - "sha256": "919da351f49bd9e944334efd6b0d44d014c64649d5afdcaad9eccb407bfe271f" + "sha256": "ce11e6fc1ad113d96c6d3a275a1906da43d7ea4718fb72d9804559bd9ef60709" }, "src/openai/types/image_input_reference_param.py": { "mode": "100644", @@ -4499,7 +4499,7 @@ }, "src/openai/types/images_response.py": { "mode": "100644", - "sha256": "45543776df980cb2b4ce5d0dfa1800959af88641a4a915bf19e665fedccbb422" + "sha256": "07b223269f452e7e06d7d037b3c4cb867f52d3f4f3a32d7cfe1160ceea0a2c1b" }, "src/openai/types/live/__init__.py": { "mode": "100644", @@ -7695,7 +7695,7 @@ }, "tests/api_resources/test_images.py": { "mode": "100644", - "sha256": "cb12a050f0b1aef0e444813b75f503914f64a4280011de339e8a6bb739c9693e" + "sha256": "39b8d0e03206abc79df8eb4c3fe5c6a928dfb22d2ccaa2423e0a0db011e2b049" }, "tests/api_resources/test_live.py": { "mode": "100644", diff --git a/src/openai/resources/images.py b/src/openai/resources/images.py index 37b3359b2a..d1f9d330c2 100644 --- a/src/openai/resources/images.py +++ b/src/openai/resources/images.py @@ -145,6 +145,7 @@ def edit( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[str, Literal["1024x1024", "1536x1024", "1024x1536", "auto", "256x256", "512x512"], None] | Omit = omit, stream: Optional[Literal[False]] | Omit = omit, @@ -225,6 +226,13 @@ def edit( response_format: Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images. + safety_identifier: A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + size: The size of the generated images. Defaults to `auto`. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and @@ -241,8 +249,9 @@ def edit( [Image generation guide](https://developers.openai.com/api/docs/guides/image-generation) for more information. - user: A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + user: Deprecated: use `safety_identifier` instead. This parameter remains accepted for + backward compatibility and is used when `safety_identifier` is omitted, null, or + empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). extra_headers: Send extra headers @@ -272,6 +281,7 @@ def edit( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[str, Literal["1024x1024", "1536x1024", "1024x1536", "auto", "256x256", "512x512"], None] | Omit = omit, user: str | Omit = omit, @@ -355,6 +365,13 @@ def edit( response_format: Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images. + safety_identifier: A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + size: The size of the generated images. Defaults to `auto`. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and @@ -367,8 +384,9 @@ def edit( `1024x1536` are supported by the GPT image models; `auto` is supported for models that allow automatic sizing. - user: A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + user: Deprecated: use `safety_identifier` instead. This parameter remains accepted for + backward compatibility and is used when `safety_identifier` is omitted, null, or + empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). extra_headers: Send extra headers @@ -398,6 +416,7 @@ def edit( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[str, Literal["1024x1024", "1536x1024", "1024x1536", "auto", "256x256", "512x512"], None] | Omit = omit, user: str | Omit = omit, @@ -481,6 +500,13 @@ def edit( response_format: Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images. + safety_identifier: A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + size: The size of the generated images. Defaults to `auto`. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and @@ -493,8 +519,9 @@ def edit( `1024x1536` are supported by the GPT image models; `auto` is supported for models that allow automatic sizing. - user: A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + user: Deprecated: use `safety_identifier` instead. This parameter remains accepted for + backward compatibility and is used when `safety_identifier` is omitted, null, or + empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). extra_headers: Send extra headers @@ -523,6 +550,7 @@ def edit( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[str, Literal["1024x1024", "1536x1024", "1024x1536", "auto", "256x256", "512x512"], None] | Omit = omit, stream: Optional[Literal[False]] | Literal[True] | Omit = omit, @@ -548,6 +576,7 @@ def edit( "partial_images": partial_images, "quality": quality, "response_format": response_format, + "safety_identifier": safety_identifier, "size": size, "stream": stream, "user": user, @@ -592,6 +621,7 @@ def generate( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard", "hd"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[ str, Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"], @@ -663,6 +693,13 @@ def generate( response_format: Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images. + safety_identifier: A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + size: The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, arbitrary @@ -681,8 +718,9 @@ def generate( style: Legacy style parameter for retired image models. Unsupported for GPT image models; describe the desired style in the prompt instead. - user: A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + user: Deprecated: use `safety_identifier` instead. This parameter remains accepted for + backward compatibility and is used when `safety_identifier` is omitted, null, or + empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). extra_headers: Send extra headers @@ -710,6 +748,7 @@ def generate( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard", "hd"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[ str, Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"], @@ -784,6 +823,13 @@ def generate( response_format: Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images. + safety_identifier: A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + size: The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, arbitrary @@ -798,8 +844,9 @@ def generate( style: Legacy style parameter for retired image models. Unsupported for GPT image models; describe the desired style in the prompt instead. - user: A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + user: Deprecated: use `safety_identifier` instead. This parameter remains accepted for + backward compatibility and is used when `safety_identifier` is omitted, null, or + empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). extra_headers: Send extra headers @@ -827,6 +874,7 @@ def generate( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard", "hd"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[ str, Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"], @@ -901,6 +949,13 @@ def generate( response_format: Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images. + safety_identifier: A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + size: The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, arbitrary @@ -915,8 +970,9 @@ def generate( style: Legacy style parameter for retired image models. Unsupported for GPT image models; describe the desired style in the prompt instead. - user: A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + user: Deprecated: use `safety_identifier` instead. This parameter remains accepted for + backward compatibility and is used when `safety_identifier` is omitted, null, or + empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). extra_headers: Send extra headers @@ -943,6 +999,7 @@ def generate( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard", "hd"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[ str, Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"], @@ -974,6 +1031,7 @@ def generate( "partial_images": partial_images, "quality": quality, "response_format": response_format, + "safety_identifier": safety_identifier, "size": size, "style": style, "user": user, @@ -1114,6 +1172,7 @@ async def edit( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[str, Literal["1024x1024", "1536x1024", "1024x1536", "auto", "256x256", "512x512"], None] | Omit = omit, stream: Optional[Literal[False]] | Omit = omit, @@ -1194,6 +1253,13 @@ async def edit( response_format: Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images. + safety_identifier: A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + size: The size of the generated images. Defaults to `auto`. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and @@ -1210,8 +1276,9 @@ async def edit( [Image generation guide](https://developers.openai.com/api/docs/guides/image-generation) for more information. - user: A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + user: Deprecated: use `safety_identifier` instead. This parameter remains accepted for + backward compatibility and is used when `safety_identifier` is omitted, null, or + empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). extra_headers: Send extra headers @@ -1241,6 +1308,7 @@ async def edit( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[str, Literal["1024x1024", "1536x1024", "1024x1536", "auto", "256x256", "512x512"], None] | Omit = omit, user: str | Omit = omit, @@ -1324,6 +1392,13 @@ async def edit( response_format: Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images. + safety_identifier: A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + size: The size of the generated images. Defaults to `auto`. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and @@ -1336,8 +1411,9 @@ async def edit( `1024x1536` are supported by the GPT image models; `auto` is supported for models that allow automatic sizing. - user: A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + user: Deprecated: use `safety_identifier` instead. This parameter remains accepted for + backward compatibility and is used when `safety_identifier` is omitted, null, or + empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). extra_headers: Send extra headers @@ -1367,6 +1443,7 @@ async def edit( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[str, Literal["1024x1024", "1536x1024", "1024x1536", "auto", "256x256", "512x512"], None] | Omit = omit, user: str | Omit = omit, @@ -1450,6 +1527,13 @@ async def edit( response_format: Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images. + safety_identifier: A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + size: The size of the generated images. Defaults to `auto`. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and @@ -1462,8 +1546,9 @@ async def edit( `1024x1536` are supported by the GPT image models; `auto` is supported for models that allow automatic sizing. - user: A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + user: Deprecated: use `safety_identifier` instead. This parameter remains accepted for + backward compatibility and is used when `safety_identifier` is omitted, null, or + empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). extra_headers: Send extra headers @@ -1492,6 +1577,7 @@ async def edit( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[str, Literal["1024x1024", "1536x1024", "1024x1536", "auto", "256x256", "512x512"], None] | Omit = omit, stream: Optional[Literal[False]] | Literal[True] | Omit = omit, @@ -1517,6 +1603,7 @@ async def edit( "partial_images": partial_images, "quality": quality, "response_format": response_format, + "safety_identifier": safety_identifier, "size": size, "stream": stream, "user": user, @@ -1561,6 +1648,7 @@ async def generate( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard", "hd"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[ str, Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"], @@ -1632,6 +1720,13 @@ async def generate( response_format: Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images. + safety_identifier: A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + size: The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, arbitrary @@ -1650,8 +1745,9 @@ async def generate( style: Legacy style parameter for retired image models. Unsupported for GPT image models; describe the desired style in the prompt instead. - user: A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + user: Deprecated: use `safety_identifier` instead. This parameter remains accepted for + backward compatibility and is used when `safety_identifier` is omitted, null, or + empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). extra_headers: Send extra headers @@ -1679,6 +1775,7 @@ async def generate( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard", "hd"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[ str, Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"], @@ -1753,6 +1850,13 @@ async def generate( response_format: Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images. + safety_identifier: A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + size: The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, arbitrary @@ -1767,8 +1871,9 @@ async def generate( style: Legacy style parameter for retired image models. Unsupported for GPT image models; describe the desired style in the prompt instead. - user: A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + user: Deprecated: use `safety_identifier` instead. This parameter remains accepted for + backward compatibility and is used when `safety_identifier` is omitted, null, or + empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). extra_headers: Send extra headers @@ -1796,6 +1901,7 @@ async def generate( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard", "hd"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[ str, Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"], @@ -1870,6 +1976,13 @@ async def generate( response_format: Legacy response format parameter for retired image models. Unsupported for GPT image models, which always return base64-encoded images. + safety_identifier: A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + size: The size of the generated images. For `gpt-image-2`, `gpt-image-2-2026-04-21`, `gpt-image-2.5-sunburst`, `gpt-image-2.5-sunburst-2026-09-08`, `gpt-image-2.5-flare`, and `gpt-image-2.5-flare-2026-09-08`, arbitrary @@ -1884,8 +1997,9 @@ async def generate( style: Legacy style parameter for retired image models. Unsupported for GPT image models; describe the desired style in the prompt instead. - user: A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + user: Deprecated: use `safety_identifier` instead. This parameter remains accepted for + backward compatibility and is used when `safety_identifier` is omitted, null, or + empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). extra_headers: Send extra headers @@ -1912,6 +2026,7 @@ async def generate( partial_images: Optional[int] | Omit = omit, quality: Optional[Literal["low", "medium", "high", "xhigh", "max", "auto", "standard", "hd"]] | Omit = omit, response_format: Optional[Literal["url", "b64_json"]] | Omit = omit, + safety_identifier: Optional[str] | Omit = omit, size: Union[ str, Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"], @@ -1943,6 +2058,7 @@ async def generate( "partial_images": partial_images, "quality": quality, "response_format": response_format, + "safety_identifier": safety_identifier, "size": size, "style": style, "user": user, diff --git a/src/openai/types/image_edit_completed_event.py b/src/openai/types/image_edit_completed_event.py index ceee34cc11..0a6d67a642 100644 --- a/src/openai/types/image_edit_completed_event.py +++ b/src/openai/types/image_edit_completed_event.py @@ -1,6 +1,6 @@ # File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details. -from typing import Union +from typing import Union, Optional from typing_extensions import Literal from .._models import BaseModel @@ -65,3 +65,10 @@ class ImageEditCompletedEvent(BaseModel): For the GPT image models only, the token usage information for the image generation. """ + + safety_identifier: Optional[str] = None + """The effective safety identifier used for safety monitoring and abuse detection. + + This is the non-empty `safety_identifier` from the request, or the deprecated + `user` value when `safety_identifier` is omitted, null, or empty. + """ diff --git a/src/openai/types/image_edit_params.py b/src/openai/types/image_edit_params.py index 8d16171287..5013d20d9c 100644 --- a/src/openai/types/image_edit_params.py +++ b/src/openai/types/image_edit_params.py @@ -110,6 +110,16 @@ class ImageEditParamsBase(TypedDict, total=False): Unsupported for GPT image models, which always return base64-encoded images. """ + safety_identifier: Optional[str] + """ + A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + """ + size: Union[str, Literal["1024x1024", "1536x1024", "1024x1536", "auto", "256x256", "512x512"], None] """The size of the generated images. @@ -126,9 +136,10 @@ class ImageEditParamsBase(TypedDict, total=False): """ user: str - """ - A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + """Deprecated: use `safety_identifier` instead. + + This parameter remains accepted for backward compatibility and is used when + `safety_identifier` is omitted, null, or empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). """ diff --git a/src/openai/types/image_gen_completed_event.py b/src/openai/types/image_gen_completed_event.py index 23a10ee818..5f1c9f517a 100644 --- a/src/openai/types/image_gen_completed_event.py +++ b/src/openai/types/image_gen_completed_event.py @@ -1,6 +1,6 @@ # File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details. -from typing import Union +from typing import Union, Optional from typing_extensions import Literal from .._models import BaseModel @@ -65,3 +65,10 @@ class ImageGenCompletedEvent(BaseModel): For the GPT image models only, the token usage information for the image generation. """ + + safety_identifier: Optional[str] = None + """The effective safety identifier used for safety monitoring and abuse detection. + + This is the non-empty `safety_identifier` from the request, or the deprecated + `user` value when `safety_identifier` is omitted, null, or empty. + """ diff --git a/src/openai/types/image_generate_params.py b/src/openai/types/image_generate_params.py index bacb564e48..f79f888dc0 100644 --- a/src/openai/types/image_generate_params.py +++ b/src/openai/types/image_generate_params.py @@ -92,6 +92,16 @@ class ImageGenerateParamsBase(TypedDict, total=False): Unsupported for GPT image models, which always return base64-encoded images. """ + safety_identifier: Optional[str] + """ + A stable identifier for an end user in your organization, used for safety + monitoring and abuse detection. Hash a username or email address to avoid + sending identifying information. A non-empty value takes precedence over the + deprecated `user` parameter. If omitted, null, or empty, the API uses `user` + when available. + [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). + """ + size: Union[ str, Literal["auto", "1024x1024", "1536x1024", "1024x1536", "256x256", "512x512", "1792x1024", "1024x1792"], @@ -119,9 +129,10 @@ class ImageGenerateParamsBase(TypedDict, total=False): """ user: str - """ - A unique identifier representing your end-user, which can help OpenAI to monitor - and detect abuse. + """Deprecated: use `safety_identifier` instead. + + This parameter remains accepted for backward compatibility and is used when + `safety_identifier` is omitted, null, or empty. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers). """ diff --git a/src/openai/types/images_response.py b/src/openai/types/images_response.py index ea8d4be977..b49f38c7e6 100644 --- a/src/openai/types/images_response.py +++ b/src/openai/types/images_response.py @@ -72,6 +72,13 @@ class ImagesResponse(BaseModel): One of `low`, `medium`, `high`, `xhigh`, or `max`. """ + safety_identifier: Optional[str] = None + """The effective safety identifier used for safety monitoring and abuse detection. + + This is the non-empty `safety_identifier` from the request, or the deprecated + `user` value when `safety_identifier` is omitted, null, or empty. + """ + size: Union[str, Literal["1024x1024", "1024x1536", "1536x1024"], None] = None """The image dimensions as a `WIDTHxHEIGHT` string, for example `1536x864`.""" diff --git a/tests/api_resources/test_images.py b/tests/api_resources/test_images.py index b761606f18..d24d308453 100644 --- a/tests/api_resources/test_images.py +++ b/tests/api_resources/test_images.py @@ -91,6 +91,7 @@ def test_method_edit_with_all_params_overload_1(self, client: OpenAI) -> None: partial_images=1, quality="high", response_format="url", + safety_identifier="user-1234", size="1024x1024", stream=False, user="user-1234", @@ -148,6 +149,7 @@ def test_method_edit_with_all_params_overload_2(self, client: OpenAI) -> None: partial_images=1, quality="high", response_format="url", + safety_identifier="user-1234", size="1024x1024", user="user-1234", ) @@ -200,6 +202,7 @@ def test_method_generate_with_all_params_overload_1(self, client: OpenAI) -> Non partial_images=1, quality="medium", response_format="url", + safety_identifier="user-1234", size="1024x1024", stream=False, style="vivid", @@ -253,6 +256,7 @@ def test_method_generate_with_all_params_overload_2(self, client: OpenAI) -> Non partial_images=1, quality="medium", response_format="url", + safety_identifier="user-1234", size="1024x1024", style="vivid", user="user-1234", @@ -362,6 +366,7 @@ async def test_method_edit_with_all_params_overload_1(self, async_client: AsyncO partial_images=1, quality="high", response_format="url", + safety_identifier="user-1234", size="1024x1024", stream=False, user="user-1234", @@ -419,6 +424,7 @@ async def test_method_edit_with_all_params_overload_2(self, async_client: AsyncO partial_images=1, quality="high", response_format="url", + safety_identifier="user-1234", size="1024x1024", user="user-1234", ) @@ -471,6 +477,7 @@ async def test_method_generate_with_all_params_overload_1(self, async_client: As partial_images=1, quality="medium", response_format="url", + safety_identifier="user-1234", size="1024x1024", stream=False, style="vivid", @@ -524,6 +531,7 @@ async def test_method_generate_with_all_params_overload_2(self, async_client: As partial_images=1, quality="medium", response_format="url", + safety_identifier="user-1234", size="1024x1024", style="vivid", user="user-1234", diff --git a/tests/test_image_safety_identifier.py b/tests/test_image_safety_identifier.py new file mode 100644 index 0000000000..18ec850495 --- /dev/null +++ b/tests/test_image_safety_identifier.py @@ -0,0 +1,106 @@ +import json +import inspect +from typing import Optional + +import httpx2 +import pytest + +from openai import OpenAI, Stream, AsyncOpenAI, AsyncStream +from openai.types import ImageGenCompletedEvent, ImageEditCompletedEvent + + +@pytest.mark.parametrize("operation", ["generate", "edit"]) +@pytest.mark.parametrize("streaming", [False, True]) +@pytest.mark.parametrize("value", ["synthetic-image-safety-user", None, "omitted"]) +@pytest.mark.parametrize("asynchronous", [False, True]) +async def test_image_safety_identifier( + operation: str, streaming: bool, value: Optional[str], asynchronous: bool +) -> None: + requests: list[httpx2.Request] = [] + field = {} if value == "omitted" else {"safety_identifier": value} + expected = None if value == "omitted" else value + event_type = "image_generation.completed" if operation == "generate" else "image_edit.completed" + payload = ( + { + "type": event_type, + "b64_json": "c3ludGhldGlj", + "created_at": 1620000000, + "size": "1024x1024", + "quality": "high", + "background": "transparent", + "output_format": "png", + "usage": { + "total_tokens": 100, + "input_tokens": 50, + "output_tokens": 50, + "input_tokens_details": {"text_tokens": 10, "image_tokens": 40}, + }, + **field, + } + if streaming + else {"created": 1620000000, "data": [{"b64_json": "c3ludGhldGlj"}], **field} + ) + + def handler(request: httpx2.Request) -> httpx2.Response: + requests.append(request) + if streaming: + return httpx2.Response( + 200, headers={"content-type": "text/event-stream"}, content=f"data: {json.dumps(payload)}\n\n" + ) + return httpx2.Response(200, json=payload) + + if asynchronous: + client = AsyncOpenAI( + api_key="synthetic-key", + base_url="https://example.com/v1", + http_client=httpx2.AsyncClient(transport=httpx2.MockTransport(handler), trust_env=False), + ) + else: + client = OpenAI( + api_key="synthetic-key", + base_url="https://example.com/v1", + http_client=httpx2.Client(transport=httpx2.MockTransport(handler), trust_env=False), + ) + try: + if operation == "generate": + pending = client.images.generate( + prompt="A synthetic image", + stream=streaming, + safety_identifier="synthetic-request-user", + user="legacy-user", + ) + else: + pending = client.images.edit( + prompt="A synthetic image", + image=("test.png", b"synthetic", "image/png"), + stream=streaming, + safety_identifier="synthetic-request-user", + user="legacy-user", + ) + result = await pending if inspect.isawaitable(pending) else pending + if isinstance(result, (Stream, AsyncStream)): + events = [event async for event in result] if isinstance(result, AsyncStream) else list(result) + assert len(events) == 1 + event = events[0] + assert event.type == event_type + assert isinstance(event, (ImageGenCompletedEvent, ImageEditCompletedEvent)) + assert event.safety_identifier == expected + else: + assert result.safety_identifier == expected + finally: + if isinstance(client, AsyncOpenAI): + await client.close() + else: + client.close() + assert len(requests) == 1 + request = requests[0] + endpoint = "generations" if operation == "generate" else "edits" + assert request.url.path == f"/v1/images/{endpoint}" + assert request.method == "POST" + if operation == "generate": + body = json.loads(request.content) + assert body["safety_identifier"] == "synthetic-request-user" + assert body["user"] == "legacy-user" + else: + assert b'name="safety_identifier"\r\n\r\nsynthetic-request-user' in request.content + assert b'name="user"\r\n\r\nlegacy-user' in request.content