Skip to content

Commit f6de1a0

Browse files
authored
Merge branch 'main' into chore/client-comment-fix
2 parents 4dcfdab + 1dbb72b commit f6de1a0

File tree

176 files changed

+7633
-3413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+7633
-3413
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
- 'integrated/**'
88
- 'stl-preview-head/**'
99
- 'stl-preview-base/**'
10+
pull_request:
11+
branches-ignore:
12+
- 'stl-preview-head/**'
13+
- 'stl-preview-base/**'
1014

1115
jobs:
1216
lint:
@@ -95,11 +99,11 @@ jobs:
9599
run: |
96100
rye sync --all-features
97101
98-
- env:
102+
- env:
99103
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
100104
run: |
101105
rye run python examples/demo.py
102-
- env:
106+
- env:
103107
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
104108
run: |
105109
rye run python examples/async_demo.py

.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.82.0"
2+
".": "1.93.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-fc64d7c2c8f51f750813375356c3f3fdfc7fc1b1b34f19c20a5410279d445d37.yml
3-
openapi_spec_hash: 618285fc70199ee32b9ebe4bf72f7e4c
4-
config_hash: c497f6b750cc89c0bf2eefc0bc839c70
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-a473967d1766dc155994d932fbc4a5bcbd1c140a37c20d0a4065e1bf0640536d.yml
3+
openapi_spec_hash: 67cdc62b0d6c8b1de29b7dc54b265749
4+
config_hash: 7b53f96f897ca1b3407a5341a6f820db

CHANGELOG.md

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

