Skip to content

Commit ea0ff9e

Browse files
authored
Merge branch 'main' into patch-1
2 parents 88d4553 + 35df552 commit ea0ff9e

23 files changed

+1887
-221
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.96.1"
2+
".": "1.97.0"
33
}

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 111
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-c7dacca97e28bceff218684bb429481a70aa47aadad983ed9178bfda75ff4cd2.yml
3-
openapi_spec_hash: 28eb1bb901ca10d2e37db4606d2bcfa7
4-
config_hash: 167ad0ca036d0f023c78e6496b4311e8
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-670ea0d2cc44f52a87dd3cadea45632953283e0636ba30788fdbdb22a232ccac.yml
3+
openapi_spec_hash: d8b7d38911fead545adf3e4297956410
4+
config_hash: 5525bda35e48ea6387c6175c4d1651fa

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 1.97.0 (2025-07-16)
4+
5+
Full Changelog: [v1.96.1...v1.97.0](https://github.com/openai/openai-python/compare/v1.96.1...v1.97.0)
6+
7+
### Features
8+
9+
* **api:** manual updates ([ed8e899](https://github.com/openai/openai-python/commit/ed8e89953d11bd5f44fa531422bdbb7a577ab426))
10+
311
## 1.96.1 (2025-07-15)
412

513
Full Changelog: [v1.96.0...v1.96.1](https://github.com/openai/openai-python/compare/v1.96.0...v1.96.1)

api.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,17 @@ Methods:
127127
Types:
128128

129129
```python
130-
from openai.types import Image, ImageModel, ImagesResponse
130+
from openai.types import (
131+
Image,
132+
ImageEditCompletedEvent,
133+
ImageEditPartialImageEvent,
134+
ImageEditStreamEvent,
135+
ImageGenCompletedEvent,
136+
ImageGenPartialImageEvent,
137+
ImageGenStreamEvent,
138+
ImageModel,
139+
ImagesResponse,
140+
)
131141
```
132142

133143
Methods:

examples/image_stream.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python
2+
3+
import base64
4+
from pathlib import Path
5+
6+
from openai import OpenAI
7+
8+
client = OpenAI()
9+
10+
11+
def main() -> None:
12+
"""Example of OpenAI image streaming with partial images."""
13+
stream = client.images.generate(
14+
model="gpt-image-1",
15+
prompt="A cute baby sea otter",
16+
n=1,
17+
size="1024x1024",
18+
stream=True,
19+
partial_images=3,
20+
)
21+
22+
for event in stream:
23+
if event.type == "image_generation.partial_image":
24+
print(f" Partial image {event.partial_image_index + 1}/3 received")
25+
print(f" Size: {len(event.b64_json)} characters (base64)")
26+
27+
# Save partial image to file
28+
filename = f"partial_{event.partial_image_index + 1}.png"
29+
image_data = base64.b64decode(event.b64_json)
30+
with open(filename, "wb") as f:
31+
f.write(image_data)
32+
print(f" 💾 Saved to: {Path(filename).resolve()}")
33+
34+
elif event.type == "image_generation.completed":
35+
print(f"\n✅ Final image completed!")
36+
print(f" Size: {len(event.b64_json)} characters (base64)")
37+
38+
# Save final image to file
39+
filename = "final_image.png"
40+
image_data = base64.b64decode(event.b64_json)
41+
with open(filename, "wb") as f:
42+
f.write(image_data)
43+
print(f" 💾 Saved to: {Path(filename).resolve()}")
44+
45+
else:
46+
print(f"❓ Unknown event: {event}") # type: ignore[unreachable]
47+
48+
49+
if __name__ == "__main__":
50+
try:
51+
main()
52+
except Exception as error:
53+
print(f"Error generating image: {error}")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "openai"
3-
version = "1.96.1"
3+
version = "1.97.0"
44
description = "The official Python library for the openai API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"

src/openai/_streaming.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,10 @@ def is_stream_class_type(typ: type) -> TypeGuard[type[Stream[object]] | type[Asy
387387

388388
def is_valid_event(event: str | None) -> bool:
389389
"""Given an event fieldname, checks if it is a response, transcript, or None"""
390+
VALID_EVENTS = ("response", "transcript", "image_edit", "image_generation")
390391
if event is None:
391392
return True
392-
if event in ("response", "transcript") or event.startswith("response.") or event.startswith("transcript."):
393+
if event in VALID_EVENTS or any(event.startswith(f"{e}.") for e in VALID_EVENTS):
393394
return True
394395
return False
395396

src/openai/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
__title__ = "openai"
4-
__version__ = "1.96.1" # x-release-please-version
4+
__version__ = "1.97.0" # x-release-please-version

0 commit comments

Comments
 (0)