Skip to content

Commit 4c622f9

Browse files
committed
feat(client): promote beta completions methods to GA
1 parent a899c97 commit 4c622f9

29 files changed

+193
-200
lines changed

MIGRATION.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ The `openai/shims` imports have been removed. Your global types must now be [cor
315315
Previously, the following code would just output a warning to the console, now it will throw an error.
316316

317317
```ts
318-
const completion = await client.beta.chat.completions.parse({
318+
const completion = await client.chat.completions.parse({
319319
// ...
320320
response_format: zodResponseFormat(
321321
z.object({
@@ -329,7 +329,7 @@ const completion = await client.beta.chat.completions.parse({
329329
You must mark optional properties with `.nullable()` as purely optional fields are not supported by the [API](https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required).
330330

331331
```ts
332-
const completion = await client.beta.chat.completions.parse({
332+
const completion = await client.chat.completions.parse({
333333
// ...
334334
response_format: zodResponseFormat(
335335
z.object({
@@ -377,18 +377,44 @@ export type FineTuningJobsPage = CursorPage<FineTuningJob>;
377377

378378
If you were importing these classes at runtime, you'll need to switch to importing the base class or only import them at the type-level.
379379

380+
### Beta chat namespace removed
381+
382+
The `beta.chat` namespace has been removed. All chat completion methods that were previously in beta have been moved to the main `chat.completions` namespace:
383+
384+
```ts
385+
// Before
386+
client.beta.chat.completions.parse()
387+
client.beta.chat.completions.stream()
388+
client.beta.chat.completions.runTools()
389+
390+
// After
391+
client.chat.completions.parse()
392+
client.chat.completions.stream()
393+
client.chat.completions.runTools()
394+
```
395+
396+
Additionally, related types have been moved:
397+
398+
```ts
399+
// Before
400+
import { ParsedChatCompletion, ParsedChoice, ParsedFunction } from 'openai/resources/beta/chat/completions';
401+
402+
// After
403+
import { ParsedChatCompletion, ParsedChoice, ParsedFunction } from 'openai/resources/chat/completions';
404+
```
405+
380406
### Removed deprecated `.runFunctions` methods
381407

382-
The deprecated `client.beta.chat.completions.runFunctions()` method and all of it's surrounding types have been removed, instead you should use
383-
`client.beta.chat.completions.runTools()`.
408+
The deprecated `client.chat.completions.runFunctions()` method and all of it's surrounding types have been removed, instead you should use
409+
`client.chat.completions.runTools()`.
384410

385411
### `.runTools()` event / method names
386412

387413
To better align with the tool-based API, several event names in the ChatCompletionRunner have been renamed:
388414

389415
```ts
390416
// Before
391-
openai.beta.chat.completions
417+
openai.chat.completions
392418
.runTools({
393419
// ..
394420
})
@@ -398,7 +424,7 @@ openai.beta.chat.completions
398424
.on('finalFunctionCallResult', (result) => console.log('finalFunctionCallResult', result));
399425

400426
// After
401-
openai.beta.chat.completions
427+
openai.chat.completions
402428
.runTools({
403429
// ..
404430
})

ecosystem-tests/node-ts-cjs-auto/tests/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ it(`ChatCompletionStream works`, async function () {
7676
let finalMessage: OpenAI.Chat.ChatCompletionMessageParam | undefined;
7777
let finalChatCompletion: OpenAI.Chat.ChatCompletion | undefined;
7878

79-
const stream = client.beta.chat.completions
79+
const stream = client.chat.completions
8080
.stream({
8181
model: 'gpt-4',
8282
messages: [{ role: 'user', content: 'Say this is a test' }],
@@ -120,7 +120,7 @@ it(`aborting ChatCompletionStream works`, async function () {
120120
let emittedError: any;
121121
let caughtError: any;
122122
const controller = new AbortController();
123-
const stream = client.beta.chat.completions
123+
const stream = client.chat.completions
124124
.stream(
125125
{
126126
model: 'gpt-4',

examples/logprobs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import OpenAI from 'openai';
66
const openai = new OpenAI();
77

88
async function main() {
9-
const stream = await openai.beta.chat.completions
9+
const stream = await openai.chat.completions
1010
.stream({
1111
model: 'gpt-4',
1212
messages: [{ role: 'user', content: 'Say this is a test' }],

examples/parsing-run-tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const Condition = z.object({
2828
const openai = new OpenAI();
2929

3030
async function main() {
31-
const runner = openai.beta.chat.completions
31+
const runner = openai.chat.completions
3232
.runTools({
3333
model: 'gpt-4o-2024-08-06',
3434
messages: [{ role: 'user', content: `What are the last 10 orders?` }],

examples/parsing-stream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const MathResponse = z.object({
1515
async function main() {
1616
const client = new OpenAI();
1717

18-
const stream = client.beta.chat.completions
18+
const stream = client.chat.completions
1919
.stream({
2020
model: 'gpt-4o-2024-08-06',
2121
messages: [

examples/parsing-tools-stream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function main() {
1212
const client = new OpenAI();
1313
const refusal = process.argv.includes('refusal');
1414

15-
const stream = client.beta.chat.completions
15+
const stream = client.chat.completions
1616
.stream({
1717
model: 'gpt-4o-2024-08-06',
1818
messages: [

examples/parsing-tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const Query = z.object({
3838
async function main() {
3939
const client = new OpenAI();
4040

41-
const completion = await client.beta.chat.completions.parse({
41+
const completion = await client.chat.completions.parse({
4242
model: 'gpt-4o-2024-08-06',
4343
messages: [
4444
{

examples/parsing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const MathResponse = z.object({
1515
async function main() {
1616
const client = new OpenAI();
1717

18-
const completion = await client.beta.chat.completions.parse({
18+
const completion = await client.chat.completions.parse({
1919
model: 'gpt-4o-2024-08-06',
2020
messages: [
2121
{ role: 'system', content: 'You are a helpful math tutor.' },

examples/stream-to-client-express.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ app.post('/', async (req: Request, res: Response) => {
3030
try {
3131
console.log('Received request:', req.body);
3232

33-
const stream = openai.beta.chat.completions.stream({
33+
const stream = openai.chat.completions.stream({
3434
model: 'gpt-3.5-turbo',
3535
stream: true,
3636
messages: [{ role: 'user', content: req.body }],

examples/stream-to-client-next.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const runtime = 'edge';
2525
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
2626
const openai = new OpenAI();
2727

28-
const stream = openai.beta.chat.completions.stream({
28+
const stream = openai.chat.completions.stream({
2929
model: 'gpt-3.5-turbo',
3030
stream: true,
3131
// @ts-ignore

0 commit comments

Comments
 (0)