3+
## 1.93.0 (2025-06-27)
4+
5+
Full Changelog: [v1.92.3...v1.93.0](https://github.com/openai/openai-python/compare/v1.92.3...v1.93.0)
6+
7+
### Features
8+
9+
* **cli:** add support for fine_tuning.jobs ([#1224](https://github.com/openai/openai-python/issues/1224)) ([e362bfd](https://github.com/openai/openai-python/commit/e362bfd10dfd04176560b964470ab0c517c601f3))
10+
11+
## 1.92.3 (2025-06-27)
12+
13+
Full Changelog: [v1.92.2...v1.92.3](https://github.com/openai/openai-python/compare/v1.92.2...v1.92.3)
14+
15+
### Bug Fixes
16+
17+
* **client:** avoid encoding error with empty API keys ([5a3e64e](https://github.com/openai/openai-python/commit/5a3e64e0cc761dbaa613fb22ec16e7e73c3bcf72))
18+
19+
20+
### Documentation
21+
22+
* **examples/realtime:** mention macOS requirements ([#2142](https://github.com/openai/openai-python/issues/2142)) ([27bf6b2](https://github.com/openai/openai-python/commit/27bf6b2a933c61d5ec23fd266148af888f69f5c1))
23+
24+
## 1.92.2 (2025-06-26)
25+
26+
Full Changelog: [v1.92.1...v1.92.2](https://github.com/openai/openai-python/compare/v1.92.1...v1.92.2)
27+
28+
### Chores
29+
30+
* **api:** remove unsupported property ([ec24408](https://github.com/openai/openai-python/commit/ec2440864e03278144d7f58b97c31d87903e0843))
31+
32+
## 1.92.1 (2025-06-26)
33+
34+
Full Changelog: [v1.92.0...v1.92.1](https://github.com/openai/openai-python/compare/v1.92.0...v1.92.1)
35+
36+
### Chores
37+
38+
* **client:** sync stream/parse methods over ([e2536cf](https://github.com/openai/openai-python/commit/e2536cfd74224047cece9c2ad86f0ffe51c0667c))
39+
* **docs:** update README to include links to docs on Webhooks ([ddbf9f1](https://github.com/openai/openai-python/commit/ddbf9f1dc47a32257716189f2056b45933328c9c))
40+
41+
## 1.92.0 (2025-06-26)
42+
43+
Full Changelog: [v1.91.0...v1.92.0](https://github.com/openai/openai-python/compare/v1.91.0...v1.92.0)
44+
45+
### Features
46+
47+
* **api:** webhook and deep research support ([d3bb116](https://github.com/openai/openai-python/commit/d3bb116f34f470502f902b88131deec43a953b12))
48+
* **client:** move stream and parse out of beta ([0e358ed](https://github.com/openai/openai-python/commit/0e358ed66b317038705fb38958a449d284f3cb88))
49+
50+
51+
### Bug Fixes
52+
53+
* **ci:** release-doctor — report correct token name ([ff8c556](https://github.com/openai/openai-python/commit/ff8c5561e44e8a0902732b5934c97299d2c98d4e))
54+
55+
56+
### Chores
57+
58+
* **internal:** add tests for breaking change detection ([710fe8f](https://github.com/openai/openai-python/commit/710fe8fd5f9e33730338341680152d3f2556dfa0))
59+
* **tests:** skip some failing tests on the latest python versions ([93ccc38](https://github.com/openai/openai-python/commit/93ccc38a8ef1575d77d33d031666d07d10e4af72))
60+
61+
## 1.91.0 (2025-06-23)
62+
63+
Full Changelog: [v1.90.0...v1.91.0](https://github.com/openai/openai-python/compare/v1.90.0...v1.91.0)
64+
65+
### Features
66+
67+
* **api:** update api shapes for usage and code interpreter ([060d566](https://github.com/openai/openai-python/commit/060d5661e4a1fcdb953c52facd3e668ee80f9295))
68+
69+
## 1.90.0 (2025-06-20)
70+
71+
Full Changelog: [v1.89.0...v1.90.0](https://github.com/openai/openai-python/compare/v1.89.0...v1.90.0)
72+
73+
### Features
74+
75+
* **api:** make model and inputs not required to create response ([11bd62e](https://github.com/openai/openai-python/commit/11bd62eb7e46eec748edaf2e0cecf253ffc1202c))
76+
77+
## 1.89.0 (2025-06-20)
78+
79+
Full Changelog: [v1.88.0...v1.89.0](https://github.com/openai/openai-python/compare/v1.88.0...v1.89.0)
80+
81+
### Features
82+
83+
* **client:** add support for aiohttp ([9218b07](https://github.com/openai/openai-python/commit/9218b07727bf6f6eb00953df66de6ab061fecddb))
84+
85+
86+
### Bug Fixes
87+
88+
* **tests:** fix: tests which call HTTP endpoints directly with the example parameters ([35bcc4b](https://github.com/openai/openai-python/commit/35bcc4b80bdbaa31108650f2a515902e83794e5a))
89+
90+
91+
### Chores
92+
93+
* **readme:** update badges ([68044ee](https://github.com/openai/openai-python/commit/68044ee85d1bf324b17d3f60c914df4725d47fc8))
94+
95+
## 1.88.0 (2025-06-17)
96+
97+
Full Changelog: [v1.87.0...v1.88.0](https://github.com/openai/openai-python/compare/v1.87.0...v1.88.0)
98+
99+
### Features
100+
101+
* **api:** manual updates ([5d18a84](https://github.com/openai/openai-python/commit/5d18a8448ecbe31597e98ec7f64d7050c831901e))
102+
103+
104+
### Chores
105+
106+
* **ci:** enable for pull requests ([542b0ce](https://github.com/openai/openai-python/commit/542b0ce98f14ccff4f9e1bcbd3a9ea5e4f846638))
107+
* **internal:** minor formatting ([29d723d](https://github.com/openai/openai-python/commit/29d723d1f1baf2a5843293c8647dc7baa16d56d1))
108+
109+
## 1.87.0 (2025-06-16)
110+
111+
Full Changelog: [v1.86.0...v1.87.0](https://github.com/openai/openai-python/compare/v1.86.0...v1.87.0)
112+
113+
### Features
114+
115+
* **api:** add reusable prompt IDs ([36bfe6e](https://github.com/openai/openai-python/commit/36bfe6e8ae12a31624ba1a360d9260f0aeec448a))
116+
117+
118+
### Bug Fixes
119+
120+
* **client:** update service_tier on `client.beta.chat.completions` ([aa488d5](https://github.com/openai/openai-python/commit/aa488d5cf210d8640f87216538d4ff79d7181f2a))
121+
122+
123+
### Chores
124+
125+
* **internal:** codegen related update ([b1a31e5](https://github.com/openai/openai-python/commit/b1a31e5ef4387d9f82cf33f9461371651788d381))
126+
* **internal:** update conftest.py ([bba0213](https://github.com/openai/openai-python/commit/bba0213842a4c161f2235e526d50901a336eecef))
127+
* **tests:** add tests for httpx client instantiation & proxies ([bc93712](https://github.com/openai/openai-python/commit/bc9371204f457aee9ed9b6ec1b61c2084f32faf1))
128+
129+
## 1.86.0 (2025-06-10)
130+
131+
Full Changelog: [v1.85.0...v1.86.0](https://github.com/openai/openai-python/compare/v1.85.0...v1.86.0)
132+
133+
### Features
134+
135+
* **api:** Add o3-pro model IDs ([d8dd80b](https://github.com/openai/openai-python/commit/d8dd80b1b4e6c73687d7acb6c3f62f0bf4b8282c))
136+
137+
## 1.85.0 (2025-06-09)
138+
139+
Full Changelog: [v1.84.0...v1.85.0](https://github.com/openai/openai-python/compare/v1.84.0...v1.85.0)
140+
141+
### Features
142+
143+
* **api:** Add tools and structured outputs to evals ([002cc7b](https://github.com/openai/openai-python/commit/002cc7bb3c315d95b81c2e497f55d21be7fd26f8))
144+
145+
146+
### Bug Fixes
147+
148+
* **responses:** support raw responses for `parse()` ([d459943](https://github.com/openai/openai-python/commit/d459943cc1c81cf9ce5c426edd3ef9112fdf6723))
149+
150+
## 1.84.0 (2025-06-03)
151+
152+
Full Changelog: [v1.83.0...v1.84.0](https://github.com/openai/openai-python/compare/v1.83.0...v1.84.0)
153+
154+
### Features
155+
156+
* **api:** add new realtime and audio models, realtime session options ([0acd0da](https://github.com/openai/openai-python/commit/0acd0da6bc0468c6c857711bc5e77d0bc6d31be6))
157+
158+
159+
### Chores
160+
161+
* **api:** update type names ([1924559](https://github.com/openai/openai-python/commit/192455913b38bf0323ddd0e2b1499b114e2111a1))
162+
163+
## 1.83.0 (2025-06-02)
164+
165+
Full Changelog: [v1.82.1...v1.83.0](https://github.com/openai/openai-python/compare/v1.82.1...v1.83.0)
166+
167+
### Features
168+
169+
* **api:** Config update for pakrym-stream-param ([88bcf3a](https://github.com/openai/openai-python/commit/88bcf3af9ce8ffa8347547d4d30aacac1ceba939))
170+
* **client:** add follow_redirects request option ([26d715f](https://github.com/openai/openai-python/commit/26d715f4e9b0f2b19e2ac16acc796a949338e1e1))
171+
172+
173+
### Bug Fixes
174+
175+
* **api:** Fix evals and code interpreter interfaces ([2650159](https://github.com/openai/openai-python/commit/2650159f6d01f6eb481cf8c7942142e4fd21ce44))
176+
* **client:** return binary content from `get /containers/{container_id}/files/{file_id}/content` ([f7c80c4](https://github.com/openai/openai-python/commit/f7c80c4368434bd0be7436375076ba33a62f63b5))
177+
178+
179+
### Chores
180+
181+
* **api:** mark some methods as deprecated ([3e2ca57](https://github.com/openai/openai-python/commit/3e2ca571cb6cdd9e15596590605b2f98a4c5a42e))
182+
* deprecate Assistants API ([9d166d7](https://github.com/openai/openai-python/commit/9d166d795e03dea49af680ec9597e9497522187c))
183+
* **docs:** remove reference to rye shell ([c7978e9](https://github.com/openai/openai-python/commit/c7978e9f1640c311022988fcd716cbb5c865daa8))
184+
185+
## 1.82.1 (2025-05-29)
186+
187+
Full Changelog: [v1.82.0...v1.82.1](https://github.com/openai/openai-python/compare/v1.82.0...v1.82.1)
188+
189+
### Bug Fixes
190+
191+
* **responses:** don't include `parsed_arguments` when re-serialising ([6d04193](https://github.com/openai/openai-python/commit/6d041937963ce452affcfb3553146ee51acfeb7a))
192+
193+
194+
### Chores
195+
196+
* **internal:** fix release workflows ([361a909](https://github.com/openai/openai-python/commit/361a909a0cc83e5029ea425fd72202ffa8d1a46a))
197+
3198
## 1.82.0 (2025-05-22)
4199

5200
Full Changelog: [v1.81.0...v1.82.0](https://github.com/openai/openai-python/compare/v1.81.0...v1.82.0)

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ $ rye sync --all-features
1717
You can then run scripts using `rye run python script.py` or by activating the virtual environment:
1818

1919
```sh
20-
$ rye shell
21-
# or manually activate - https://docs.python.org/3/library/venv.html#how-venvs-work
20+
# Activate the virtual environment - https://docs.python.org/3/library/venv.html#how-venvs-work
2221
$ source .venv/bin/activate
2322

2423
# now you can omit the `rye run` prefix

README.md

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OpenAI Python API library
22

3-
[![PyPI version](https://img.shields.io/pypi/v/openai.svg)](https://pypi.org/project/openai/)
3+
[![PyPI version](<https://img.shields.io/pypi/v/openai.svg?label=pypi%20(stable)>)](https://pypi.org/project/openai/)
44

55
The OpenAI Python library provides convenient access to the OpenAI REST API from any Python 3.8+
66
application. The library includes type definitions for all request params and response fields,
@@ -145,6 +145,45 @@ asyncio.run(main())
145145

146146
Functionality between the synchronous and asynchronous clients is otherwise identical.
147147

148+
### With aiohttp
149+
150+
By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.
151+
152+
You can enable this by installing `aiohttp`:
153+
154+
```sh
155+
# install from PyPI
156+
pip install openai[aiohttp]
157+
```
158+
159+
Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
160+
161+
```python
162+
import os
163+
import asyncio
164+
from openai import DefaultAioHttpClient
165+
from openai import AsyncOpenAI
166+
167+
168+
async def main() -> None:
169+
async with AsyncOpenAI(
170+
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
171+
http_client=DefaultAioHttpClient(),
172+
) as client:
173+
chat_completion = await client.chat.completions.create(
174+
messages=[
175+
{
176+
"role": "user",
177+
"content": "Say this is a test",
178+
}
179+
],
180+
model="gpt-4o",
181+
)
182+
183+
184+
asyncio.run(main())
185+
```
186+
148187
## Streaming responses
149188

150189
We provide support for streaming responses using Server Side Events (SSE).
@@ -367,6 +406,86 @@ client.files.create(
367406

368407
The async client uses the exact same interface. If you pass a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance, the file contents will be read asynchronously automatically.
369408

409+
## Webhook Verification
410+
411+
Verifying webhook signatures is _optional but encouraged_.
412+
413+
For more information about webhooks, see [the API docs](https://platform.openai.com/docs/guides/webhooks).
414+
415+
### Parsing webhook payloads
416+
417+
For most use cases, you will likely want to verify the webhook and parse the payload at the same time. To achieve this, we provide the method `client.webhooks.unwrap()`, which parses a webhook request and verifies that it was sent by OpenAI. This method will raise an error if the signature is invalid.
418+
419+
Note that the `body` parameter must be the raw JSON string sent from the server (do not parse it first). The `.unwrap()` method will parse this JSON for you into an event object after verifying the webhook was sent from OpenAI.
420+
421+
```python
422+
from openai import OpenAI
423+
from flask import Flask, request
424+
425+
app = Flask(__name__)
426+
client = OpenAI() # OPENAI_WEBHOOK_SECRET environment variable is used by default
427+
428+
429+
@app.route("/webhook", methods=["POST"])
430+
def webhook():
431+
request_body = request.get_data(as_text=True)
432+
433+
try:
434+
event = client.webhooks.unwrap(request_body, request.headers)
435+
436+
if event.type == "response.completed":
437+
print("Response completed:", event.data)
438+
elif event.type == "response.failed":
439+
print("Response failed:", event.data)
440+
else:
441+
print("Unhandled event type:", event.type)
442+
443+
return "ok"
444+
except Exception as e:
445+
print("Invalid signature:", e)
446+
return "Invalid signature", 400
447+
448+
449+
if __name__ == "__main__":
450+
app.run(port=8000)
451+
```
452+
453+
### Verifying webhook payloads directly
454+
455+
In some cases, you may want to verify the webhook separately from parsing the payload. If you prefer to handle these steps separately, we provide the method `client.webhooks.verify_signature()` to _only verify_ the signature of a webhook request. Like `.unwrap()`, this method will raise an error if the signature is invalid.
456+
457+
Note that the `body` parameter must be the raw JSON string sent from the server (do not parse it first). You will then need to parse the body after verifying the signature.
458+
459+
```python
460+
import json
461+
from openai import OpenAI
462+
from flask import Flask, request
463+
464+
app = Flask(__name__)
465+
client = OpenAI() # OPENAI_WEBHOOK_SECRET environment variable is used by default
466+
467+
468+
@app.route("/webhook", methods=["POST"])
469+
def webhook():
470+
request_body = request.get_data(as_text=True)
471+
472+
try:
473+
client.webhooks.verify_signature(request_body, request.headers)
474+
475+
# Parse the body after verification
476+
event = json.loads(request_body)
477+
print("Verified event:", event)
478+
479+
return "ok"
480+
except Exception as e:
481+
print("Invalid signature:", e)
482+
return "Invalid signature", 400
483+
484+
485+
if __name__ == "__main__":
486+
app.run(port=8000)
487+
```
488+
370489
## Handling errors
371490

372491
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `openai.APIConnectionError` is raised.

0 commit comments

Comments
 (0)