Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update dependency openai to v4.85.2 #247

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Feb 26, 2025

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
openai 4.83.0 -> 4.85.2 age adoption passing confidence

Release Notes

openai/openai-node (openai)

v4.85.2

Compare Source

Full Changelog: v4.85.1...v4.85.2

Bug Fixes

v4.85.1

Compare Source

Full Changelog: v4.85.0...v4.85.1

Bug Fixes
Chores

v4.85.0

Compare Source

Full Changelog: v4.84.1...v4.85.0

Features
Bug Fixes

v4.84.1

Compare Source

Full Changelog: v4.84.0...v4.84.1

Bug Fixes

v4.84.0

Compare Source

Full Changelog: v4.83.0...v4.84.0

Features
Bug Fixes
  • api: add missing reasoning effort + model enums (#​1302) (14c55c3)
  • assistants: handle thread.run.incomplete event (7032cc4)
  • correctly decode multi-byte characters over multiple chunks (#​1316) (dd776c4)
Chores
  • internal: remove segfault-handler dependency (3521ca3)
Documentation
  • readme: cleanup into multiple files (da94424)

Configuration

📅 Schedule: Branch creation - "* 0-12 * * 3" (UTC), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot requested a review from thypon as a code owner February 26, 2025 01:50
Copy link

anthropic debug - [puLL-Merge] - openai/[email protected]

Diff
diff --git .github/workflows/ci.yml .github/workflows/ci.yml
index d6798e38a..85d792c44 100644
--- .github/workflows/ci.yml
+++ .github/workflows/ci.yml
@@ -64,3 +64,36 @@ jobs:
 
       - name: Run tests
         run: ./scripts/test
+
+  ecosystem_tests:
+    name: ecosystem tests (v${{ matrix.node-version }})
+    runs-on: ubuntu-latest
+    if: github.repository == 'openai/openai-node'
+    timeout-minutes: 20
+    strategy:
+      fail-fast: false
+      matrix:
+        node-version: ['20']
+
+    steps:
+      - uses: actions/checkout@v4
+
+      - name: Set up Node
+        uses: actions/setup-node@v4
+        with:
+          node-version: '${{ matrix.node-version }}'
+
+      - uses: denoland/setup-deno@v1
+        with:
+          deno-version: v1.39.0
+
+      - uses: oven-sh/setup-bun@v2
+
+      - name: Bootstrap
+        run: ./scripts/bootstrap
+
+      - name: Run ecosystem tests
+        run: |
+          yarn tsn ecosystem-tests/cli.ts --live --verbose --parallel --jobs=4 --retry=3
+        env:
+          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
diff --git .gitignore .gitignore
index 81c4c41ca..3fdab1cb7 100644
--- .gitignore
+++ .gitignore
@@ -11,4 +11,4 @@ tmp
 .pack
 ecosystem-tests/deno/package.json
 ecosystem-tests/*/openai.tgz
-
+.dev.vars
diff --git .release-please-manifest.json .release-please-manifest.json
index 6eb0f130e..541794534 100644
--- .release-please-manifest.json
+++ .release-please-manifest.json
@@ -1,3 +1,3 @@
 {
-  ".": "4.83.0"
+  ".": "4.85.2"
 }
diff --git .stats.yml .stats.yml
index df7877dfd..658877d3b 100644
--- .stats.yml
+++ .stats.yml
@@ -1,2 +1,2 @@
-configured_endpoints: 69
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-fc5dbc19505b0035f9e7f88868619f4fb519b048bde011f6154f3132d4be71fb.yml
+configured_endpoints: 74
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-4aa6ee65ba9efc789e05e6a5ef0883b2cadf06def8efd863dbf75e9e233067e1.yml
diff --git CHANGELOG.md CHANGELOG.md
index f61def5e4..70a447b0a 100644
--- CHANGELOG.md
+++ CHANGELOG.md
@@ -1,5 +1,73 @@
 # Changelog
 
+## 4.85.2 (2025-02-18)
+
+Full Changelog: [v4.85.1...v4.85.2](https://github.com/openai/openai-node/compare/v4.85.1...v4.85.2)
+
+### Bug Fixes
+
+* optimize sse chunk reading off-by-one error ([#1339](https://github.com/openai/openai-node/issues/1339)) ([c82795b](https://github.com/openai/openai-node/commit/c82795b189c73d1c0e3bc3a40d0d4a2558b0483a))
+
+## 4.85.1 (2025-02-14)
+
+Full Changelog: [v4.85.0...v4.85.1](https://github.com/openai/openai-node/compare/v4.85.0...v4.85.1)
+
+### Bug Fixes
+
+* **client:** fix export map for index exports ([#1328](https://github.com/openai/openai-node/issues/1328)) ([647ba7a](https://github.com/openai/openai-node/commit/647ba7a52311928f604c72b2cc95698c0837887f))
+* **package:** add chat/completions.ts back in ([#1333](https://github.com/openai/openai-node/issues/1333)) ([e4b5546](https://github.com/openai/openai-node/commit/e4b554632ab1646da831f29413fefb3378c49cc1))
+
+
+### Chores
+
+* **internal:** add missing return type annotation ([#1334](https://github.com/openai/openai-node/issues/1334)) ([53e0856](https://github.com/openai/openai-node/commit/53e0856ec4d36deee4d71b5aaf436df0a59b9402))
+
+## 4.85.0 (2025-02-13)
+
+Full Changelog: [v4.84.1...v4.85.0](https://github.com/openai/openai-node/compare/v4.84.1...v4.85.0)
+
+### Features
+
+* **api:** add support for storing chat completions ([#1327](https://github.com/openai/openai-node/issues/1327)) ([8d77f8e](https://github.com/openai/openai-node/commit/8d77f8e3c4801b7fa1e7c6f50b48c1de1f43f3e6))
+
+
+### Bug Fixes
+
+* **realtime:** call .toString() on WebSocket url ([#1324](https://github.com/openai/openai-node/issues/1324)) ([09bc50d](https://github.com/openai/openai-node/commit/09bc50d439679b6acfd2441e69ee5aa18c00e5d9))
+
+## 4.84.1 (2025-02-13)
+
+Full Changelog: [v4.84.0...v4.84.1](https://github.com/openai/openai-node/compare/v4.84.0...v4.84.1)
+
+### Bug Fixes
+
+* **realtime:** correct websocket type var constraint ([#1321](https://github.com/openai/openai-node/issues/1321)) ([afb17ea](https://github.com/openai/openai-node/commit/afb17ea6497b860ebbe5d8e68e4a97681dd307ff))
+
+## 4.84.0 (2025-02-12)
+
+Full Changelog: [v4.83.0...v4.84.0](https://github.com/openai/openai-node/compare/v4.83.0...v4.84.0)
+
+### Features
+
+* **pagination:** avoid fetching when has_more: false ([#1305](https://github.com/openai/openai-node/issues/1305)) ([b6944c6](https://github.com/openai/openai-node/commit/b6944c634b53c9084f2ccf777c2491e89b2cc7af))
+
+
+### Bug Fixes
+
+* **api:** add missing reasoning effort + model enums ([#1302](https://github.com/openai/openai-node/issues/1302)) ([14c55c3](https://github.com/openai/openai-node/commit/14c55c312e31f1ed46d02f39a99049f785504a53))
+* **assistants:** handle `thread.run.incomplete` event ([7032cc4](https://github.com/openai/openai-node/commit/7032cc40b8aa0a58459cf114bceb8028a8517400))
+* correctly decode multi-byte characters over multiple chunks ([#1316](https://github.com/openai/openai-node/issues/1316)) ([dd776c4](https://github.com/openai/openai-node/commit/dd776c4867401f527f699bd4b9e567890256e849))
+
+
+### Chores
+
+* **internal:** remove segfault-handler dependency ([3521ca3](https://github.com/openai/openai-node/commit/3521ca34e7f5bd51542084e27c084a5d7cc5448b))
+
+
+### Documentation
+
+* **readme:** cleanup into multiple files ([da94424](https://github.com/openai/openai-node/commit/da944242e542e9e5e51cb11853c621fc6825ac02))
+
 ## 4.83.0 (2025-02-05)
 
 Full Changelog: [v4.82.0...v4.83.0](https://github.com/openai/openai-node/compare/v4.82.0...v4.83.0)
diff --git README.md README.md
index a1f4bf760..166e35e22 100644
--- README.md
+++ README.md
@@ -40,7 +40,7 @@ import OpenAI from 'jsr:@openai/openai';
 The full API of this library can be found in [api.md file](api.md) along with many [code examples](https://github.com/openai/openai-node/tree/master/examples). The code below shows how to get started using the chat completions API.
 
 <!-- prettier-ignore -->
-\`\`\`js
+```ts
 import OpenAI from 'openai';
 
 const client = new OpenAI({
@@ -80,189 +80,11 @@ async function main() {
 main();

-If you need to cancel a stream, you can break from the loop
-or call stream.controller.abort().

-## Realtime API beta

-The Realtime API enables you to build low-latency, multi-modal conversational experiences. It currently supports text and audio as both input and output, as well as function calling through a WebSocket connection.

-The Realtime API works through a combination of client-sent events and server-sent events. Clients can send events to do things like update session configuration or send text and audio inputs. Server events confirm when audio responses have completed, or when a text response from the model has been received. A full event reference can be found here and a guide can be found here.

-This SDK supports accessing the Realtime API through the WebSocket API or with ws.

-Basic text based example with ws:

-```ts
-// requires yarn add ws @types/ws
-import { OpenAIRealtimeWS } from 'openai/beta/realtime/ws';

-const rt = new OpenAIRealtimeWS({ model: 'gpt-4o-realtime-preview-2024-12-17' });

-// access the underlying ws.WebSocket instance
-rt.socket.on('open', () => {

  • console.log('Connection opened!');
  • rt.send({
  • type: 'session.update',
  • session: {
  •  modalities: ['text'],
    
  •  model: 'gpt-4o-realtime-preview',
    
  • },
  • });
  • rt.send({
  • type: 'conversation.item.create',
  • item: {
  •  type: 'message',
    
  •  role: 'user',
    
  •  content: [{ type: 'input_text', text: 'Say a couple paragraphs!' }],
    
  • },
  • });
  • rt.send({ type: 'response.create' });
    -});

-rt.on('error', (err) => {

  • // in a real world scenario this should be logged somewhere as you
  • // likely want to continue procesing events regardless of any errors
  • throw err;
    -});

-rt.on('session.created', (event) => {

  • console.log('session created!', event.session);
  • console.log();
    -});

-rt.on('response.text.delta', (event) => process.stdout.write(event.delta));
-rt.on('response.text.done', () => console.log());

-rt.on('response.done', () => rt.close());

-rt.socket.on('close', () => console.log('\nConnection closed!'));
-```

-To use the web API WebSocket implementation, replace OpenAIRealtimeWS with OpenAIRealtimeWebSocket and adjust any rt.socket access:

-```ts
-import { OpenAIRealtimeWebSocket } from 'openai/beta/realtime/websocket';

-const rt = new OpenAIRealtimeWebSocket({ model: 'gpt-4o-realtime-preview-2024-12-17' });
-// ...
-rt.socket.addEventListener('open', () => {

  • // ...
    -});
    -```

-A full example can be found here.

-### Realtime error handling

-When an error is encountered, either on the client side or returned from the server through the error event, the error event listener will be fired. However, if you haven't registered an error event listener then an unhandled Promise rejection error will be thrown.

-It is highly recommended that you register an error event listener and handle errors approriately as typically the underlying connection is still usable.

-```ts
-const rt = new OpenAIRealtimeWS({ model: 'gpt-4o-realtime-preview-2024-12-17' });
-rt.on('error', (err) => {

  • // in a real world scenario this should be logged somewhere as you
  • // likely want to continue procesing events regardless of any errors
  • throw err;
    -});
    -```

-### Request & Response types

-This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:

-
-```ts
-import OpenAI from 'openai';

-const client = new OpenAI({

  • apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
    -});

-async function main() {

  • const params: OpenAI.Chat.ChatCompletionCreateParams = {
  • messages: [{ role: 'user', content: 'Say this is a test' }],
  • model: 'gpt-4o',
  • };
  • const chatCompletion: OpenAI.Chat.ChatCompletion = await client.chat.completions.create(params);
    -}

-main();
-```

-Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.

-> [!IMPORTANT]
-> Previous versions of this SDK used a Configuration class. See the v3 to v4 migration guide.

-### Polling Helpers

-When interacting with the API some actions such as starting a Run and adding files to vector stores are asynchronous and take time to complete. The SDK includes
-helper functions which will poll the status until it reaches a terminal state and then return the resulting object.
-If an API method results in an action which could benefit from polling there will be a corresponding version of the
-method ending in 'AndPoll'.

-For instance to create a Run and poll until it reaches a terminal state you can run:

-```ts
-const run = await openai.beta.threads.runs.createAndPoll(thread.id, {

  • assistant_id: assistantId,
    -});
    -```

-More information on the lifecycle of a Run can be found in the Run Lifecycle Documentation

-### Bulk Upload Helpers

-When creating and interacting with vector stores, you can use the polling helpers to monitor the status of operations.
-For convenience, we also provide a bulk upload helper to allow you to simultaneously upload several files at once.

-```ts
-const fileList = [

  • createReadStream('/home/data/example.pdf'),
  • ...
    -];

-const batch = await openai.vectorStores.fileBatches.uploadAndPoll(vectorStore.id, {files: fileList});
-```

-### Streaming Helpers

-The SDK also includes helpers to process streams and handle the incoming events.

-```ts
-const run = openai.beta.threads.runs

  • .stream(thread.id, {
  • assistant_id: assistant.id,
  • })
  • .on('textCreated', (text) => process.stdout.write('\nassistant > '))
  • .on('textDelta', (textDelta, snapshot) => process.stdout.write(textDelta.value))
  • .on('toolCallCreated', (toolCall) => process.stdout.write(\nassistant > ${toolCall.type}\n\n))
  • .on('toolCallDelta', (toolCallDelta, snapshot) => {
  • if (toolCallDelta.type === 'code_interpreter') {
  •  if (toolCallDelta.code_interpreter.input) {
    
  •    process.stdout.write(toolCallDelta.code_interpreter.input);
    
  •  }
    
  •  if (toolCallDelta.code_interpreter.outputs) {
    
  •    process.stdout.write('\noutput >\n');
    
  •    toolCallDelta.code_interpreter.outputs.forEach((output) => {
    
  •      if (output.type === 'logs') {
    
  •        process.stdout.write(`\n${output.logs}\n`);
    
  •      }
    
  •    });
    
  •  }
    
  • }
  • });
    -```

-More information on streaming helpers can be found in the dedicated documentation: helpers.md
+If you need to cancel a stream, you can break from the loop or call stream.controller.abort().

-### Streaming responses
+### Chat Completion streaming helpers

-This library provides several conveniences for streaming chat completions, for example:
+This library also provides several conveniences for streaming chat completions, for example:

import OpenAI from 'openai';
@@ -292,98 +114,32 @@ async function main() {
main();

-Streaming with openai.beta.chat.completions.stream({…}) exposes
-various helpers for your convenience including event handlers and promises.

-Alternatively, you can use openai.chat.completions.create({ stream: true, … })
-which only returns an async iterable of the chunks in the stream and thus uses less memory
-(it does not build up a final chat completion object for you).

-If you need to cancel a stream, you can break from a for await loop or call stream.abort().

-### Automated function calls
+See helpers.md for more details.

-We provide the openai.beta.chat.completions.runTools({…})
-convenience helper for using function tool calls with the /chat/completions endpoint
-which automatically call the JavaScript functions you provide
-and sends their results back to the /chat/completions endpoint,
-looping as long as the model requests tool calls.

-If you pass a parse function, it will automatically parse the arguments for you
-and returns any parsing errors to the model to attempt auto-recovery.
-Otherwise, the args will be passed to the function you provide as a string.
+### Request & Response types

-If you pass tool_choice: {function: {name: …}} instead of auto,
-it returns immediately after calling that function (and only loops to auto-recover parsing errors).
+This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:

+

import OpenAI from 'openai';

-const client = new OpenAI();
+const client = new OpenAI({
+  apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
+});

async function main() {
-  const runner = client.beta.chat.completions
-    .runTools({
-      model: 'gpt-4o',
-      messages: [{ role: 'user', content: 'How is the weather this week?' }],
-      tools: [
-        {
-          type: 'function',
-          function: {
-            function: getCurrentLocation,
-            parameters: { type: 'object', properties: {} },
-          },
-        },
-        {
-          type: 'function',
-          function: {
-            function: getWeather,
-            parse: JSON.parse, // or use a validation library like zod for typesafe parsing.
-            parameters: {
-              type: 'object',
-              properties: {
-                location: { type: 'string' },
-              },
-            },
-          },
-        },
-      ],
-    })
-    .on('message', (message) => console.log(message));
-
-  const finalContent = await runner.finalContent();
-  console.log();
-  console.log('Final content:', finalContent);
-}
-
-async function getCurrentLocation() {
-  return 'Boston'; // Simulate lookup
-}
-
-async function getWeather(args: { location: string }) {
-  const { location } = args;
-  // … do lookup …
-  return { temperature, precipitation };
+  const params: OpenAI.Chat.ChatCompletionCreateParams = {
+    messages: [{ role: 'user', content: 'Say this is a test' }],
+    model: 'gpt-4o',
+  };
+  const chatCompletion: OpenAI.Chat.ChatCompletion = await client.chat.completions.create(params);
}

main();
-
-// {role: "user",      content: "How's the weather this week?"}
-// {role: "assistant", tool_calls: [{type: "function", function: {name: "getCurrentLocation", arguments: "{}"}, id: "123"}
-// {role: "tool",      name: "getCurrentLocation", content: "Boston", tool_call_id: "123"}
-// {role: "assistant", tool_calls: [{type: "function", function: {name: "getWeather", arguments: '{"location": "Boston"}'}, id: "1234"}]}
-// {role: "tool",      name: "getWeather", content: '{"temperature": "50degF", "preciptation": "high"}', tool_call_id: "1234"}
-// {role: "assistant", content: "It's looking cold and rainy - you might want to wear a jacket!"}
-//
-// Final content: "It's looking cold and rainy - you might want to wear a jacket!"

-Like with .stream(), we provide a variety of helpers and events.

-Note that runFunctions was previously available as well, but has been deprecated in favor of runTools.

-Read more about various examples such as with integrating with zod,
-next.js, and proxying a stream to the browser.
+Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.

File uploads

@@ -434,6 +190,7 @@ async function main() {
.create({ model: 'gpt-4o', training_file: 'file-abc123' })
.catch(async (err) => {
if (err instanceof OpenAI.APIError) {

  •    console.log(err.request_id);
       console.log(err.status); // 400
       console.log(err.name); // BadRequestError
       console.log(err.headers); // {server: 'nginx', ...}
    

@@ -459,76 +216,6 @@ Error codes are as followed:
| >=500 | InternalServerError |
| N/A | APIConnectionError |

-## Request IDs

-> For more information on debugging requests, see these docs

-All object responses in the SDK provide a _request_id property which is added from the x-request-id response header so that you can quickly log failing requests and report them back to OpenAI.

-ts -const completion = await client.chat.completions.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-4o' }); -console.log(completion._request_id) // req_123 -

-You can also access the Request ID using the .withResponse() method:

-```ts
-const { data: stream, request_id } = await openai.chat.completions

  • .create({
  • model: 'gpt-4',
  • messages: [{ role: 'user', content: 'Say this is a test' }],
  • stream: true,
  • })
  • .withResponse();
    -```

-## Microsoft Azure OpenAI

-To use this library with Azure OpenAI, use the AzureOpenAI
-class instead of the OpenAI class.

-> [!IMPORTANT]
-> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params
-> won't always be correct.

-```ts
-import { AzureOpenAI } from 'openai';
-import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';

-const credential = new DefaultAzureCredential();
-const scope = 'https://cognitiveservices.azure.com/.default';
-const azureADTokenProvider = getBearerTokenProvider(credential, scope);

-const openai = new AzureOpenAI({ azureADTokenProvider, apiVersion: "<The API version, e.g. 2024-10-01-preview>" });

-const result = await openai.chat.completions.create({

  • model: 'gpt-4o',
  • messages: [{ role: 'user', content: 'Say hello!' }],
    -});

-console.log(result.choices[0]!.message?.content);
-```

-### Realtime API
-This SDK provides real-time streaming capabilities for Azure OpenAI through the OpenAIRealtimeWS and OpenAIRealtimeWebSocket clients described previously.

-To utilize the real-time features, begin by creating a fully configured AzureOpenAI client and passing it into either OpenAIRealtimeWS.azure or OpenAIRealtimeWebSocket.azure. For example:

-```ts
-const cred = new DefaultAzureCredential();
-const scope = 'https://cognitiveservices.azure.com/.default';
-const deploymentName = 'gpt-4o-realtime-preview-1001';
-const azureADTokenProvider = getBearerTokenProvider(cred, scope);
-const client = new AzureOpenAI({

  • azureADTokenProvider,
  • apiVersion: '2024-10-01-preview',
  • deployment: deploymentName,
    -});
    -const rt = await OpenAIRealtimeWS.azure(client);
    -```

-Once the instance has been created, you can then begin sending requests and receiving streaming responses in real time.

Retries

Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
@@ -571,6 +258,29 @@ On timeout, an APIConnectionTimeoutError is thrown.

Note that requests which time out will be retried twice by default.

+## Request IDs
+
+> For more information on debugging requests, see these docs
+
+All object responses in the SDK provide a _request_id property which is added from the x-request-id response header so that you can quickly log failing requests and report them back to OpenAI.
+
+ts +const completion = await client.chat.completions.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-4o' }); +console.log(completion._request_id) // req_123 +
+
+You can also access the Request ID using the .withResponse() method:
+
+```ts
+const { data: stream, request_id } = await openai.chat.completions

  • .create({
  • model: 'gpt-4',
  • messages: [{ role: 'user', content: 'Say this is a test' }],
  • stream: true,
  • })
  • .withResponse();
    +```

Auto-pagination

List methods in the OpenAI API are paginated.
@@ -602,6 +312,55 @@ while (page.hasNextPage()) {
}


+## Realtime API Beta
+
+The Realtime API enables you to build low-latency, multi-modal conversational experiences. It currently supports text and audio as both input and output, as well as [function calling](https://platform.openai.com/docs/guides/function-calling) through a `WebSocket` connection.
+
+```ts
+import { OpenAIRealtimeWebSocket } from 'openai/beta/realtime/websocket';
+
+const rt = new OpenAIRealtimeWebSocket({ model: 'gpt-4o-realtime-preview-2024-12-17' });
+
+rt.on('response.text.delta', (event) => process.stdout.write(event.delta));
+```
+
+For more information see [realtime.md](realtime.md).
+
+## Microsoft Azure OpenAI
+
+To use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the `AzureOpenAI`
+class instead of the `OpenAI` class.
+
+> [!IMPORTANT]
+> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params
+> won't always be correct.
+
+```ts
+import { AzureOpenAI } from 'openai';
+import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';
+
+const credential = new DefaultAzureCredential();
+const scope = 'https://cognitiveservices.azure.com/.default';
+const azureADTokenProvider = getBearerTokenProvider(credential, scope);
+
+const openai = new AzureOpenAI({ azureADTokenProvider, apiVersion: "<The API version, e.g. 2024-10-01-preview>" });
+
+const result = await openai.chat.completions.create({
+  model: 'gpt-4o',
+  messages: [{ role: 'user', content: 'Say hello!' }],
+});
+
+console.log(result.choices[0]!.message?.content);
+```
+
+For more information on support for the Azure API, see [azure.md](azure.md).
+
+## Automated function calls
+
+We provide the `openai.beta.chat.completions.runTools({…})` convenience helper for using function tool calls with the `/chat/completions` endpoint which automatically call the JavaScript functions you provide and sends their results back to the `/chat/completions` endpoint, looping as long as the model requests tool calls.
+
+For more information see [helpers.md](helpers.md#automated-function-calls).
+
## Advanced Usage

### Accessing raw Response data (e.g., headers)
diff --git api.md api.md
index 01854a8e0..63f239628 100644
--- api.md
+++ api.md
@@ -32,39 +32,51 @@ Types:

Types:

-- <code><a href="./src/resources/chat/completions.ts">ChatCompletion</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionAssistantMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionAudio</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionAudioParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionChunk</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPart</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPartImage</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPartInputAudio</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPartRefusal</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPartText</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionDeveloperMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionFunctionCallOption</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionFunctionMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionMessage</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionMessageToolCall</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionModality</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionNamedToolChoice</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionPredictionContent</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionReasoningEffort</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionRole</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionStreamOptions</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionSystemMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionTokenLogprob</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionTool</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionToolChoiceOption</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionToolMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionUserMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">CreateChatCompletionRequestMessage</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletion</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionAssistantMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionAudio</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionAudioParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionChunk</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPart</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPartImage</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPartInputAudio</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPartRefusal</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPartText</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionDeleted</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionDeveloperMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionFunctionCallOption</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionFunctionMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionMessage</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionMessageToolCall</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionModality</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionNamedToolChoice</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionPredictionContent</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionReasoningEffort</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionRole</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionStoreMessage</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionStreamOptions</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionSystemMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionTokenLogprob</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionTool</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionToolChoiceOption</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionToolMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionUserMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">CreateChatCompletionRequestMessage</a></code>

Methods:

-- <code title="post /chat/completions">client.chat.completions.<a href="./src/resources/chat/completions.ts">create</a>({ ...params }) -> ChatCompletion</code>
+- <code title="post /chat/completions">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">create</a>({ ...params }) -> ChatCompletion</code>
+- <code title="get /chat/completions/{completion_id}">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">retrieve</a>(completionId) -> ChatCompletion</code>
+- <code title="post /chat/completions/{completion_id}">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">update</a>(completionId, { ...params }) -> ChatCompletion</code>
+- <code title="get /chat/completions">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">list</a>({ ...params }) -> ChatCompletionsPage</code>
+- <code title="delete /chat/completions/{completion_id}">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">del</a>(completionId) -> ChatCompletionDeleted</code>
+
+### Messages
+
+Methods:
+
+- <code title="get /chat/completions/{completion_id}/messages">client.chat.completions.messages.<a href="./src/resources/chat/completions/messages.ts">list</a>(completionId, { ...params }) -> ChatCompletionStoreMessagesPage</code>

# Embeddings

diff --git a/azure.md b/azure.md
new file mode 100644
index 000000000..df06c2985
--- /dev/null
+++ azure.md
@@ -0,0 +1,49 @@
+# Microsoft Azure OpenAI
+
+To use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the `AzureOpenAI`
+class instead of the `OpenAI` class.
+
+> [!IMPORTANT]
+> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params
+> won't always be correct.
+
+```ts
+import { AzureOpenAI } from 'openai';
+import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';
+
+const credential = new DefaultAzureCredential();
+const scope = 'https://cognitiveservices.azure.com/.default';
+const azureADTokenProvider = getBearerTokenProvider(credential, scope);
+
+const openai = new AzureOpenAI({ azureADTokenProvider, apiVersion: "<The API version, e.g. 2024-10-01-preview>" });
+
+const result = await openai.chat.completions.create({
+  model: 'gpt-4o',
+  messages: [{ role: 'user', content: 'Say hello!' }],
+});
+
+console.log(result.choices[0]!.message?.content);
+```
+
+For more information on support for the Azure API, see [azure.md](azure.md).
+
+## Realtime API
+
+This SDK provides real-time streaming capabilities for Azure OpenAI through the `OpenAIRealtimeWS` and `OpenAIRealtimeWebSocket` clients described previously.
+
+To utilize the real-time features, begin by creating a fully configured `AzureOpenAI` client and passing it into either `OpenAIRealtimeWS.azure` or `OpenAIRealtimeWebSocket.azure`. For example:
+
+```ts
+const cred = new DefaultAzureCredential();
+const scope = 'https://cognitiveservices.azure.com/.default';
+const deploymentName = 'gpt-4o-realtime-preview-1001';
+const azureADTokenProvider = getBearerTokenProvider(cred, scope);
+const client = new AzureOpenAI({
+  azureADTokenProvider,
+  apiVersion: '2024-10-01-preview',
+  deployment: deploymentName,
+});
+const rt = await OpenAIRealtimeWS.azure(client);
+```
+
+Once the instance has been created, you can then begin sending requests and receiving streaming responses in real time.
diff --git ecosystem-tests/cli.ts ecosystem-tests/cli.ts
index 00120e5f9..77faddec5 100644
--- ecosystem-tests/cli.ts
+++ ecosystem-tests/cli.ts
@@ -4,10 +4,6 @@ import yargs from 'yargs';
import assert from 'assert';
import path from 'path';

-// @ts-ignore
-var SegfaultHandler = require('segfault-handler');
-SegfaultHandler.registerHandler('crash.log');
-
const TAR_NAME = 'openai.tgz';
const PACK_FOLDER = '.pack';
const PACK_FILE = `${PACK_FOLDER}/${TAR_NAME}`;
@@ -74,6 +70,7 @@ const projectRunners = {
  'cloudflare-worker': async () => {
    await installPackage();

+    await fs.writeFile('.dev.vars', `OPENAI_API_KEY='${process.env['OPENAI_API_KEY']}'`);
    await run('npm', ['run', 'tsc']);

    if (state.live) {
diff --git helpers.md helpers.md
index 16bc1f277..41b352e5e 100644
--- helpers.md
+++ helpers.md
@@ -142,9 +142,7 @@ More information can be found in the documentation: [Assistant Streaming](https:

```ts
const run = openai.beta.threads.runs
-  .stream(thread.id, {
-    assistant_id: assistant.id,
-  })
+  .stream(thread.id, { assistant_id: assistant.id })
  .on('textCreated', (text) => process.stdout.write('\nassistant > '))
  .on('textDelta', (textDelta, snapshot) => process.stdout.write(textDelta.value))
  .on('toolCallCreated', (toolCall) => process.stdout.write(`\nassistant > ${toolCall.type}\n\n`))
@@ -304,47 +302,87 @@ If you need to cancel a stream, you can `break` from a `for await` loop or call

See an example of streaming helpers in action in [`examples/stream.ts`](examples/stream.ts).

-### Automated Function Calls
+### Automated function calls

-```ts
-openai.chat.completions.runTools({ stream: false, … }, options?): ChatCompletionRunner
-openai.chat.completions.runTools({ stream: true, … }, options?): ChatCompletionStreamingRunner
-```
+We provide the `openai.beta.chat.completions.runTools({…})`
+convenience helper for using function tool calls with the `/chat/completions` endpoint
+which automatically call the JavaScript functions you provide
+and sends their results back to the `/chat/completions` endpoint,
+looping as long as the model requests tool calls.

-`openai.chat.completions.runTools()` returns a Runner
-for automating function calls with chat completions.
-The runner automatically calls the JavaScript functions you provide and sends their results back
-to the API, looping as long as the model requests function calls.
+If you pass a `parse` function, it will automatically parse the `arguments` for you
+and returns any parsing errors to the model to attempt auto-recovery.
+Otherwise, the args will be passed to the function you provide as a string.

-If you pass a `parse` function, it will automatically parse the `arguments` for you and returns any parsing
-errors to the model to attempt auto-recovery. Otherwise, the args will be passed to the function you provide
-as a string.
+If you pass `tool_choice: {function: {name: …}}` instead of `auto`,
+it returns immediately after calling that function (and only loops to auto-recover parsing errors).

```ts
-client.chat.completions.runTools({
-  model: 'gpt-3.5-turbo',
-  messages: [{ role: 'user', content: 'How is the weather this week?' }],
-  tools: [
-    {
-      type: 'function',
-      function: {
-        function: getWeather as (args: { location: string; time: Date }) => any,
-        parse: parseFunction as (args: strings) => { location: string; time: Date },
-        parameters: {
-          type: 'object',
-          properties: {
-            location: { type: 'string' },
-            time: { type: 'string', format: 'date-time' },
+import OpenAI from 'openai';
+
+const client = new OpenAI();
+
+async function main() {
+  const runner = client.beta.chat.completions
+    .runTools({
+      model: 'gpt-4o',
+      messages: [{ role: 'user', content: 'How is the weather this week?' }],
+      tools: [
+        {
+          type: 'function',
+          function: {
+            function: getCurrentLocation,
+            parameters: { type: 'object', properties: {} },
          },
        },
-      },
-    },
-  ],
-});
+        {
+          type: 'function',
+          function: {
+            function: getWeather,
+            parse: JSON.parse, // or use a validation library like zod for typesafe parsing.
+            parameters: {
+              type: 'object',
+              properties: {
+                location: { type: 'string' },
+              },
+            },
+          },
+        },
+      ],
+    })
+    .on('message', (message) => console.log(message));
+
+  const finalContent = await runner.finalContent();
+  console.log();
+  console.log('Final content:', finalContent);
+}
+
+async function getCurrentLocation() {
+  return 'Boston'; // Simulate lookup
+}
+
+async function getWeather(args: { location: string }) {
+  const { location } = args;
+  // … do lookup …
+  return { temperature, precipitation };
+}
+
+main();
+
+// {role: "user",      content: "How's the weather this week?"}
+// {role: "assistant", tool_calls: [{type: "function", function: {name: "getCurrentLocation", arguments: "{}"}, id: "123"}
+// {role: "tool",      name: "getCurrentLocation", content: "Boston", tool_call_id: "123"}
+// {role: "assistant", tool_calls: [{type: "function", function: {name: "getWeather", arguments: '{"location": "Boston"}'}, id: "1234"}]}
+// {role: "tool",      name: "getWeather", content: '{"temperature": "50degF", "preciptation": "high"}', tool_call_id: "1234"}
+// {role: "assistant", content: "It's looking cold and rainy - you might want to wear a jacket!"}
+//
+// Final content: "It's looking cold and rainy - you might want to wear a jacket!"

-If you pass function_call: {name: …} instead of auto, it returns immediately after calling that
-function (and only loops to auto-recover parsing errors).
+Like with .stream(), we provide a variety of helpers and events.
+
+Read more about various examples such as with integrating with zod,
+next.js, and proxying a stream to the browser.

By default, we run the loop up to 10 chat completions from the API. You can change this behavior by
adjusting maxChatCompletions in the request options object. Note that max_tokens is the limit per
@@ -662,3 +700,17 @@ client.beta.vectorStores.files.createAndPoll((...)
client.beta.vectorStores.fileBatches.createAndPoll((...)
client.beta.vectorStores.fileBatches.uploadAndPoll((...)

+
+# Bulk Upload Helpers
+
+When creating and interacting with vector stores, you can use the polling helpers to monitor the status of operations.
+For convenience, we also provide a bulk upload helper to allow you to simultaneously upload several files at once.
+
+```ts
+const fileList = [
+  createReadStream('/home/data/example.pdf'),
+  ...
+];
+
+const batch = await openai.vectorStores.fileBatches.uploadAndPoll(vectorStore.id, {files: fileList});
+```
diff --git jsr.json jsr.json
index 6fa05e624..8f83c0ff2 100644
--- jsr.json
+++ jsr.json
@@ -1,6 +1,6 @@
{
  "name": "@openai/openai",
-  "version": "4.83.0",
+  "version": "4.85.2",
  "exports": {
    ".": "./index.ts",
    "./helpers/zod": "./helpers/zod.ts",
diff --git package.json package.json
index bd507e9f8..661bc2938 100644
--- package.json
+++ package.json
@@ -1,6 +1,6 @@
{
  "name": "openai",
-  "version": "4.83.0",
+  "version": "4.85.2",
  "description": "The official TypeScript library for the OpenAI API",
  "author": "OpenAI <[email protected]>",
  "types": "dist/index.d.ts",
@@ -47,7 +47,6 @@
    "jest": "^29.4.0",
    "prettier": "^3.0.0",
    "prettier-2": "npm:prettier@^2",
-    "segfault-handler": "^1.3.0",
    "ts-jest": "^29.1.0",
    "ts-node": "^10.5.0",
    "tsc-multi": "^1.1.0",
@@ -113,17 +112,38 @@
      "default": "./dist/index.mjs"
    },
    "./*.mjs": {
-      "types": "./dist/*.d.ts",
-      "default": "./dist/*.mjs"
+      "types": [
+        "./dist/*.d.ts",
+        "./dist/*/index.d.ts"
+      ],
+      "default": [
+        "./dist/*.mjs",
+        "./dist/*/index.mjs"
+      ]
    },
    "./*.js": {
-      "types": "./dist/*.d.ts",
-      "default": "./dist/*.js"
+      "types": [
+        "./dist/*.d.ts",
+        "./dist/*/index.d.ts"
+      ],
+      "default": [
+        "./dist/*.js",
+        "./dist/*/index.js"
+      ]
    },
    "./*": {
-      "types": "./dist/*.d.ts",
-      "require": "./dist/*.js",
-      "default": "./dist/*.mjs"
+      "types": [
+        "./dist/*.d.ts",
+        "./dist/*/index.d.ts"
+      ],
+      "require": [
+        "./dist/*.js",
+        "./dist/*/index.js"
+      ],
+      "default": [
+        "./dist/*.mjs",
+        "./dist/*/index.mjs"
+      ]
    }
  },
  "bin": "./bin/cli",
diff --git a/realtime.md b/realtime.md
new file mode 100644
index 000000000..2fcd17e9e
--- /dev/null
+++ realtime.md
@@ -0,0 +1,87 @@
+## Realtime API beta
+
+The Realtime API enables you to build low-latency, multi-modal conversational experiences. It currently supports text and audio as both input and output, as well as [function calling](https://platform.openai.com/docs/guides/function-calling) through a `WebSocket` connection.
+
+The Realtime API works through a combination of client-sent events and server-sent events. Clients can send events to do things like update session configuration or send text and audio inputs. Server events confirm when audio responses have completed, or when a text response from the model has been received. A full event reference can be found [here](https://platform.openai.com/docs/api-reference/realtime-client-events) and a guide can be found [here](https://platform.openai.com/docs/guides/realtime).
+
+This SDK supports accessing the Realtime API through the [WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) or with [ws](https://github.com/websockets/ws).
+
+Basic text based example with `ws`:
+
+```ts
+// requires `yarn add ws @types/ws`
+import { OpenAIRealtimeWS } from 'openai/beta/realtime/ws';
+
+const rt = new OpenAIRealtimeWS({ model: 'gpt-4o-realtime-preview-2024-12-17' });
+
+// access the underlying `ws.WebSocket` instance
+rt.socket.on('open', () => {
+  console.log('Connection opened!');
+  rt.send({
+    type: 'session.update',
+    session: {
+      modalities: ['text'],
+      model: 'gpt-4o-realtime-preview',
+    },
+  });
+
+  rt.send({
+    type: 'conversation.item.create',
+    item: {
+      type: 'message',
+      role: 'user',
+      content: [{ type: 'input_text', text: 'Say a couple paragraphs!' }],
+    },
+  });
+
+  rt.send({ type: 'response.create' });
+});
+
+rt.on('error', (err) => {
+  // in a real world scenario this should be logged somewhere as you
+  // likely want to continue procesing events regardless of any errors
+  throw err;
+});
+
+rt.on('session.created', (event) => {
+  console.log('session created!', event.session);
+  console.log();
+});
+
+rt.on('response.text.delta', (event) => process.stdout.write(event.delta));
+rt.on('response.text.done', () => console.log());
+
+rt.on('response.done', () => rt.close());
+
+rt.socket.on('close', () => console.log('\nConnection closed!'));
+```
+
+To use the web API `WebSocket` implementation, replace `OpenAIRealtimeWS` with `OpenAIRealtimeWebSocket` and adjust any `rt.socket` access:
+
+```ts
+import { OpenAIRealtimeWebSocket } from 'openai/beta/realtime/websocket';
+
+const rt = new OpenAIRealtimeWebSocket({ model: 'gpt-4o-realtime-preview-2024-12-17' });
+// ...
+rt.socket.addEventListener('open', () => {
+ // ...
+});
+```
+
+A full example can be found [here](https://github.com/openai/openai-node/blob/master/examples/realtime/websocket.ts).
+
+### Realtime error handling
+
+When an error is encountered, either on the client side or returned from the server through the [`error` event](https://platform.openai.com/docs/guides/realtime-model-capabilities#error-handling), the `error` event listener will be fired. However, if you haven't registered an `error` event listener then an `unhandled Promise rejection` error will be thrown.
+
+It is **highly recommended** that you register an `error` event listener and handle errors approriately as typically the underlying connection is still usable.
+
+```ts
+const rt = new OpenAIRealtimeWS({ model: 'gpt-4o-realtime-preview-2024-12-17' });
+rt.on('error', (err) => {
+  // in a real world scenario this should be logged somewhere as you
+  // likely want to continue procesing events regardless of any errors
+  throw err;
+});
+```
+
diff --git src/beta/realtime/websocket.ts src/beta/realtime/websocket.ts
index 349cf5760..e8900e809 100644
--- src/beta/realtime/websocket.ts
+++ src/beta/realtime/websocket.ts
@@ -11,7 +11,7 @@ interface MessageEvent {
type _WebSocket =
  typeof globalThis extends (
    {
-      WebSocket: infer ws;
+      WebSocket: infer ws extends abstract new (...args: any) => any;
    }
  ) ?
    // @ts-ignore
@@ -53,7 +53,7 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
    props.onURL?.(this.url);

    // @ts-ignore
-    this.socket = new WebSocket(this.url, [
+    this.socket = new WebSocket(this.url.toString(), [
      'realtime',
      ...(isAzure(client) ? [] : [`openai-insecure-api-key.${client.apiKey}`]),
      'openai-beta.realtime-v1',
@@ -95,7 +95,7 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
  }

  static async azure(
-    client: AzureOpenAI,
+    client: Pick<AzureOpenAI, '_getAzureADToken' | 'apiVersion' | 'apiKey' | 'baseURL' | 'deploymentName'>,
    options: { deploymentName?: string; dangerouslyAllowBrowser?: boolean } = {},
  ): Promise<OpenAIRealtimeWebSocket> {
    const token = await client._getAzureADToken();
diff --git src/beta/realtime/ws.ts src/beta/realtime/ws.ts
index 51339089c..3f51dfc4b 100644
--- src/beta/realtime/ws.ts
+++ src/beta/realtime/ws.ts
@@ -52,7 +52,7 @@ export class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {
  }

  static async azure(
-    client: AzureOpenAI,
+    client: Pick<AzureOpenAI, '_getAzureADToken' | 'apiVersion' | 'apiKey' | 'baseURL' | 'deploymentName'>,
    options: { deploymentName?: string; options?: WS.ClientOptions | undefined } = {},
  ): Promise<OpenAIRealtimeWS> {
    const deploymentName = options.deploymentName ?? client.deploymentName;
@@ -82,7 +82,7 @@ export class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {
  }
}

-async function getAzureHeaders(client: AzureOpenAI) {
+async function getAzureHeaders(client: Pick<AzureOpenAI, '_getAzureADToken' | 'apiKey'>) {
  if (client.apiKey !== '<Missing Key>') {
    return { 'api-key': client.apiKey };
  } else {
diff --git src/index.ts src/index.ts
index f4e940af8..debefce8c 100644
--- src/index.ts
+++ src/index.ts
@@ -66,6 +66,13 @@ import {
import { Audio, AudioModel, AudioResponseFormat } from './resources/audio/audio';
import { Beta } from './resources/beta/beta';
import { Chat, ChatModel } from './resources/chat/chat';
+import { FineTuning } from './resources/fine-tuning/fine-tuning';
+import {
+  Upload,
+  UploadCompleteParams,
+  UploadCreateParams,
+  Uploads as UploadsAPIUploads,
+} from './resources/uploads/uploads';
import {
  ChatCompletion,
  ChatCompletionAssistantMessageParam,
@@ -80,9 +87,11 @@ import {
  ChatCompletionCreateParams,
  ChatCompletionCreateParamsNonStreaming,
  ChatCompletionCreateParamsStreaming,
+  ChatCompletionDeleted,
  ChatCompletionDeveloperMessageParam,
  ChatCompletionFunctionCallOption,
  ChatCompletionFunctionMessageParam,
+  ChatCompletionListParams,
  ChatCompletionMessage,
  ChatCompletionMessageParam,
  ChatCompletionMessageToolCall,
@@ -91,21 +100,17 @@ import {
  ChatCompletionPredictionContent,
  ChatCompletionReasoningEffort,
  ChatCompletionRole,
+  ChatCompletionStoreMessage,
  ChatCompletionStreamOptions,
  ChatCompletionSystemMessageParam,
  ChatCompletionTokenLogprob,
  ChatCompletionTool,
  ChatCompletionToolChoiceOption,
  ChatCompletionToolMessageParam,
+  ChatCompletionUpdateParams,
  ChatCompletionUserMessageParam,
-} from './resources/chat/completions';
-import { FineTuning } from './resources/fine-tuning/fine-tuning';
-import {
-  Upload,
-  UploadCompleteParams,
-  UploadCreateParams,
-  Uploads as UploadsAPIUploads,
-} from './resources/uploads/uploads';
+  ChatCompletionsPage,
+} from './resources/chat/completions/completions';

export interface ClientOptions {
  /**
@@ -310,6 +315,7 @@ export class OpenAI extends Core.APIClient {

OpenAI.Completions = Completions;
OpenAI.Chat = Chat;
+OpenAI.ChatCompletionsPage = ChatCompletionsPage;
OpenAI.Embeddings = Embeddings;
OpenAI.Files = Files;
OpenAI.FileObjectsPage = FileObjectsPage;
@@ -355,6 +361,7 @@ export declare namespace OpenAI {
    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,
    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,
    type ChatCompletionContentPartText as ChatCompletionContentPartText,
+    type ChatCompletionDeleted as ChatCompletionDeleted,
    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,
    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
@@ -366,6 +373,7 @@ export declare namespace OpenAI {
    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,
    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,
    type ChatCompletionRole as ChatCompletionRole,
+    type ChatCompletionStoreMessage as ChatCompletionStoreMessage,
    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,
    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
@@ -373,9 +381,12 @@ export declare namespace OpenAI {
    type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,
    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
+    ChatCompletionsPage as ChatCompletionsPage,
    type ChatCompletionCreateParams as ChatCompletionCreateParams,
    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,
    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,
+    type ChatCompletionUpdateParams as ChatCompletionUpdateParams,
+    type ChatCompletionListParams as ChatCompletionListParams,
  };

  export {
diff --git src/internal/decoders/line.ts src/internal/decoders/line.ts
index 34e41d1dc..947f240b3 100644
--- src/internal/decoders/line.ts
+++ src/internal/decoders/line.ts
@@ -13,52 +13,58 @@ export class LineDecoder {
  static NEWLINE_CHARS = new Set(['\n', '\r']);
  static NEWLINE_REGEXP = /\r\n|[\n\r]/g;

-  buffer: string[];
-  trailingCR: boolean;
+  buffer: Uint8Array;
+  #carriageReturnIndex: number | null;
  textDecoder: any; // TextDecoder found in browsers; not typed to avoid pulling in either "dom" or "node" types.

  constructor() {
-    this.buffer = [];
-    this.trailingCR = false;
+    this.buffer = new Uint8Array();
+    this.#carriageReturnIndex = null;
  }

  decode(chunk: Bytes): string[] {
-    let text = this.decodeText(chunk);
-
-    if (this.trailingCR) {
-      text = '\r' + text;
-      this.trailingCR = false;
-    }
-    if (text.endsWith('\r')) {
-      this.trailingCR = true;
-      text = text.slice(0, -1);
-    }
-
-    if (!text) {
+    if (chunk == null) {
      return [];
    }

-    const trailingNewline = LineDecoder.NEWLINE_CHARS.has(text[text.length - 1] || '');
-    let lines = text.split(LineDecoder.NEWLINE_REGEXP);
+    const binaryChunk =
+      chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
+      : typeof chunk === 'string' ? new TextEncoder().encode(chunk)
+      : chunk;
+
+    let newData = new Uint8Array(this.buffer.length + binaryChunk.length);
+    newData.set(this.buffer);
+    newData.set(binaryChunk, this.buffer.length);
+    this.buffer = newData;
+
+    const lines: string[] = [];
+    let patternIndex;
+    while ((patternIndex = findNewlineIndex(this.buffer, this.#carriageReturnIndex)) != null) {
+      if (patternIndex.carriage && this.#carriageReturnIndex == null) {
+        // skip until we either get a corresponding `\n`, a new `\r` or nothing
+        this.#carriageReturnIndex = patternIndex.index;
+        continue;
+      }

-    // if there is a trailing new line then the last entry will be an empty
-    // string which we don't care about
-    if (trailingNewline) {
-      lines.pop();
-    }
+      // we got double \r or \rtext\n
+      if (
+        this.#carriageReturnIndex != null &&
+        (patternIndex.index !== this.#carriageReturnIndex + 1 || patternIndex.carriage)
+      ) {
+        lines.push(this.decodeText(this.buffer.slice(0, this.#carriageReturnIndex - 1)));
+        this.buffer = this.buffer.slice(this.#carriageReturnIndex);
+        this.#carriageReturnIndex = null;
+        continue;
+      }

-    if (lines.length === 1 && !trailingNewline) {
-      this.buffer.push(lines[0]!);
-      return [];
-    }
+      const endIndex =
+        this.#carriageReturnIndex !== null ? patternIndex.preceding - 1 : patternIndex.preceding;

-    if (this.buffer.length > 0) {
-      lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
-      this.buffer = [];
-    }
+      const line = this.decodeText(this.buffer.slice(0, endIndex));
+      lines.push(line);

-    if (!trailingNewline) {
-      this.buffer = [lines.pop() || ''];
+      this.buffer = this.buffer.slice(patternIndex.index);
+      this.#carriageReturnIndex = null;
    }

    return lines;
@@ -102,13 +108,69 @@ export class LineDecoder {
  }

  flush(): string[] {
-    if (!this.buffer.length && !this.trailingCR) {
+    if (!this.buffer.length) {
      return [];
    }
+    return this.decode('\n');
+  }
+}

-    const lines = [this.buffer.join('')];
-    this.buffer = [];
-    this.trailingCR = false;
-    return lines;
+/**
+ * This function searches the buffer for the end patterns, (\r or \n)
+ * and returns an object with the index preceding the matched newline and the
+ * index after the newline char. `null` is returned if no new line is found.
+ *
+ * ```ts
+ * findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 }
+ * ```
+ */
+function findNewlineIndex(
+  buffer: Uint8Array,
+  startIndex: number | null,
+): { preceding: number; index: number; carriage: boolean } | null {
+  const newline = 0x0a; // \n
+  const carriage = 0x0d; // \r
+
+  for (let i = startIndex ?? 0; i < buffer.length; i++) {
+    if (buffer[i] === newline) {
+      return { preceding: i, index: i + 1, carriage: false };
+    }
+
+    if (buffer[i] === carriage) {
+      return { preceding: i, index: i + 1, carriage: true };
+    }
  }
+
+  return null;
+}
+
+export function findDoubleNewlineIndex(buffer: Uint8Array): number {
+  // This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
+  // and returns the index right after the first occurrence of any pattern,
+  // or -1 if none of the patterns are found.
+  const newline = 0x0a; // \n
+  const carriage = 0x0d; // \r
+
+  for (let i = 0; i < buffer.length - 1; i++) {
+    if (buffer[i] === newline && buffer[i + 1] === newline) {
+      // \n\n
+      return i + 2;
+    }
+    if (buffer[i] === carriage && buffer[i + 1] === carriage) {
+      // \r\r
+      return i + 2;
+    }
+    if (
+      buffer[i] === carriage &&
+      buffer[i + 1] === newline &&
+      i + 3 < buffer.length &&
+      buffer[i + 2] === carriage &&
+      buffer[i + 3] === newline
+    ) {
+      // \r\n\r\n
+      return i + 4;
+    }
+  }
+
+  return -1;
}
diff --git src/lib/AssistantStream.ts src/lib/AssistantStream.ts
index caf68e7dd..9b6cc20c5 100644
--- src/lib/AssistantStream.ts
+++ src/lib/AssistantStream.ts
@@ -370,6 +370,7 @@ export class AssistantStream
      case 'thread.run.in_progress':
      case 'thread.run.requires_action':
      case 'thread.run.completed':
+      case 'thread.run.incomplete':
      case 'thread.run.failed':
      case 'thread.run.cancelling':
      case 'thread.run.cancelled':
@@ -400,6 +401,8 @@ export class AssistantStream
        throw new Error(
          'Encountered an error event in event processing - errors should be processed earlier',
        );
+      default:
+        assertNever(event);
    }
  }

@@ -772,3 +775,5 @@ export class AssistantStream
    return await this._createToolAssistantStream(runs, threadId, runId, params, options);
  }
}
+
+function assertNever(_x: never) {}
diff --git src/lib/ChatCompletionStream.ts src/lib/ChatCompletionStream.ts
index 6c846f70b..35648c27b 100644
--- src/lib/ChatCompletionStream.ts
+++ src/lib/ChatCompletionStream.ts
@@ -13,7 +13,7 @@ import {
  type ChatCompletionCreateParamsStreaming,
  type ChatCompletionCreateParamsBase,
  type ChatCompletionRole,
-} from '../resources/chat/completions';
+} from '../resources/chat/completions/completions';
import {
  AbstractChatCompletionRunner,
  type AbstractChatCompletionRunnerEvents,
diff --git src/pagination.ts src/pagination.ts
index 63644e333..7a513fc44 100644
--- src/pagination.ts
+++ src/pagination.ts
@@ -43,6 +43,8 @@ export class Page<Item> extends AbstractPage<Item> implements PageResponse<Item>

export interface CursorPageResponse<Item> {
  data: Array<Item>;
+
+  has_more: boolean;
}

export interface CursorPageParams {
@@ -57,6 +59,8 @@ export class CursorPage<Item extends { id: string }>
{
  data: Array<Item>;

+  has_more: boolean;
+
  constructor(
    client: APIClient,
    response: Response,
@@ -66,12 +70,21 @@ export class CursorPage<Item extends { id: string }>
    super(client, response, body, options);

    this.data = body.data || [];
+    this.has_more = body.has_more || false;
  }

  getPaginatedItems(): Item[] {
    return this.data ?? [];
  }

+  override hasNextPage(): boolean {
+    if (this.has_more === false) {
+      return false;
+    }
+
+    return super.hasNextPage();
+  }
+
  // @deprecated Please use `nextPageInfo()` instead
  nextPageParams(): Partial<CursorPageParams> | null {
    const info = this.nextPageInfo();
diff --git src/resources/beta/assistants.ts src/resources/beta/assistants.ts
index 69a5db520..0cc63d691 100644
--- src/resources/beta/assistants.ts
+++ src/resources/beta/assistants.ts
@@ -1133,6 +1133,16 @@ export interface AssistantCreateParams {
   */
  name?: string | null;

+  /**
+   * **o1 and o3-mini models only**
+   *
+   * Constrains effort on reasoning for
+   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+   * result in faster responses and fewer tokens used on reasoning in a response.
+   */
+  reasoning_effort?: 'low' | 'medium' | 'high' | null;
+
  /**
   * Specifies the format that the model must output. Compatible with
   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
@@ -1288,13 +1298,52 @@ export interface AssistantUpdateParams {
   * [Model overview](https://platform.openai.com/docs/models) for descriptions of
   * them.
   */
-  model?: string;
+  model?:
+    | (string & {})
+    | 'o3-mini'
+    | 'o3-mini-2025-01-31'
+    | 'o1'
+    | 'o1-2024-12-17'
+    | 'gpt-4o'
+    | 'gpt-4o-2024-11-20'
+    | 'gpt-4o-2024-08-06'
+    | 'gpt-4o-2024-05-13'
+    | 'gpt-4o-mini'
+    | 'gpt-4o-mini-2024-07-18'
+    | 'gpt-4-turbo'
+    | 'gpt-4-turbo-2024-04-09'
+    | 'gpt-4-0125-preview'
+    | 'gpt-4-turbo-preview'
+    | 'gpt-4-1106-preview'
+    | 'gpt-4-vision-preview'
+    | 'gpt-4'
+    | 'gpt-4-0314'
+    | 'gpt-4-0613'
+    | 'gpt-4-32k'
+    | 'gpt-4-32k-0314'
+    | 'gpt-4-32k-0613'
+    | 'gpt-3.5-turbo'
+    | 'gpt-3.5-turbo-16k'
+    | 'gpt-3.5-turbo-0613'
+    | 'gpt-3.5-turbo-1106'
+    | 'gpt-3.5-turbo-0125'
+    | 'gpt-3.5-turbo-16k-0613';

  /**
   * The name of the assistant. The maximum length is 256 characters.
   */
  name?: string | null;

+  /**
+   * **o1 and o3-mini models only**
+   *
+   * Constrains effort on reasoning for
+   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+   * result in faster responses and fewer tokens used on reasoning in a response.
+   */
+  reasoning_effort?: 'low' | 'medium' | 'high' | null;
+
  /**
   * Specifies the format that the model must output. Compatible with
   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
diff --git src/resources/beta/threads/runs/runs.ts src/resources/beta/threads/runs/runs.ts
index 84ba7b63c..8ab94cc99 100644
--- src/resources/beta/threads/runs/runs.ts
+++ src/resources/beta/threads/runs/runs.ts
@@ -731,6 +731,16 @@ export interface RunCreateParamsBase {
   */
  parallel_tool_calls?: boolean;

+  /**
+   * Body param: **o1 and o3-mini models only**
+   *
+   * Constrains effort on reasoning for
+   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+   * result in faster responses and fewer tokens used on reasoning in a response.
+   */
+  reasoning_effort?: 'low' | 'medium' | 'high' | null;
+
  /**
   * Body param: Specifies the format that the model must output. Compatible with
   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
diff --git src/resources/chat/chat.ts src/resources/chat/chat.ts
index d4a18929c..5bceec45a 100644
--- src/resources/chat/chat.ts
+++ src/resources/chat/chat.ts
@@ -1,7 +1,7 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../resource';
-import * as CompletionsAPI from './completions';
+import * as CompletionsAPI from './completions/completions';
import {
  ChatCompletion,
  ChatCompletionAssistantMessageParam,
@@ -16,9 +16,11 @@ import {
  ChatCompletionCreateParams,
  ChatCompletionCreateParamsNonStreaming,
  ChatCompletionCreateParamsStreaming,
+  ChatCompletionDeleted,
  ChatCompletionDeveloperMessageParam,
  ChatCompletionFunctionCallOption,
  ChatCompletionFunctionMessageParam,
+  ChatCompletionListParams,
  ChatCompletionMessage,
  ChatCompletionMessageParam,
  ChatCompletionMessageToolCall,
@@ -27,19 +29,24 @@ import {
  ChatCompletionPredictionContent,
  Cha,tCompletionReasoningEffort,
  ChatCompletionRole,
+  ChatCompletionStoreMessage,
  ChatCompletionStreamOptions,
  ChatCompletionSystemMessageParam,
  ChatCompletionTokenLogprob,
  ChatCompletionTool,
  ChatCompletionToolChoiceOption,
  ChatCompletionToolMessageParam,
+  ChatCompletionUpdateParams,
  ChatCompletionUserMessageParam,
+  ChatCompletionsPage,
  CompletionCreateParams,
  CompletionCreateParamsNonStreaming,
  CompletionCreateParamsStreaming,
+  CompletionListParams,
+  CompletionUpdateParams,
  Completions,
  CreateChatCompletionRequestMessage,
-} from './completions';
+} from './completions/completions';

export class Chat extends APIResource {
  completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this._client);
@@ -87,6 +94,7 @@ export type ChatModel =
  | 'gpt-3.5-turbo-16k-0613';

Chat.Completions = Completions;
+Chat.ChatCompletionsPage = ChatCompletionsPage;

export declare namespace Chat {
  export { type ChatModel as ChatModel };
@@ -103,6 +111,7 @@ export declare namespace Chat {
    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,
    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,
    type ChatCompletionContentPartText as ChatCompletionContentPartText,
+    type ChatCompletionDeleted as ChatCompletionDeleted,
    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,
    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
@@ -114,6 +123,7 @@ export declare namespace Chat {
    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,
    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,
    type ChatCompletionRole as ChatCompletionRole,
+    type ChatCompletionStoreMessage as ChatCompletionStoreMessage,
    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,
    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
@@ -122,11 +132,16 @@ export declare namespace Chat {
    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
    type CreateChatCompletionRequestMessage as CreateChatCompletionRequestMessage,
+    ChatCompletionsPage as ChatCompletionsPage,
    type ChatCompletionCreateParams as ChatCompletionCreateParams,
    type CompletionCreateParams as CompletionCreateParams,
    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,
    type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,
    type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
+    type ChatCompletionUpdateParams as ChatCompletionUpdateParams,
+    type CompletionUpdateParams as CompletionUpdateParams,
+    type ChatCompletionListParams as ChatCompletionListParams,
+    type CompletionListParams as CompletionListParams,
  };
}
diff --git src/resources/chat/completions.ts src/resources/chat/completions.ts
index 55b008cf0..55b151e8b 100644
--- src/resources/chat/completions.ts
+++ src/resources/chat/completions.ts
@@ -1,1313 +1 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-import { APIResource } from '../../resource';
-import { APIPromise } from '../../core';
-import * as Core from '../../core';
-import * as ChatCompletionsAPI from './completions';
-import * as CompletionsAPI from '../completions';
-import * as Shared from '../shared';
-import * as ChatAPI from './chat';
-import { Stream } from '../../streaming';
-
-export class Completions extends APIResource {
-  /**
-   * Creates a model response for the given chat conversation. Learn more in the
-   * [text generation](https://platform.openai.com/docs/guides/text-generation),
-   * [vision](https://platform.openai.com/docs/guides/vision), and
-   * [audio](https://platform.openai.com/docs/guides/audio) guides.
-   *
-   * Parameter support can differ depending on the model used to generate the
-   * response, particularly for newer reasoning models. Parameters that are only
-   * supported for reasoning models are noted below. For the current state of
-   * unsupported parameters in reasoning models,
-   * [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).
-   */
-  create(
-    body: ChatCompletionCreateParamsNonStreaming,
-    options?: Core.RequestOptions,
-  ): APIPromise<ChatCompletion>;
-  create(
-    body: ChatCompletionCreateParamsStreaming,
-    options?: Core.RequestOptions,
-  ): APIPromise<Stream<ChatCompletionChunk>>;
-  create(
-    body: ChatCompletionCreateParamsBase,
-    options?: Core.RequestOptions,
-  ): APIPromise<Stream<ChatCompletionChunk> | ChatCompletion>;
-  create(
-    body: ChatCompletionCreateParams,
-    options?: Core.RequestOptions,
-  ): APIPromise<ChatCompletion> | APIPromise<Stream<ChatCompletionChunk>> {
-    return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false }) as
-      | APIPromise<ChatCompletion>
-      | APIPromise<Stream<ChatCompletionChunk>>;
-  }
-}
-
-/**
- * Represents a chat completion response returned by model, based on the provided
- * input.
- */
-export interface ChatCompletion {
-  /**
-   * A unique identifier for the chat completion.
-   */
-  id: string;
-
-  /**
-   * A list of chat completion choices. Can be more than one if `n` is greater
-   * than 1.
-   */
-  choices: Array<ChatCompletion.Choice>;
-
-  /**
-   * The Unix timestamp (in seconds) of when the chat completion was created.
-   */
-  created: number;
-
-  /**
-   * The model used for the chat completion.
-   */
-  model: string;
-
-  /**
-   * The object type, which is always `chat.completion`.
-   */
-  object: 'chat.completion';
-
-  /**
-   * The service tier used for processing the request.
-   */
-  service_tier?: 'scale' | 'default' | null;
-
-  /**
-   * This fingerprint represents the backend configuration that the model runs with.
-   *
-   * Can be used in conjunction with the `seed` request parameter to understand when
-   * backend changes have been made that might impact determinism.
-   */
-  system_fingerprint?: string;
-
-  /**
-   * Usage statistics for the completion request.
-   */
-  usage?: CompletionsAPI.CompletionUsage;
-}
-
-export namespace ChatCompletion {
-  export interface Choice {
-    /**
-     * The reason the model stopped generating tokens. This will be `stop` if the model
-     * hit a natural stop point or a provided stop sequence, `length` if the maximum
-     * number of tokens specified in the request was reached, `content_filter` if
-     * content was omitted due to a flag from our content filters, `tool_calls` if the
-     * model called a tool, or `function_call` (deprecated) if the model called a
-     * function.
-     */
-    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
-
-    /**
-     * The index of the choice in the list of choices.
-     */
-    index: number;
-
-    /**
-     * Log probability information for the choice.
-     */
-    logprobs: Choice.Logprobs | null;
-
-    /**
-     * A chat completion message generated by the model.
-     */
-    message: ChatCompletionsAPI.ChatCompletionMessage;
-  }
-
-  export namespace Choice {
-    /**
-     * Log probability information for the choice.
-     */
-    export interface Logprobs {
-      /**
-       * A list of message content tokens with log probability information.
-       */
-      content: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
-
-      /**
-       * A list of message refusal tokens with log probability information.
-       */
-      refusal: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
-    }
-  }
-}
-
-/**
- * Messages sent by the model in response to user messages.
- */
-export interface ChatCompletionAssistantMessageParam {
-  /**
-   * The role of the messages author, in this case `assistant`.
-   */
-  role: 'assistant';
-
-  /**
-   * Data about a previous audio response from the model.
-   * [Learn more](https://platform.openai.com/docs/guides/audio).
-   */
-  audio?: ChatCompletionAssistantMessageParam.Audio | null;
-
-  /**
-   * The contents of the assistant message. Required unless `tool_calls` or
-   * `function_call` is specified.
-   */
-  content?: string | Array<ChatCompletionContentPartText | ChatCompletionContentPartRefusal> | null;
-
-  /**
-   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-   * function that should be called, as generated by the model.
-   */
-  function_call?: ChatCompletionAssistantMessageParam.FunctionCall | null;
-
-  /**
-   * An optional name for the participant. Provides the model information to
-   * differentiate between participants of the same role.
-   */
-  name?: string;
-
-  /**
-   * The refusal message by the assistant.
-   */
-  refusal?: string | null;
-
-  /**
-   * The tool calls generated by the model, such as function calls.
-   */
-  tool_calls?: Array<ChatCompletionMessageToolCall>;
-}
-
-export namespace ChatCompletionAssistantMessageParam {
-  /**
-   * Data about a previous audio response from the model.
-   * [Learn more](https://platform.openai.com/docs/guides/audio).
-   */
-  export interface Audio {
-    /**
-     * Unique identifier for a previous audio response from the model.
-     */
-    id: string;
-  }
-
-  /**
-   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-   * function that should be called, as generated by the model.
-   */
-  export interface FunctionCall {
-    /**
-     * The arguments to call the function with, as generated by the model in JSON
-     * format. Note that the model does not always generate valid JSON, and may
-     * hallucinate parameters not defined by your function schema. Validate the
-     * arguments in your code before calling your function.
-     */
-    arguments: string;
-
-    /**
-     * The name of the function to call.
-     */
-    name: string;
-  }
-}
-
-/**
- * If the audio output modality is requested, this object contains data about the
- * audio response from the model.
- * [Learn more](https://platform.openai.com/docs/guides/audio).
- */
-export interface ChatCompletionAudio {
-  /**
-   * Unique identifier for this audio response.
-   */
-  id: string;
-
-  /**
-   * Base64 encoded audio bytes generated by the model, in the format specified in
-   * the request.
-   */
-  data: string;
-
-  /**
-   * The Unix timestamp (in seconds) for when this audio response will no longer be
-   * accessible on the server for use in multi-turn conversations.
-   */
-  expires_at: number;
-
-  /**
-   * Transcript of the audio generated by the model.
-   */
-  transcript: string;
-}
-
-/**
- * Parameters for audio output. Required when audio output is requested with
- * `modalities: ["audio"]`.
- * [Learn more](https://platform.openai.com/docs/guides/audio).
- */
-export interface ChatCompletionAudioParam {
-  /**
-   * Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
-   * or `pcm16`.
-   */
-  format: 'wav' | 'mp3' | 'flac' | 'opus' | 'pcm16';
-
-  /**
-   * The voice the model uses to respond. Supported voices are `ash`, `ballad`,
-   * `coral`, `sage`, and `verse` (also supported but not recommended are `alloy`,
-   * `echo`, and `shimmer`; these voices are less expressive).
-   */
-  voice: 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';
-}
-
-/**
- * Represents a streamed chunk of a chat completion response returned by model,
- * based on the provided input.
- */
-export interface ChatCompletionChunk {
-  /**
-   * A unique identifier for the chat completion. Each chunk has the same ID.
-   */
-  id: string;
-
-  /**
-   * A list of chat completion choices. Can contain more than one elements if `n` is
-   * greater than 1. Can also be empty for the last chunk if you set
-   * `stream_options: {"include_usage": true}`.
-   */
-  choices: Array<ChatCompletionChunk.Choice>;
-
-  /**
-   * The Unix timestamp (in seconds) of when the chat completion was created. Each
-   * chunk has the same timestamp.
-   */
-  created: number;
-
-  /**
-   * The model to generate the completion.
-   */
-  model: string;
-
-  /**
-   * The object type, which is always `chat.completion.chunk`.
-   */
-  object: 'chat.completion.chunk';
-
-  /**
-   * The service tier used for processing the request.
-   */
-  service_tier?: 'scale' | 'default' | null;
-
-  /**
-   * This fingerprint represents the backend configuration that the model runs with.
-   * Can be used in conjunction with the `seed` request parameter to understand when
-   * backend changes have been made that might impact determinism.
-   */
-  system_fingerprint?: string;
-
-  /**
-   * An optional field that will only be present when you set
-   * `stream_options: {"include_usage": true}` in your request. When present, it
-   * contains a null value except for the last chunk which contains the token usage
-   * statistics for the entire request.
-   */
-  usage?: CompletionsAPI.CompletionUsage | null;
-}
-
-export namespace ChatCompletionChunk {
-  export interface Choice {
-    /**
-     * A chat completion delta generated by streamed model responses.
-     */
-    delta: Choice.Delta;
-
-    /**
-     * The reason the model stopped generating tokens. This will be `stop` if the model
-     * hit a natural stop point or a provided stop sequence, `length` if the maximum
-     * number of tokens specified in the request was reached, `content_filter` if
-     * content was omitted due to a flag from our content filters, `tool_calls` if the
-     * model called a tool, or `function_call` (deprecated) if the model called a
-     * function.
-     */
-    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call' | null;
-
-    /**
-     * The index of the choice in the list of choices.
-     */
-    index: number;
-
-    /**
-     * Log probability information for the choice.
-     */
-    logprobs?: Choice.Logprobs | null;
-  }
-
-  export namespace Choice {
-    /**
-     * A chat completion delta generated by streamed model responses.
-     */
-    export interface Delta {
-      /**
-       * The contents of the chunk message.
-       */
-      content?: string | null;
-
-      /**
-       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-       * function that should be called, as generated by the model.
-       */
-      function_call?: Delta.FunctionCall;
-
-      /**
-       * The refusal message generated by the model.
-       */
-      refusal?: string | null;
-
-      /**
-       * The role of the author of this message.
-       */
-      role?: 'developer' | 'system' | 'user' | 'assistant' | 'tool';
-
-      tool_calls?: Array<Delta.ToolCall>;
-    }
-
-    export namespace Delta {
-      /**
-       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-       * function that should be called, as generated by the model.
-       */
-      export interface FunctionCall {
-        /**
-         * The arguments to call the function with, as generated by the model in JSON
-         * format. Note that the model does not always generate valid JSON, and may
-         * hallucinate parameters not defined by your function schema. Validate the
-         * arguments in your code before calling your function.
-         */
-        arguments?: string;
-
-        /**
-         * The name of the function to call.
-         */
-        name?: string;
-      }
-
-      export interface ToolCall {
-        index: number;
-
-        /**
-         * The ID of the tool call.
-         */
-        id?: string;
-
-        function?: ToolCall.Function;
-
-        /**
-         * The type of the tool. Currently, only `function` is supported.
-         */
-        type?: 'function';
-      }
-
-      export namespace ToolCall {
-        export interface Function {
-          /**
-           * The arguments to call the function with, as generated by the model in JSON
-           * format. Note that the model does not always generate valid JSON, and may
-           * hallucinate parameters not defined by your function schema. Validate the
-           * arguments in your code before calling your function.
-           */
-          arguments?: string;
-
-          /**
-           * The name of the function to call.
-           */
-          name?: string;
-        }
-      }
-    }
-
-    /**
-     * Log probability information for the choice.
-     */
-    export interface Logprobs {
-      /**
-       * A list of message content tokens with log probability information.
-       */
-      content: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
-
-      /**
-       * A list of message refusal tokens with log probability information.
-       */
-      refusal: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
-    }
-  }
-}
-
-/**
- * Learn about
- * [text inputs](https://platform.openai.com/docs/guides/text-generation).
- */
-export type ChatCompletionContentPart =
-  | ChatCompletionContentPartText
-  | ChatCompletionContentPartImage
-  | ChatCompletionContentPartInputAudio;
-
-/**
- * Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
- */
-export interface ChatCompletionContentPartImage {
-  image_url: ChatCompletionContentPartImage.ImageURL;
-
-  /**
-   * The type of the content part.
-   */
-  type: 'image_url';
-}
-
-export namespace ChatCompletionContentPartImage {
-  export interface ImageURL {
-    /**
-     * Either a URL of the image or the base64 encoded image data.
-     */
-    url: string;
-
-    /**
-     * Specifies the detail level of the image. Learn more in the
-     * [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
-     */
-    detail?: 'auto' | 'low' | 'high';
-  }
-}
-
-/**
- * Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
- */
-export interface ChatCompletionContentPartInputAudio {
-  input_audio: ChatCompletionContentPartInputAudio.InputAudio;
-
-  /**
-   * The type of the content part. Always `input_audio`.
-   */
-  type: 'input_audio';
-}
-
-export namespace ChatCompletionContentPartInputAudio {
-  export interface InputAudio {
-    /**
-     * Base64 encoded audio data.
-     */
-    data: string;
-
-    /**
-     * The format of the encoded audio data. Currently supports "wav" and "mp3".
-     */
-    format: 'wav' | 'mp3';
-  }
-}
-
-export interface ChatCompletionContentPartRefusal {
-  /**
-   * The refusal message generated by the model.
-   */
-  refusal: string;
-
-  /**
-   * The type of the content part.
-   */
-  type: 'refusal';
-}
-
-/**
- * Learn about
- * [text inputs](https://platform.openai.com/docs/guides/text-generation).
- */
-export interface ChatCompletionContentPartText {
-  /**
-   * The text content.
-   */
-  text: string;
-
-  /**
-   * The type of the content part.
-   */
-  type: 'text';
-}
-
-/**
- * Developer-provided instructions that the model should follow, regardless of
- * messages sent by the user. With o1 models and newer, `developer` messages
- * replace the previous `system` messages.
- */
-export interface ChatCompletionDeveloperMessageParam {
-  /**
-   * The contents of the developer message.
-   */
-  content: string | Array<ChatCompletionContentPartText>;
-
-  /**
-   * The role of the messages author, in this case `developer`.
-   */
-  role: 'developer';
-
-  /**
-   * An optional name for the participant. Provides the model information to
-   * differentiate between participants of the same role.
-   */
-  name?: string;
-}
-
-/**
- * Specifying a particular function via `{"name": "my_function"}` forces the model
- * to call that function.
- */
-export interface ChatCompletionFunctionCallOption {
-  /**
-   * The name of the function to call.
-   */
-  name: string;
-}
-
-/**
- * @deprecated
- */
-export interface ChatCompletionFunctionMessageParam {
-  /**
-   * The contents of the function message.
-   */
-  content: string | null;
-
-  /**
-   * The name of the function to call.
-   */
-  name: string;
-
-  /**
-   * The role of the messages author, in this case `function`.
-   */
-  role: 'function';
-}
-
-/**
- * A chat completion message generated by the model.
- */
-export interface ChatCompletionMessage {
-  /**
-   * The contents of the message.
-   */
-  content: string | null;
-
-  /**
-   * The refusal message generated by the model.
-   */
-  refusal: string | null;
-
-  /**
-   * The role of the author of this message.
-   */
-  role: 'assistant';
-
-  /**
-   * If the audio output modality is requested, this object contains data about the
-   * audio response from the model.
-   * [Learn more](https://platform.openai.com/docs/guides/audio).
-   */
-  audio?: ChatCompletionAudio | null;
-
-  /**
-   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-   * function that should be called, as generated by the model.
-   */
-  function_call?: ChatCompletionMessage.FunctionCall | null;
-
-  /**
-   * The tool calls generated by the model, such as function calls.
-   */
-  tool_calls?: Array<ChatCompletionMessageToolCall>;
-}
-
-export namespace ChatCompletionMessage {
-  /**
-   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-   * function that should be called, as generated by the model.
-   */
-  export interface FunctionCall {
-    /**
-     * The arguments to call the function with, as generated by the model in JSON
-     * format. Note that the model does not always generate valid JSON, and may
-     * hallucinate parameters not defined by your function schema. Validate the
-     * arguments in your code before calling your function.
-     */
-    arguments: string;
-
-    /**
-     * The name of the function to call.
-     */
-    name: string;
-  }
-}
-
-/**
- * Developer-provided instructions that the model should follow, regardless of
- * messages sent by the user. With o1 models and newer, `developer` messages
- * replace the previous `system` messages.
- */
-export type ChatCompletionMessageParam =
-  | ChatCompletionDeveloperMessageParam
-  | ChatCompletionSystemMessageParam
-  | ChatCompletionUserMessageParam
-  | ChatCompletionAssistantMessageParam
-  | ChatCompletionToolMessageParam
-  | ChatCompletionFunctionMessageParam;
-
-export interface ChatCompletionMessageToolCall {
-  /**
-   * The ID of the tool call.
-   */
-  id: string;
-
-  /**
-   * The function that the model called.
-   */
-  function: ChatCompletionMessageToolCall.Function;
-
-  /**
-   * The type of the tool. Currently, only `function` is supported.
-   */
-  type: 'function';
-}
-
-export namespace ChatCompletionMessageToolCall {
-  /**
-   * The function that the model called.
-   */
-  export interface Function {
-    /**
-     * The arguments to call the function with, as generated by the model in JSON
-     * format. Note that the model does not always generate valid JSON, and may
-     * hallucinate parameters not defined by your function schema. Validate the
-     * arguments in your code before calling your function.
-     */
-    arguments: string;
-
-    /**
-     * The name of the function to call.
-     */
-    name: string;
-  }
-}
-
-export type ChatCompletionModality = 'text' | 'audio';
-
-/**
- * Specifies a tool the model should use. Use to force the model to call a specific
- * function.
- */
-export interface ChatCompletionNamedToolChoice {
-  function: ChatCompletionNamedToolChoice.Function;
-
-  /**
-   * The type of the tool. Currently, only `function` is supported.
-   */
-  type: 'function';
-}
-
-export namespace ChatCompletionNamedToolChoice {
-  export interface Function {
-    /**
-     * The name of the function to call.
-     */
-    name: string;
-  }
-}
-
-/**
- * Static predicted output content, such as the content of a text file that is
- * being regenerated.
- */
-export interface ChatCompletionPredictionContent {
-  /**
-   * The content that should be matched when generating a model response. If
-   * generated tokens would match this content, the entire model response can be
-   * returned much more quickly.
-   */
-  content: string | Array<ChatCompletionContentPartText>;
-
-  /**
-   * The type of the predicted content you want to provide. This type is currently
-   * always `content`.
-   */
-  type: 'content';
-}
-
-/**
- * **o1 models only**
- *
- * Constrains effort on reasoning for
- * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
- * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
- * result in faster responses and fewer tokens used on reasoning in a response.
- */
-export type ChatCompletionReasoningEffort = 'low' | 'medium' | 'high';
-
-/**
- * The role of the author of a message
- */
-export type ChatCompletionRole = 'developer' | 'system' | 'user' | 'assistant' | 'tool' | 'function';
-
-/**
- * Options for streaming response. Only set this when you set `stream: true`.
- */
-export interface ChatCompletionStreamOptions {
-  /**
-   * If set, an additional chunk will be streamed before the `data: [DONE]` message.
-   * The `usage` field on this chunk shows the token usage statistics for the entire
-   * request, and the `choices` field will always be an empty array. All other chunks
-   * will also include a `usage` field, but with a null value.
-   */
-  include_usage?: boolean;
-}
-
-/**
- * Developer-provided instructions that the model should follow, regardless of
- * messages sent by the user. With o1 models and newer, use `developer` messages
- * for this purpose instead.
- */
-export interface ChatCompletionSystemMessageParam {
-  /**
-   * The contents of the system message.
-   */
-  content: string | Array<ChatCompletionContentPartText>;
-
-  /**
-   * The role of the messages author, in this case `system`.
-   */
-  role: 'system';
-
-  /**
-   * An optional name for the participant. Provides the model information to
-   * differentiate between participants of the same role.
-   */
-  name?: string;
-}
-
-export interface ChatCompletionTokenLogprob {
-  /**
-   * The token.
-   */
-  token: string;
-
-  /**
-   * A list of integers representing the UTF-8 bytes representation of the token.
-   * Useful in instances where characters are represented by multiple tokens and
-   * their byte representations must be combined to generate the correct text
-   * representation. Can be `null` if there is no bytes representation for the token.
-   */
-  bytes: Array<number> | null;
-
-  /**
-   * The log probability of this token, if it is within the top 20 most likely
-   * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
-   * unlikely.
-   */
-  logprob: number;
-
-  /**
-   * List of the most likely tokens and their log probability, at this token
-   * position. In rare cases, there may be fewer than the number of requested
-   * `top_logprobs` returned.
-   */
-  top_logprobs: Array<ChatCompletionTokenLogprob.TopLogprob>;
-}
-
-export namespace ChatCompletionTokenLogprob {
-  export interface TopLogprob {
-    /**
-     * The token.
-     */
-    token: string;
-
-    /**
-     * A list of integers representing the UTF-8 bytes representation of the token.
-     * Useful in instances where characters are represented by multiple tokens and
-     * their byte representations must be combined to generate the correct text
-     * representation. Can be `null` if there is no bytes representation for the token.
-     */
-    bytes: Array<number> | null;
-
-    /**
-     * The log probability of this token, if it is within the top 20 most likely
-     * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
-     * unlikely.
-     */
-    logprob: number;
-  }
-}
-
-export interface ChatCompletionTool {
-  function: Shared.FunctionDefinition;
-
-  /**
-   * The type of the tool. Currently, only `function` is supported.
-   */
-  type: 'function';
-}
-
-/**
- * Controls which (if any) tool is called by the model. `none` means the model will
- * not call any tool and instead generates a message. `auto` means the model can
- * pick between generating a message or calling one or more tools. `required` means
- * the model must call one or more tools. Specifying a particular tool via
- * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
- * call that tool.
- *
- * `none` is the default when no tools are present. `auto` is the default if tools
- * are present.
- */
-export type ChatCompletionToolChoiceOption = 'none' | 'auto' | 'required' | ChatCompletionNamedToolChoice;
-
-export interface ChatCompletionToolMessageParam {
-  /**
-   * The contents of the tool message.
-   */
-  content: string | Array<ChatCompletionContentPartText>;
-
-  /**
-   * The role of the messages author, in this case `tool`.
-   */
-  role: 'tool';
-
-  /**
-   * Tool call that this message is responding to.
-   */
-  tool_call_id: string;
-}
-
-/**
- * Messages sent by an end user, containing prompts or additional context
- * information.
- */
-export interface ChatCompletionUserMessageParam {
-  /**
-   * The contents of the user message.
-   */
-  content: string | Array<ChatCompletionContentPart>;
-
-  /**
-   * The role of the messages author, in this case `user`.
-   */
-  role: 'user';
-
-  /**
-   * An optional name for the participant. Provides the model information to
-   * differentiate between participants of the same role.
-   */
-  name?: string;
-}
-
-/**
- * @deprecated ChatCompletionMessageParam should be used instead
- */
-export type CreateChatCompletionRequestMessage = ChatCompletionMessageParam;
-
-export type ChatCompletionCreateParams =
-  | ChatCompletionCreateParamsNonStreaming
-  | ChatCompletionCreateParamsStreaming;
-
-export interface ChatCompletionCreateParamsBase {
-  /**
-   * A list of messages comprising the conversation so far. Depending on the
-   * [model](https://platform.openai.com/docs/models) you use, different message
-   * types (modalities) are supported, like
-   * [text](https://platform.openai.com/docs/guides/text-generation),
-   * [images](https://platform.openai.com/docs/guides/vision), and
-   * [audio](https://platform.openai.com/docs/guides/audio).
-   */
-  messages: Array<ChatCompletionMessageParam>;
-
-  /**
-   * ID of the model to use. See the
-   * [model endpoint compatibility](https://platform.openai.com/docs/models#model-endpoint-compatibility)
-   * table for details on which models work with the Chat API.
-   */
-  model: (string & {}) | ChatAPI.ChatModel;
-
-  /**
-   * Parameters for audio output. Required when audio output is requested with
-   * `modalities: ["audio"]`.
-   * [Learn more](https://platform.openai.com/docs/guides/audio).
-   */
-  audio?: ChatCompletionAudioParam | null;
-
-  /**
-   * Number between -2.0 and 2.0. Positive values penalize new tokens based on their
-   * existing frequency in the text so far, decreasing the model's likelihood to
-   * repeat the same line verbatim.
-   */
-  frequency_penalty?: number | null;
-
-  /**
-   * Deprecated in favor of `tool_choice`.
-   *
-   * Controls which (if any) function is called by the model.
-   *
-   * `none` means the model will not call a function and instead generates a message.
-   *
-   * `auto` means the model can pick between generating a message or calling a
-   * function.
-   *
-   * Specifying a particular function via `{"name": "my_function"}` forces the model
-   * to call that function.
-   *
-   * `none` is the default when no functions are present. `auto` is the default if
-   * functions are present.
-   */
-  function_call?: 'none' | 'auto' | ChatCompletionFunctionCallOption;
-
-  /**
-   * Deprecated in favor of `tools`.
-   *
-   * A list of functions the model may generate JSON inputs for.
-   */
-  functions?: Array<ChatCompletionCreateParams.Function>;
-
-  /**
-   * Modify the likelihood of specified tokens appearing in the completion.
-   *
-   * Accepts a JSON object that maps tokens (specified by their token ID in the
-   * tokenizer) to an associated bias value from -100 to 100. Mathematically, the
-   * bias is added to the logits generated by the model prior to sampling. The exact
-   * effect will vary per model, but values between -1 and 1 should decrease or
-   * increase likelihood of selection; values like -100 or 100 should result in a ban
-   * or exclusive selection of the relevant token.
-   */
-  logit_bias?: Record<string, number> | null;
-
-  /**
-   * Whether to return log probabilities of the output tokens or not. If true,
-   * returns the log probabilities of each output token returned in the `content` of
-   * `message`.
-   */
-  logprobs?: boolean | null;
-
-  /**
-   * An upper bound for the number of tokens that can be generated for a completion,
-   * including visible output tokens and
-   * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
-   */
-  max_completion_tokens?: number | null;
-
-  /**
-   * The maximum number of [tokens](/tokenizer) that can be generated in the chat
-   * completion. This value can be used to control
-   * [costs](https://openai.com/api/pricing/) for text generated via API.
-   *
-   * This value is now deprecated in favor of `max_completion_tokens`, and is not
-   * compatible with
-   * [o1 series models](https://platform.openai.com/docs/guides/reasoning).
-   */
-  max_tokens?: number | null;
-
-  /**
-   * Set of 16 key-value pairs that can be attached to an object. This can be useful
-   * for storing additional information about the object in a structured format, and
-   * querying for objects via API or the dashboard.
-   *
-   * Keys are strings with a maximum length of 64 characters. Values are strings with
-   * a maximum length of 512 characters.
-   */
-  metadata?: Shared.Metadata | null;
-
-  /**
-   * Output types that you would like the model to generate for this request. Most
-   * models are capable of generating text, which is the default:
-   *
-   * `["text"]`
-   *
-   * The `gpt-4o-audio-preview` model can also be used to
-   * [generate audio](https://platform.openai.com/docs/guides/audio). To request that
-   * this model generate both text and audio responses, you can use:
-   *
-   * `["text", "audio"]`
-   */
-  modalities?: Array<ChatCompletionModality> | null;
-
-  /**
-   * How many chat completion choices to generate for each input message. Note that
-   * you will be charged based on the number of generated tokens across all of the
-   * choices. Keep `n` as `1` to minimize costs.
-   */
-  n?: number | null;
-
-  /**
-   * Whether to enable
-   * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
-   * during tool use.
-   */
-  parallel_tool_calls?: boolean;
-
-  /**
-   * Static predicted output content, such as the content of a text file that is
-   * being regenerated.
-   */
-  prediction?: ChatCompletionPredictionContent | null;
-
-  /**
-   * Number between -2.0 and 2.0. Positive values penalize new tokens based on
-   * whether they appear in the text so far, increasing the model's likelihood to
-   * talk about new topics.
-   */
-  presence_penalty?: number | null;
-
-  /**
-   * **o1 models only**
-   *
-   * Constrains effort on reasoning for
-   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
-   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
-   * result in faster responses and fewer tokens used on reasoning in a response.
-   */
-  reasoning_effort?: ChatCompletionReasoningEffort;
-
-  /**
-   * An object specifying the format that the model must output.
-   *
-   * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
-   * Outputs which ensures the model will match your supplied JSON schema. Learn more
-   * in the
-   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
-   *
-   * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
-   * message the model generates is valid JSON.
-   *
-   * **Important:** when using JSON mode, you **must** also instruct the model to
-   * produce JSON yourself via a system or user message. Without this, the model may
-   * generate an unending stream of whitespace until the generation reaches the token
-   * limit, resulting in a long-running and seemingly "stuck" request. Also note that
-   * the message content may be partially cut off if `finish_reason="length"`, which
-   * indicates the generation exceeded `max_tokens` or the conversation exceeded the
-   * max context length.
-   */
-  response_format?:
-    | Shared.ResponseFormatText
-    | Shared.ResponseFormatJSONObject
-    | Shared.ResponseFormatJSONSchema;
-
-  /**
-   * This feature is in Beta. If specified, our system will make a best effort to
-   * sample deterministically, such that repeated requests with the same `seed` and
-   * parameters should return the same result. Determinism is not guaranteed, and you
-   * should refer to the `system_fingerprint` response parameter to monitor changes
-   * in the backend.
-   */
-  seed?: number | null;
-
-  /**
-   * Specifies the latency tier to use for processing the request. This parameter is
-   * relevant for customers subscribed to the scale tier service:
-   *
-   * - If set to 'auto', and the Project is Scale tier enabled, the system will
-   *   utilize scale tier credits until they are exhausted.
-   * - If set to 'auto', and the Project is not Scale tier enabled, the request will
-   *   be processed using the default service tier with a lower uptime SLA and no
-   *   latency guarantee.
-   * - If set to 'default', the request will be processed using the default service
-   *   tier with a lower uptime SLA and no latency guarantee.
-   * - When not set, the default behavior is 'auto'.
-   */
-  service_tier?: 'auto' | 'default' | null;
-
-  /**
-   * Up to 4 sequences where the API will stop generating further tokens.
-   */
-  stop?: string | null | Array<string>;
-
-  /**
-   * Whether or not to store the output of this chat completion request for use in
-   * our [model distillation](https://platform.openai.com/docs/guides/distillation)
-   * or [evals](https://platform.openai.com/docs/guides/evals) products.
-   */
-  store?: boolean | null;
-
-  /**
-   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
-   * sent as data-only
-   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
-   * as they become available, with the stream terminated by a `data: [DONE]`
-   * message.
-   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
-   */
-  stream?: boolean | null;
-
-  /**
-   * Options for streaming response. Only set this when you set `stream: true`.
-   */
-  stream_options?: ChatCompletionStreamOptions | null;
-
-  /**
-   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
-   * make the output more random, while lower values like 0.2 will make it more
-   * focused and deterministic. We generally recommend altering this or `top_p` but
-   * not both.
-   */
-  temperature?: number | null;
-
-  /**
-   * Controls which (if any) tool is called by the model. `none` means the model will
-   * not call any tool and instead generates a message. `auto` means the model can
-   * pick between generating a message or calling one or more tools. `required` means
-   * the model must call one or more tools. Specifying a particular tool via
-   * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
-   * call that tool.
-   *
-   * `none` is the default when no tools are present. `auto` is the default if tools
-   * are present.
-   */
-  tool_choice?: ChatCompletionToolChoiceOption;
-
-  /**
-   * A list of tools the model may call. Currently, only functions are supported as a
-   * tool. Use this to provide a list of functions the model may generate JSON inputs
-   * for. A max of 128 functions are supported.
-   */
-  tools?: Array<ChatCompletionTool>;
-
-  /**
-   * An integer between 0 and 20 specifying the number of most likely tokens to
-   * return at each token position, each with an associated log probability.
-   * `logprobs` must be set to `true` if this parameter is used.
-   */
-  top_logprobs?: number | null;
-
-  /**
-   * An alternative to sampling with temperature, called nucleus sampling, where the
-   * model considers the results of the tokens with top_p probability mass. So 0.1
-   * means only the tokens comprising the top 10% probability mass are considered.
-   *
-   * We generally recommend altering this or `temperature` but not both.
-   */
-  top_p?: number | null;
-
-  /**
-   * A unique identifier representing your end-user, which can help OpenAI to monitor
-   * and detect abuse.
-   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
-   */
-  user?: string;
-}
-
-export namespace ChatCompletionCreateParams {
-  /**
-   * @deprecated
-   */
-  export interface Function {
-    /**
-     * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
-     * underscores and dashes, with a maximum length of 64.
-     */
-    name: string;
-
-    /**
-     * A description of what the function does, used by the model to choose when and
-     * how to call the function.
-     */
-    description?: string;
-
-    /**
-     * The parameters the functions accepts, described as a JSON Schema object. See the
-     * [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
-     * and the
-     * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
-     * documentation about the format.
-     *
-     * Omitting `parameters` defines a function with an empty parameter list.
-     */
-    parameters?: Shared.FunctionParameters;
-  }
-
-  export type ChatCompletionCreateParamsNonStreaming =
-    ChatCompletionsAPI.ChatCompletionCreateParamsNonStreaming;
-  export type ChatCompletionCreateParamsStreaming = ChatCompletionsAPI.ChatCompletionCreateParamsStreaming;
-}
-
-/**
- * @deprecated Use ChatCompletionCreateParams instead
- */
-export type CompletionCreateParams = ChatCompletionCreateParams;
-
-export interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase {
-  /**
-   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
-   * sent as data-only
-   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
-   * as they become available, with the stream terminated by a `data: [DONE]`
-   * message.
-   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
-   */
-  stream?: false | null;
-}
-
-/**
- * @deprecated Use ChatCompletionCreateParamsNonStreaming instead
- */
-export type CompletionCreateParamsNonStreaming = ChatCompletionCreateParamsNonStreaming;
-
-export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreateParamsBase {
-  /**
-   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
-   * sent as data-only
-   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
-   * as they become available, with the stream terminated by a `data: [DONE]`
-   * message.
-   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
-   */
-  stream: true;
-}
-
-/**
- * @deprecated Use ChatCompletionCreateParamsStreaming instead
- */
-export type CompletionCreateParamsStreaming = ChatCompletionCreateParamsStreaming;
-
-export declare namespace Completions {
-  export {
-    type ChatCompletion as ChatCompletion,
-    type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,
-    type ChatCompletionAudio as ChatCompletionAudio,
-    type ChatCompletionAudioParam as ChatCompletionAudioParam,
-    type ChatCompletionChunk as ChatCompletionChunk,
-    type ChatCompletionContentPart as ChatCompletionContentPart,
-    type ChatCompletionContentPartImage as ChatCompletionContentPartImage,
-    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,
-    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,
-    type ChatCompletionContentPartText as ChatCompletionContentPartText,
-    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,
-    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
-    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
-    type ChatCompletionMessage as ChatCompletionMessage,
-    type ChatCompletionMessageParam as ChatCompletionMessageParam,
-    type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,
-    type ChatCompletionModality as ChatCompletionModality,
-    type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,
-    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,
-    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,
-    type ChatCompletionRole as ChatCompletionRole,
-    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,
-    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
-    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
-    type ChatCompletionTool as ChatCompletionTool,
-    type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,
-    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
-    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
-    type CreateChatCompletionRequestMessage as CreateChatCompletionRequestMessage,
-    type ChatCompletionCreateParams as ChatCompletionCreateParams,
-    type CompletionCreateParams as CompletionCreateParams,
-    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,
-    type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
-    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,
-    type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
-  };
-}
+export * from './completions/completions';
diff --git a/src/resources/chat/completions/completions.ts b/src/resources/chat/completions/completions.ts
new file mode 100644
index 000000000..3af4a3a1d
--- /dev/null
+++ src/resources/chat/completions/completions.ts
@@ -0,0 +1,1453 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import { APIResource } from '../../../resource';
+import { isRequestOptions } from '../../../core';
+import { APIPromise } from '../../../core';
+import * as Core from '../../../core';
+import * as CompletionsCompletionsAPI from './completions';
+import * as CompletionsAPI from '../../completions';
+import * as Shared from '../../shared';
+import * as ChatAPI from '../chat';
+import * as MessagesAPI from './messages';
+import { MessageListParams, Messages } from './messages';
+import { CursorPage, type CursorPageParams } from '../../../pagination';
+import { Stream } from '../../../streaming';
+
+export class Completions extends APIResource {
+  messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);
+
+  /**
+   * Creates a model response for the given chat conversation. Learn more in the
+   * [text generation](https://platform.openai.com/docs/guides/text-generation),
+   * [vision](https://platform.openai.com/docs/guides/vision), and
+   * [audio](https://platform.openai.com/docs/guides/audio) guides.
+   *
+   * Parameter support can differ depending on the model used to generate the
+   * response, particularly for newer reasoning models. Parameters that are only
+   * supported for reasoning models are noted below. For the current state of
+   * unsupported parameters in reasoning models,
+   * [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).
+   */
+  create(
+    body: ChatCompletionCreateParamsNonStreaming,
+    options?: Core.RequestOptions,
+  ): APIPromise<ChatCompletion>;
+  create(
+    body: ChatCompletionCreateParamsStreaming,
+    options?: Core.RequestOptions,
+  ): APIPromise<Stream<ChatCompletionChunk>>;
+  create(
+    body: ChatCompletionCreateParamsBase,
+    options?: Core.RequestOptions,
+  ): APIPromise<Stream<ChatCompletionChunk> | ChatCompletion>;
+  create(
+    body: ChatCompletionCreateParams,
+    options?: Core.RequestOptions,
+  ): APIPromise<ChatCompletion> | APIPromise<Stream<ChatCompletionChunk>> {
+    return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false }) as
+      | APIPromise<ChatCompletion>
+      | APIPromise<Stream<ChatCompletionChunk>>;
+  }
+
+  /**
+   * Get a stored chat completion. Only chat completions that have been created with
+   * the `store` parameter set to `true` will be returned.
+   */
+  retrieve(completionId: string, options?: Core.RequestOptions): Core.APIPromise<ChatCompletion> {
+    return this._client.get(`/chat/completions/${completionId}`, options);
+  }
+
+  /**
+   * Modify a stored chat completion. Only chat completions that have been created
+   * with the `store` parameter set to `true` can be modified. Currently, the only
+   * supported modification is to update the `metadata` field.
+   */
+  update(
+    completionId: string,
+    body: ChatCompletionUpdateParams,
+    options?: Core.RequestOptions,
+  ): Core.APIPromise<ChatCompletion> {
+    return this._client.post(`/chat/completions/${completionId}`, { body, ...options });
+  }
+
+  /**
+   * List stored chat completions. Only chat completions that have been stored with
+   * the `store` parameter set to `true` will be returned.
+   */
+  list(
+    query?: ChatCompletionListParams,
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionsPage, ChatCompletion>;
+  list(options?: Core.RequestOptions): Core.PagePromise<ChatCompletionsPage, ChatCompletion>;
+  list(
+    query: ChatCompletionListParams | Core.RequestOptions = {},
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionsPage, ChatCompletion> {
+    if (isRequestOptions(query)) {
+      return this.list({}, query);
+    }
+    return this._client.getAPIList('/chat/completions', ChatCompletionsPage, { query, ...options });
+  }
+
+  /**
+   * Delete a stored chat completion. Only chat completions that have been created
+   * with the `store` parameter set to `true` can be deleted.
+   */
+  del(completionId: string, options?: Core.RequestOptions): Core.APIPromise<ChatCompletionDeleted> {
+    return this._client.delete(`/chat/completions/${completionId}`, options);
+  }
+}
+
+export class ChatCompletionsPage extends CursorPage<ChatCompletion> {}
+
+export class ChatCompletionStoreMessagesPage extends CursorPage<ChatCompletionStoreMessage> {}
+
+/**
+ * Represents a chat completion response returned by model, based on the provided
+ * input.
+ */
+export interface ChatCompletion {
+  /**
+   * A unique identifier for the chat completion.
+   */
+  id: string;
+
+  /**
+   * A list of chat completion choices. Can be more than one if `n` is greater
+   * than 1.
+   */
+  choices: Array<ChatCompletion.Choice>;
+
+  /**
+   * The Unix timestamp (in seconds) of when the chat completion was created.
+   */
+  created: number;
+
+  /**
+   * The model used for the chat completion.
+   */
+  model: string;
+
+  /**
+   * The object type, which is always `chat.completion`.
+   */
+  object: 'chat.completion';
+
+  /**
+   * The service tier used for processing the request.
+   */
+  service_tier?: 'scale' | 'default' | null;
+
+  /**
+   * This fingerprint represents the backend configuration that the model runs with.
+   *
+   * Can be used in conjunction with the `seed` request parameter to understand when
+   * backend changes have been made that might impact determinism.
+   */
+  system_fingerprint?: string;
+
+  /**
+   * Usage statistics for the completion request.
+   */
+  usage?: CompletionsAPI.CompletionUsage;
+}
+
+export namespace ChatCompletion {
+  export interface Choice {
+    /**
+     * The reason the model stopped generating tokens. This will be `stop` if the model
+     * hit a natural stop point or a provided stop sequence, `length` if the maximum
+     * number of tokens specified in the request was reached, `content_filter` if
+     * content was omitted due to a flag from our content filters, `tool_calls` if the
+     * model called a tool, or `function_call` (deprecated) if the model called a
+     * function.
+     */
+    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
+
+    /**
+     * The index of the choice in the list of choices.
+     */
+    index: number;
+
+    /**
+     * Log probability information for the choice.
+     */
+    logprobs: Choice.Logprobs | null;
+
+    /**
+     * A chat completion message generated by the model.
+     */
+    message: CompletionsCompletionsAPI.ChatCompletionMessage;
+  }
+
+  export namespace Choice {
+    /**
+     * Log probability information for the choice.
+     */
+    export interface Logprobs {
+      /**
+       * A list of message content tokens with log probability information.
+       */
+      content: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
+
+      /**
+       * A list of message refusal tokens with log probability information.
+       */
+      refusal: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
+    }
+  }
+}
+
+/**
+ * Messages sent by the model in response to user messages.
+ */
+export interface ChatCompletionAssistantMessageParam {
+  /**
+   * The role of the messages author, in this case `assistant`.
+   */
+  role: 'assistant';
+
+  /**
+   * Data about a previous audio response from the model.
+   * [Learn more](https://platform.openai.com/docs/guides/audio).
+   */
+  audio?: ChatCompletionAssistantMessageParam.Audio | null;
+
+  /**
+   * The contents of the assistant message. Required unless `tool_calls` or
+   * `function_call` is specified.
+   */
+  content?: string | Array<ChatCompletionContentPartText | ChatCompletionContentPartRefusal> | null;
+
+  /**
+   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+   * function that should be called, as generated by the model.
+   */
+  function_call?: ChatCompletionAssistantMessageParam.FunctionCall | null;
+
+  /**
+   * An optional name for the participant. Provides the model information to
+   * differentiate between participants of the same role.
+   */
+  name?: string;
+
+  /**
+   * The refusal message by the assistant.
+   */
+  refusal?: string | null;
+
+  /**
+   * The tool calls generated by the model, such as function calls.
+   */
+  tool_calls?: Array<ChatCompletionMessageToolCall>;
+}
+
+export namespace ChatCompletionAssistantMessageParam {
+  /**
+   * Data about a previous audio response from the model.
+   * [Learn more](https://platform.openai.com/docs/guides/audio).
+   */
+  export interface Audio {
+    /**
+     * Unique identifier for a previous audio response from the model.
+     */
+    id: string;
+  }
+
+  /**
+   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+   * function that should be called, as generated by the model.
+   */
+  export interface FunctionCall {
+    /**
+     * The arguments to call the function with, as generated by the model in JSON
+     * format. Note that the model does not always generate valid JSON, and may
+     * hallucinate parameters not defined by your function schema. Validate the
+     * arguments in your code before calling your function.
+     */
+    arguments: string;
+
+    /**
+     * The name of the function to call.
+     */
+    name: string;
+  }
+}
+
+/**
+ * If the audio output modality is requested, this object contains data about the
+ * audio response from the model.
+ * [Learn more](https://platform.openai.com/docs/guides/audio).
+ */
+export interface ChatCompletionAudio {
+  /**
+   * Unique identifier for this audio response.
+   */
+  id: string;
+
+  /**
+   * Base64 encoded audio bytes generated by the model, in the format specified in
+   * the request.
+   */
+  data: string;
+
+  /**
+   * The Unix timestamp (in seconds) for when this audio response will no longer be
+   * accessible on the server for use in multi-turn conversations.
+   */
+  expires_at: number;
+
+  /**
+   * Transcript of the audio generated by the model.
+   */
+  transcript: string;
+}
+
+/**
+ * Parameters for audio output. Required when audio output is requested with
+ * `modalities: ["audio"]`.
+ * [Learn more](https://platform.openai.com/docs/guides/audio).
+ */
+export interface ChatCompletionAudioParam {
+  /**
+   * Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
+   * or `pcm16`.
+   */
+  format: 'wav' | 'mp3' | 'flac' | 'opus' | 'pcm16';
+
+  /**
+   * The voice the model uses to respond. Supported voices are `ash`, `ballad`,
+   * `coral`, `sage`, and `verse` (also supported but not recommended are `alloy`,
+   * `echo`, and `shimmer`; these voices are less expressive).
+   */
+  voice: 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';
+}
+
+/**
+ * Represents a streamed chunk of a chat completion response returned by model,
+ * based on the provided input.
+ */
+export interface ChatCompletionChunk {
+  /**
+   * A unique identifier for the chat completion. Each chunk has the same ID.
+   */
+  id: string;
+
+  /**
+   * A list of chat completion choices. Can contain more than one elements if `n` is
+   * greater than 1. Can also be empty for the last chunk if you set
+   * `stream_options: {"include_usage": true}`.
+   */
+  choices: Array<ChatCompletionChunk.Choice>;
+
+  /**
+   * The Unix timestamp (in seconds) of when the chat completion was created. Each
+   * chunk has the same timestamp.
+   */
+  created: number;
+
+  /**
+   * The model to generate the completion.
+   */
+  model: string;
+
+  /**
+   * The object type, which is always `chat.completion.chunk`.
+   */
+  object: 'chat.completion.chunk';
+
+  /**
+   * The service tier used for processing the request.
+   */
+  service_tier?: 'scale' | 'default' | null;
+
+  /**
+   * This fingerprint represents the backend configuration that the model runs with.
+   * Can be used in conjunction with the `seed` request parameter to understand when
+   * backend changes have been made that might impact determinism.
+   */
+  system_fingerprint?: string;
+
+  /**
+   * An optional field that will only be present when you set
+   * `stream_options: {"include_usage": true}` in your request. When present, it
+   * contains a null value except for the last chunk which contains the token usage
+   * statistics for the entire request.
+   */
+  usage?: CompletionsAPI.CompletionUsage | null;
+}
+
+export namespace ChatCompletionChunk {
+  export interface Choice {
+    /**
+     * A chat completion delta generated by streamed model responses.
+     */
+    delta: Choice.Delta;
+
+    /**
+     * The reason the model stopped generating tokens. This will be `stop` if the model
+     * hit a natural stop point or a provided stop sequence, `length` if the maximum
+     * number of tokens specified in the request was reached, `content_filter` if
+     * content was omitted due to a flag from our content filters, `tool_calls` if the
+     * model called a tool, or `function_call` (deprecated) if the model called a
+     * function.
+     */
+    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call' | null;
+
+    /**
+     * The index of the choice in the list of choices.
+     */
+    index: number;
+
+    /**
+     * Log probability information for the choice.
+     */
+    logprobs?: Choice.Logprobs | null;
+  }
+
+  export namespace Choice {
+    /**
+     * A chat completion delta generated by streamed model responses.
+     */
+    export interface Delta {
+      /**
+       * The contents of the chunk message.
+       */
+      content?: string | null;
+
+      /**
+       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+       * function that should be called, as generated by the model.
+       */
+      function_call?: Delta.FunctionCall;
+
+      /**
+       * The refusal message generated by the model.
+       */
+      refusal?: string | null;
+
+      /**
+       * The role of the author of this message.
+       */
+      role?: 'developer' | 'system' | 'user' | 'assistant' | 'tool';
+
+      tool_calls?: Array<Delta.ToolCall>;
+    }
+
+    export namespace Delta {
+      /**
+       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+       * function that should be called, as generated by the model.
+       */
+      export interface FunctionCall {
+        /**
+         * The arguments to call the function with, as generated by the model in JSON
+         * format. Note that the model does not always generate valid JSON, and may
+         * hallucinate parameters not defined by your function schema. Validate the
+         * arguments in your code before calling your function.
+         */
+        arguments?: string;
+
+        /**
+         * The name of the function to call.
+         */
+        name?: string;
+      }
+
+      export interface ToolCall {
+        index: number;
+
+        /**
+         * The ID of the tool call.
+         */
+        id?: string;
+
+        function?: ToolCall.Function;
+
+        /**
+         * The type of the tool. Currently, only `function` is supported.
+         */
+        type?: 'function';
+      }
+
+      export namespace ToolCall {
+        export interface Function {
+          /**
+           * The arguments to call the function with, as generated by the model in JSON
+           * format. Note that the model does not always generate valid JSON, and may
+           * hallucinate parameters not defined by your function schema. Validate the
+           * arguments in your code before calling your function.
+           */
+          arguments?: string;
+
+          /**
+           * The name of the function to call.
+           */
+          name?: string;
+        }
+      }
+    }
+
+    /**
+     * Log probability information for the choice.
+     */
+    export interface Logprobs {
+      /**
+       * A list of message content tokens with log probability information.
+       */
+      content: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
+
+      /**
+       * A list of message refusal tokens with log probability information.
+       */
+      refusal: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
+    }
+  }
+}
+
+/**
+ * Learn about
+ * [text inputs](https://platform.openai.com/docs/guides/text-generation).
+ */
+export type ChatCompletionContentPart =
+  | ChatCompletionContentPartText
+  | ChatCompletionContentPartImage
+  | ChatCompletionContentPartInputAudio;
+
+/**
+ * Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
+ */
+export interface ChatCompletionContentPartImage {
+  image_url: ChatCompletionContentPartImage.ImageURL;
+
+  /**
+   * The type of the content part.
+   */
+  type: 'image_url';
+}
+
+export namespace ChatCompletionContentPartImage {
+  export interface ImageURL {
+    /**
+     * Either a URL of the image or the base64 encoded image data.
+     */
+    url: string;
+
+    /**
+     * Specifies the detail level of the image. Learn more in the
+     * [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
+     */
+    detail?: 'auto' | 'low' | 'high';
+  }
+}
+
+/**
+ * Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
+ */
+export interface ChatCompletionContentPartInputAudio {
+  input_audio: ChatCompletionContentPartInputAudio.InputAudio;
+
+  /**
+   * The type of the content part. Always `input_audio`.
+   */
+  type: 'input_audio';
+}
+
+export namespace ChatCompletionContentPartInputAudio {
+  export interface InputAudio {
+    /**
+     * Base64 encoded audio data.
+     */
+    data: string;
+
+    /**
+     * The format of the encoded audio data. Currently supports "wav" and "mp3".
+     */
+    format: 'wav' | 'mp3';
+  }
+}
+
+export interface ChatCompletionContentPartRefusal {
+  /**
+   * The refusal message generated by the model.
+   */
+  refusal: string;
+
+  /**
+   * The type of the content part,.
+   */
+  type: 'refusal';
+}
+
+/**
+ * Learn about
+ * [text inputs](https://platform.openai.com/docs/guides/text-generation).
+ */
+export interface ChatCompletionContentPartText {
+  /**
+   * The text content.
+   */
+  text: string;
+
+  /**
+   * The type of the content part.
+   */
+  type: 'text';
+}
+
+export interface ChatCompletionDeleted {
+  /**
+   * The ID of the chat completion that was deleted.
+   */
+  id: string;
+
+  /**
+   * Whether the chat completion was deleted.
+   */
+  deleted: boolean;
+
+  /**
+   * The type of object being deleted.
+   */
+  object: 'chat.completion.deleted';
+}
+
+/**
+ * Developer-provided instructions that the model should follow, regardless of
+ * messages sent by the user. With o1 models and newer, `developer` messages
+ * replace the previous `system` messages.
+ */
+export interface ChatCompletionDeveloperMessageParam {
+  /**
+   * The contents of the developer message.
+   */
+  content: string | Array<ChatCompletionContentPartText>;
+
+  /**
+   * The role of the messages author, in this case `developer`.
+   */
+  role: 'developer';
+
+  /**
+   * An optional name for the participant. Provides the model information to
+   * differentiate between participants of the same role.
+   */
+  name?: string;
+}
+
+/**
+ * Specifying a particular function via `{"name": "my_function"}` forces the model
+ * to call that function.
+ */
+export interface ChatCompletionFunctionCallOption {
+  /**
+   * The name of the function to call.
+   */
+  name: string;
+}
+
+/**
+ * @deprecated
+ */
+export interface ChatCompletionFunctionMessageParam {
+  /**
+   * The contents of the function message.
+   */
+  content: string | null;
+
+  /**
+   * The name of the function to call.
+   */
+  name: string;
+
+  /**
+   * The role of the messages author, in this case `function`.
+   */
+  role: 'function';
+}
+
+/**
+ * A chat completion message generated by the model.
+ */
+export interface ChatCompletionMessage {
+  /**
+   * The contents of the message.
+   */
+  content: string | null;
+
+  /**
+   * The refusal message generated by the model.
+   */
+  refusal: string | null;
+
+  /**
+   * The role of the author of this message.
+   */
+  role: 'assistant';
+
+  /**
+   * If the audio output modality is requested, this object contains data about the
+   * audio response from the model.
+   * [Learn more](https://platform.openai.com/docs/guides/audio).
+   */
+  audio?: ChatCompletionAudio | null;
+
+  /**
+   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+   * function that should be called, as generated by the model.
+   */
+  function_call?: ChatCompletionMessage.FunctionCall | null;
+
+  /**
+   * The tool calls generated by the model, such as function calls.
+   */
+  tool_calls?: Array<ChatCompletionMessageToolCall>;
+}
+
+export namespace ChatCompletionMessage {
+  /**
+   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+   * function that should be called, as generated by the model.
+   */
+  export interface FunctionCall {
+    /**
+     * The arguments to call the function with, as generated by the model in JSON
+     * format. Note that the model does not always generate valid JSON, and may
+     * hallucinate parameters not defined by your function schema. Validate the
+     * arguments in your code before calling your function.
+     */
+    arguments: string;
+
+    /**
+     * The name of the function to call.
+     */
+    name: string;
+  }
+}
+
+/**
+ * Developer-provided instructions that the model should follow, regardless of
+ * messages sent by the user. With o1 models and newer, `developer` messages
+ * replace the previous `system` messages.
+ */
+export type ChatCompletionMessageParam =
+  | ChatCompletionDeveloperMessageParam
+  | ChatCompletionSystemMessageParam
+  | ChatCompletionUserMessageParam
+  | ChatCompletionAssistantMessageParam
+  | ChatCompletionToolMessageParam
+  | ChatCompletionFunctionMessageParam;
+
+export interface ChatCompletionMessageToolCall {
+  /**
+   * The ID of the tool call.
+   */
+  id: string;
+
+  /**
+   * The function that the model called.
+   */
+  function: ChatCompletionMessageToolCall.Function;
+
+  /**
+   * The type of the tool. Currently, only `function` is supported.
+   */
+  type: 'function';
+}
+
+export namespace ChatCompletionMessageToolCall {
+  /**
+   * The function that the model called.
+   */
+  export interface Function {
+    /**
+     * The arguments to call the function with, as generated by the model in JSON
+     * format. Note that the model does not always generate valid JSON, and may
+     * hallucinate parameters not defined by your function schema. Validate the
+     * arguments in your code before calling your function.
+     */
+    arguments: string;
+
+    /**
+     * The name of the function to call.
+     */
+    name: string;
+  }
+}
+
+export type ChatCompletionModality = 'text' | 'audio';
+
+/**
+ * Specifies a tool the model should use. Use to force the model to call a specific
+ * function.
+ */
+export interface ChatCompletionNamedToolChoice {
+  function: ChatCompletionNamedToolChoice.Function;
+
+  /**
+   * The type of the tool. Currently, only `function` is supported.
+   */
+  type: 'function';
+}
+
+export namespace ChatCompletionNamedToolChoice {
+  export interface Function {
+    /**
+     * The name of the function to call.
+     */
+    name: string;
+  }
+}
+
+/**
+ * Static predicted output content, such as the content of a text file that is
+ * being regenerated.
+ */
+export interface ChatCompletionPredictionContent {
+  /**
+   * The content that should be matched when generating a model response. If
+   * generated tokens would match this content, the entire model response can be
+   * returned much more quickly.
+   */
+  content: string | Array<ChatCompletionContentPartText>;
+
+  /**
+   * The type of the predicted content you want to provide. This type is currently
+   * always `content`.
+   */
+  type: 'content';
+}
+
+/**
+ * **o1 and o3-mini models only**
+ *
+ * Constrains effort on reasoning for
+ * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+ * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+ * result in faster responses and fewer tokens used on reasoning in a response.
+ */
+export type ChatCompletionReasoningEffort = 'low' | 'medium' | 'high' | null;
+
+/**
+ * The role of the author of a message
+ */
+export type ChatCompletionRole = 'developer' | 'system' | 'user' | 'assistant' | 'tool' | 'function';
+
+/**
+ * A chat completion message generated by the model.
+ */
+export interface ChatCompletionStoreMessage extends ChatCompletionMessage {
+  /**
+   * The identifier of the chat message.
+   */
+  id: string;
+}
+
+/**
+ * Options for streaming response. Only set this when you set `stream: true`.
+ */
+export interface ChatCompletionStreamOptions {
+  /**
+   * If set, an additional chunk will be streamed before the `data: [DONE]` message.
+   * The `usage` field on this chunk shows the token usage statistics for the entire
+   * request, and the `choices` field will always be an empty array. All other chunks
+   * will also include a `usage` field, but with a null value.
+   */
+  include_usage?: boolean;
+}
+
+/**
+ * Developer-provided instructions that the model should follow, regardless of
+ * messages sent by the user. With o1 models and newer, use `developer` messages
+ * for this purpose instead.
+ */
+export interface ChatCompletionSystemMessageParam {
+  /**
+   * The contents of the system message.
+   */
+  content: string | Array<ChatCompletionContentPartText>;
+
+  /**
+   * The role of the messages author, in this case `system`.
+   */
+  role: 'system';
+
+  /**
+   * An optional name for the participant. Provides the model information to
+   * differentiate between participants of the same role.
+   */
+  name?: string;
+}
+
+export interface ChatCompletionTokenLogprob {
+  /**
+   * The token.
+   */
+  token: string;
+
+  /**
+   * A list of integers representing the UTF-8 bytes representation of the token.
+   * Useful in instances where characters are represented by multiple tokens and
+   * their byte representations must be combined to generate the correct text
+   * representation. Can be `null` if there is no bytes representation for the token.
+   */
+  bytes: Array<number> | null;
+
+  /**
+   * The log probability of this token, if it is within the top 20 most likely
+   * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
+   * unlikely.
+   */
+  logprob: number;
+
+  /**
+   * List of the most likely tokens and their log probability, at this token
+   * position. In rare cases, there may be fewer than the number of requested
+   * `top_logprobs` returned.
+   */
+  top_logprobs: Array<ChatCompletionTokenLogprob.TopLogprob>;
+}
+
+export namespace ChatCompletionTokenLogprob {
+  export interface TopLogprob {
+    /**
+     * The token.
+     */
+    token: string;
+
+    /**
+     * A list of integers representing the UTF-8 bytes representation of the token.
+     * Useful in instances where characters are represented by multiple tokens and
+     * their byte representations must be combined to generate the correct text
+     * representation. Can be `null` if there is no bytes representation for the token.
+     */
+    bytes: Array<number> | null;
+
+    /**
+     * The log probability of this token, if it is within the top 20 most likely
+     * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
+     * unlikely.
+     */
+    logprob: number;
+  }
+}
+
+export interface ChatCompletionTool {
+  function: Shared.FunctionDefinition;
+
+  /**
+   * The type of the tool. Currently, only `function` is supported.
+   */
+  type: 'function';
+}
+
+/**
+ * Controls which (if any) tool is called by the model. `none` means the model will
+ * not call any tool and instead generates a message. `auto` means the model can
+ * pick between generating a message or calling one or more tools. `required` means
+ * the model must call one or more tools. Specifying a particular tool via
+ * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
+ * call that tool.
+ *
+ * `none` is the default when no tools are present. `auto` is the default if tools
+ * are present.
+ */
+export type ChatCompletionToolChoiceOption = 'none' | 'auto' | 'required' | ChatCompletionNamedToolChoice;
+
+export interface ChatCompletionToolMessageParam {
+  /**
+   * The contents of the tool message.
+   */
+  content: string | Array<ChatCompletionContentPartText>;
+
+  /**
+   * The role of the messages author, in this case `tool`.
+   */
+  role: 'tool';
+
+  /**
+   * Tool call that this message is responding to.
+   */
+  tool_call_id: string;
+}
+
+/**
+ * Messages sent by an end user, containing prompts or additional context
+ * information.
+ */
+export interface ChatCompletionUserMessageParam {
+  /**
+   * The contents of the user message.
+   */
+  content: string | Array<ChatCompletionContentPart>;
+
+  /**
+   * The role of the messages author, in this case `user`.
+   */
+  role: 'user';
+
+  /**
+   * An optional name for the participant. Provides the model information to
+   * differentiate between participants of the same role.
+   */
+  name?: string;
+}
+
+/**
+ * @deprecated ChatCompletionMessageParam should be used instead
+ */
+export type CreateChatCompletionRequestMessage = ChatCompletionMessageParam;
+
+export type ChatCompletionCreateParams =
+  | ChatCompletionCreateParamsNonStreaming
+  | ChatCompletionCreateParamsStreaming;
+
+export interface ChatCompletionCreateParamsBase {
+  /**
+   * A list of messages comprising the conversation so far. Depending on the
+   * [model](https://platform.openai.com/docs/models) you use, different message
+   * types (modalities) are supported, like
+   * [text](https://platform.openai.com/docs/guides/text-generation),
+   * [images](https://platform.openai.com/docs/guides/vision), and
+   * [audio](https://platform.openai.com/docs/guides/audio).
+   */
+  messages: Array<ChatCompletionMessageParam>;
+
+  /**
+   * ID of the model to use. See the
+   * [model endpoint compatibility](https://platform.openai.com/docs/models#model-endpoint-compatibility)
+   * table for details on which models work with the Chat API.
+   */
+  model: (string & {}) | ChatAPI.ChatModel;
+
+  /**
+   * Parameters for audio output. Required when audio output is requested with
+   * `modalities: ["audio"]`.
+   * [Learn more](https://platform.openai.com/docs/guides/audio).
+   */
+  audio?: ChatCompletionAudioParam | null;
+
+  /**
+   * Number between -2.0 and 2.0. Positive values penalize new tokens based on their
+   * existing frequency in the text so far, decreasing the model's likelihood to
+   * repeat the same line verbatim.
+   */
+  frequency_penalty?: number | null;
+
+  /**
+   * Deprecated in favor of `tool_choice`.
+   *
+   * Controls which (if any) function is called by the model.
+   *
+   * `none` means the model will not call a function and instead generates a message.
+   *
+   * `auto` means the model can pick between generating a message or calling a
+   * function.
+   *
+   * Specifying a particular function via `{"name": "my_function"}` forces the model
+   * to call that function.
+   *
+   * `none` is the default when no functions are present. `auto` is the default if
+   * functions are present.
+   */
+  function_call?: 'none' | 'auto' | ChatCompletionFunctionCallOption;
+
+  /**
+   * Deprecated in favor of `tools`.
+   *
+   * A list of functions the model may generate JSON inputs for.
+   */
+  functions?: Array<ChatCompletionCreateParams.Function>;
+
+  /**
+   * Modify the likelihood of specified tokens appearing in the completion.
+   *
+   * Accepts a JSON object that maps tokens (specified by their token ID in the
+   * tokenizer) to an associated bias value from -100 to 100. Mathematically, the
+   * bias is added to the logits generated by the model prior to sampling. The exact
+   * effect will vary per model, but values between -1 and 1 should decrease or
+   * increase likelihood of selection; values like -100 or 100 should result in a ban
+   * or exclusive selection of the relevant token.
+   */
+  logit_bias?: Record<string, number> | null;
+
+  /**
+   * Whether to return log probabilities of the output tokens or not. If true,
+   * returns the log probabilities of each output token returned in the `content` of
+   * `message`.
+   */
+  logprobs?: boolean | null;
+
+  /**
+   * An upper bound for the number of tokens that can be generated for a completion,
+   * including visible output tokens and
+   * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
+   */
+  max_completion_tokens?: number | null;
+
+  /**
+   * The maximum number of [tokens](/tokenizer) that can be generated in the chat
+   * completion. This value can be used to control
+   * [costs](https://openai.com/api/pricing/) for text generated via API.
+   *
+   * This value is now deprecated in favor of `max_completion_tokens`, and is not
+   * compatible with
+   * [o1 series models](https://platform.openai.com/docs/guides/reasoning).
+   */
+  max_tokens?: number | null;
+
+  /**
+   * Set of 16 key-value pairs that can be attached to an object. This can be useful
+   * for storing additional information about the object in a structured format, and
+   * querying for objects via API or the dashboard.
+   *
+   * Keys are strings with a maximum length of 64 characters. Values are strings with
+   * a maximum length of 512 characters.
+   */
+  metadata?: Shared.Metadata | null;
+
+  /**
+   * Output types that you would like the model to generate for this request. Most
+   * models are capable of generating text, which is the default:
+   *
+   * `["text"]`
+   *
+   * The `gpt-4o-audio-preview` model can also be used to
+   * [generate audio](https://platform.openai.com/docs/guides/audio). To request that
+   * this model generate both text and audio responses, you can use:
+   *
+   * `["text", "audio"]`
+   */
+  modalities?: Array<ChatCompletionModality> | null;
+
+  /**
+   * How many chat completion choices to generate for each input message. Note that
+   * you will be charged based on the number of generated tokens across all of the
+   * choices. Keep `n` as `1` to minimize costs.
+   */
+  n?: number | null;
+
+  /**
+   * Whether to enable
+   * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
+   * during tool use.
+   */
+  parallel_tool_calls?: boolean;
+
+  /**
+   * Static predicted output content, such as the content of a text file that is
+   * being regenerated.
+   */
+  prediction?: ChatCompletionPredictionContent | null;
+
+  /**
+   * Number between -2.0 and 2.0. Positive values penalize new tokens based on
+   * whether they appear in the text so far, increasing the model's likelihood to
+   * talk about new topics.
+   */
+  presence_penalty?: number | null;
+
+  /**
+   * **o1 and o3-mini models only**
+   *
+   * Constrains effort on reasoning for
+   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+   * result in faster responses and fewer tokens used on reasoning in a response.
+   */
+  reasoning_effort?: ChatCompletionReasoningEffort | null;
+
+  /**
+   * An object specifying the format that the model must output.
+   *
+   * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
+   * Outputs which ensures the model will match your supplied JSON schema. Learn more
+   * in the
+   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
+   *
+   * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
+   * message the model generates is valid JSON.
+   *
+   * **Important:** when using JSON mode, you **must** also instruct the model to
+   * produce JSON yourself via a system or user message. Without this, the model may
+   * generate an unending stream of whitespace until the generation reaches the token
+   * limit, resulting in a long-running and seemingly "stuck" request. Also note that
+   * the message content may be partially cut off if `finish_reason="length"`, which
+   * indicates the generation exceeded `max_tokens` or the conversation exceeded the
+   * max context length.
+   */
+  response_format?:
+    | Shared.ResponseFormatText
+    | Shared.ResponseFormatJSONObject
+    | Shared.ResponseFormatJSONSchema;
+
+  /**
+   * This feature is in Beta. If specified, our system will make a best effort to
+   * sample deterministically, such that repeated requests with the same `seed` and
+   * parameters should return the same result. Determinism is not guaranteed, and you
+   * should refer to the `system_fingerprint` response parameter to monitor changes
+   * in the backend.
+   */
+  seed?: number | null;
+
+  /**
+   * Specifies the latency tier to use for processing the request. This parameter is
+   * relevant for customers subscribed to the scale tier service:
+   *
+   * - If set to 'auto', and the Project is Scale tier enabled, the system will
+   *   utilize scale tier credits until they are exhausted.
+   * - If set to 'auto', and the Project is not Scale tier enabled, the request will
+   *   be processed using the default service tier with a lower uptime SLA and no
+   *   latency guarantee.
+   * - If set to 'default', the request will be processed using the default service
+   *   tier with a lower uptime SLA and no latency guarantee.
+   * - When not set, the default behavior is 'auto'.
+   */
+  service_tier?: 'auto' | 'default' | null;
+
+  /**
+   * Up to 4 sequences where the API will stop generating further tokens.
+   */
+  stop?: string | null | Array<string>;
+
+  /**
+   * Whether or not to store the output of this chat completion request for use in
+   * our [model distillation](https://platform.openai.com/docs/guides/distillation)
+   * or [evals](https://platform.openai.com/docs/guides/evals) products.
+   */
+  store?: boolean | null;
+
+  /**
+   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
+   * sent as data-only
+   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
+   * as they become available, with the stream terminated by a `data: [DONE]`
+   * message.
+   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
+   */
+  stream?: boolean | null;
+
+  /**
+   * Options for streaming response. Only set this when you set `stream: true`.
+   */
+  stream_options?: ChatCompletionStreamOptions | null;
+
+  /**
+   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
+   * make the output more random, while lower values like 0.2 will make it more
+   * focused and deterministic. We generally recommend altering this or `top_p` but
+   * not both.
+   */
+  temperature?: number | null;
+
+  /**
+   * Controls which (if any) tool is called by the model. `none` means the model will
+   * not call any tool and instead generates a message. `auto` means the model can
+   * pick between generating a message or calling one or more tools. `required` means
+   * the model must call one or more tools. Specifying a particular tool via
+   * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
+   * call that tool.
+   *
+   * `none` is the default when no tools are present. `auto` is the default if tools
+   * are present.
+   */
+  tool_choice?: ChatCompletionToolChoiceOption;
+
+  /**
+   * A list of tools the model may call. Currently, only functions are supported as a
+   * tool. Use this to provide a list of functions the model may generate JSON inputs
+   * for. A max of 128 functions are supported.
+   */
+  tools?: Array<ChatCompletionTool>;
+
+  /**
+   * An integer between 0 and 20 specifying the number of most likely tokens to
+   * return at each token position, each with an associated log probability.
+   * `logprobs` must be set to `true` if this parameter is used.
+   */
+  top_logprobs?: number | null;
+
+  /**
+   * An alternative to sampling with temperature, called nucleus sampling, where the
+   * model considers the results of the tokens with top_p probability mass. So 0.1
+   * means only the tokens comprising the top 10% probability mass are considered.
+   *
+   * We generally recommend altering this or `temperature` but not both.
+   */
+  top_p?: number | null;
+
+  /**
+   * A unique identifier representing your end-user, which can help OpenAI to monitor
+   * and detect abuse.
+   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
+   */
+  user?: string;
+}
+
+export namespace ChatCompletionCreateParams {
+  /**
+   * @deprecated
+   */
+  export interface Function {
+    /**
+     * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
+     * underscores and dashes, with a maximum length of 64.
+     */
+    name: string;
+
+    /**
+     * A description of what the function does, used by the model to choose when and
+     * how to call the function.
+     */
+    description?: string;
+
+    /**
+     * The parameters the functions accepts, described as a JSON Schema object. See the
+     * [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
+     * and the
+     * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
+     * documentation about the format.
+     *
+     * Omitting `parameters` defines a function with an empty parameter list.
+     */
+    parameters?: Shared.FunctionParameters;
+  }
+
+  export type ChatCompletionCreateParamsNonStreaming =
+    CompletionsCompletionsAPI.ChatCompletionCreateParamsNonStreaming;
+  export type ChatCompletionCreateParamsStreaming =
+    CompletionsCompletionsAPI.ChatCompletionCreateParamsStreaming;
+}
+
+/**
+ * @deprecated Use ChatCompletionCreateParams instead
+ */
+export type CompletionCreateParams = ChatCompletionCreateParams;
+
+export interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase {
+  /**
+   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
+   * sent as data-only
+   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
+   * as they become available, with the stream terminated by a `data: [DONE]`
+   * message.
+   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
+   */
+  stream?: false | null;
+}
+
+/**
+ * @deprecated Use ChatCompletionCreateParamsNonStreaming instead
+ */
+export type CompletionCreateParamsNonStreaming = ChatCompletionCreateParamsNonStreaming;
+
+export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreateParamsBase {
+  /**
+   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
+   * sent as data-only
+   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
+   * as they become available, with the stream terminated by a `data: [DONE]`
+   * message.
+   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
+   */
+  stream: true;
+}
+
+/**
+ * @deprecated Use ChatCompletionCreateParamsStreaming instead
+ */
+export type CompletionCreateParamsStreaming = ChatCompletionCreateParamsStreaming;
+
+export interface ChatCompletionUpdateParams {
+  /**
+   * Set of 16 key-value pairs that can be attached to an object. This can be useful
+   * for storing additional information about the object in a structured format, and
+   * querying for objects via API or the dashboard.
+   *
+   * Keys are strings with a maximum length of 64 characters. Values are strings with
+   * a maximum length of 512 characters.
+   */
+  metadata: Shared.Metadata | null;
+}
+
+/**
+ * @deprecated Use ChatCompletionUpdateParams instead
+ */
+export type CompletionUpdateParams = ChatCompletionUpdateParams;
+
+export interface ChatCompletionListParams extends CursorPageParams {
+  /**
+   * A list of metadata keys to filter the chat completions by. Example:
+   *
+   * `metadata[key1]=value1&metadata[key2]=value2`
+   */
+  metadata?: Shared.Metadata | null;
+
+  /**
+   * The model used to generate the chat completions.
+   */
+  model?: string;
+
+  /**
+   * Sort order for chat completions by timestamp. Use `asc` for ascending order or
+   * `desc` for descending order. Defaults to `asc`.
+   */
+  order?: 'asc' | 'desc';
+}
+
+/**
+ * @deprecated Use ChatCompletionListParams instead
+ */
+export type CompletionListParams = ChatCompletionListParams;
+
+Completions.ChatCompletionsPage = ChatCompletionsPage;
+Completions.Messages = Messages;
+
+export declare namespace Completions {
+  export {
+    type ChatCompletion as ChatCompletion,
+    type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,
+    type ChatCompletionAudio as ChatCompletionAudio,
+    type ChatCompletionAudioParam as ChatCompletionAudioParam,
+    type ChatCompletionChunk as ChatCompletionChunk,
+    type ChatCompletionContentPart as ChatCompletionContentPart,
+    type ChatCompletionContentPartImage as ChatCompletionContentPartImage,
+    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,
+    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,
+    type ChatCompletionContentPartText as ChatCompletionContentPartText,
+    type ChatCompletionDeleted as ChatCompletionDeleted,
+    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,
+    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
+    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
+    type ChatCompletionMessage as ChatCompletionMessage,
+    type ChatCompletionMessageParam as ChatCompletionMessageParam,
+    type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,
+    type ChatCompletionModality as ChatCompletionModality,
+    type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,
+    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,
+    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,
+    type ChatCompletionRole as ChatCompletionRole,
+    type ChatCompletionStoreMessage as ChatCompletionStoreMessage,
+    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,
+    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
+    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
+    type ChatCompletionTool as ChatCompletionTool,
+    type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,
+    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
+    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
+    type CreateChatCompletionRequestMessage as CreateChatCompletionRequestMessage,
+    ChatCompletionsPage as ChatCompletionsPage,
+    type ChatCompletionCreateParams as ChatCompletionCreateParams,
+    type CompletionCreateParams as CompletionCreateParams,
+    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,
+    type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
+    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,
+    type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
+    type ChatCompletionUpdateParams as ChatCompletionUpdateParams,
+    type CompletionUpdateParams as CompletionUpdateParams,
+    type ChatCompletionListParams as ChatCompletionListParams,
+    type CompletionListParams as CompletionListParams,
+  };
+
+  export { Messages as Messages, type MessageListParams as MessageListParams };
+}
diff --git a/src/resources/chat/completions/index.ts b/src/resources/chat/completions/index.ts
new file mode 100644
index 000000000..3691f41d8
--- /dev/null
+++ src/resources/chat/completions/index.ts
@@ -0,0 +1,49 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+export {
+  ChatCompletionStoreMessagesPage,
+  ChatCompletionsPage,
+  Completions,
+  type ChatCompletion,
+  type ChatCompletionAssistantMessageParam,
+  type ChatCompletionAudio,
+  type ChatCompletionAudioParam,
+  type ChatCompletionChunk,
+  type ChatCompletionContentPart,
+  type ChatCompletionContentPartImage,
+  type ChatCompletionContentPartInputAudio,
+  type ChatCompletionContentPartRefusal,
+  type ChatCompletionContentPartText,
+  type ChatCompletionDeleted,
+  type ChatCompletionDeveloperMessageParam,
+  type ChatCompletionFunctionCallOption,
+  type ChatCompletionFunctionMessageParam,
+  type ChatCompletionMessage,
+  type ChatCompletionMessageParam,
+  type ChatCompletionMessageToolCall,
+  type ChatCompletionModality,
+  type ChatCompletionNamedToolChoice,
+  type ChatCompletionPredictionContent,
+  type ChatCompletionReasoningEffort,
+  type ChatCompletionRole,
+  type ChatCompletionStoreMessage,
+  type ChatCompletionStreamOptions,
+  type ChatCompletionSystemMessageParam,
+  type ChatCompletionTokenLogprob,
+  type ChatCompletionTool,
+  type ChatCompletionToolChoiceOption,
+  type ChatCompletionToolMessageParam,
+  type ChatCompletionUserMessageParam,
+  type CreateChatCompletionRequestMessage,
+  type ChatCompletionCreateParams,
+  type CompletionCreateParams,
+  type ChatCompletionCreateParamsNonStreaming,
+  type CompletionCreateParamsNonStreaming,
+  type ChatCompletionCreateParamsStreaming,
+  type CompletionCreateParamsStreaming,
+  type ChatCompletionUpdateParams,
+  type CompletionUpdateParams,
+  type ChatCompletionListParams,
+  type CompletionListParams,
+} from './completions';
+export { Messages, type MessageListParams } from './messages';
diff --git a/src/resources/chat/completions/messages.ts b/src/resources/chat/completions/messages.ts
new file mode 100644
index 000000000..fc1cc5d94
--- /dev/null
+++ src/resources/chat/completions/messages.ts
@@ -0,0 +1,52 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import { APIResource } from '../../../resource';
+import { isRequestOptions } from '../../../core';
+import * as Core from '../../../core';
+import * as CompletionsAPI from './completions';
+import { ChatCompletionStoreMessagesPage } from './completions';
+import { type CursorPageParams } from '../../../pagination';
+
+export class Messages extends APIResource {
+  /**
+   * Get the messages in a stored chat completion. Only chat completions that have
+   * been created with the `store` parameter set to `true` will be returned.
+   */
+  list(
+    completionId: string,
+    query?: MessageListParams,
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionStoreMessagesPage, CompletionsAPI.ChatCompletionStoreMessage>;
+  list(
+    completionId: string,
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionStoreMessagesPage, CompletionsAPI.ChatCompletionStoreMessage>;
+  list(
+    completionId: string,
+    query: MessageListParams | Core.RequestOptions = {},
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionStoreMessagesPage, CompletionsAPI.ChatCompletionStoreMessage> {
+    if (isRequestOptions(query)) {
+      return this.list(completionId, {}, query);
+    }
+    return this._client.getAPIList(
+      `/chat/completions/${completionId}/messages`,
+      ChatCompletionStoreMessagesPage,
+      { query, ...options },
+    );
+  }
+}
+
+export interface MessageListParams extends CursorPageParams {
+  /**
+   * Sort order for messages by timestamp. Use `asc` for ascending order or `desc`
+   * for descending order. Defaults to `asc`.
+   */
+  order?: 'asc' | 'desc';
+}
+
+export declare namespace Messages {
+  export { type MessageListParams as MessageListParams };
+}
+
+export { ChatCompletionStoreMessagesPage };
diff --git src/resources/chat/index.ts src/resources/chat/index.ts
index c3be19402..a9b5b46fb 100644
--- src/resources/chat/index.ts
+++ src/resources/chat/index.ts
@@ -2,6 +2,8 @@

export { Chat, type ChatModel } from './chat';
export {
+  ChatCompletionStoreMessagesPage,
+  ChatCompletionsPage,
  Completions,
  type ChatCompletion,
  type ChatCompletionAssistantMessageParam,
@@ -13,6 +15,7 @@ export {
  type ChatCompletionContentPartInputAudio,
  type ChatCompletionContentPartRefusal,
  type ChatCompletionContentPartText,
+  type ChatCompletionDeleted,
  type ChatCompletionDeveloperMessageParam,
  type ChatCompletionFunctionCallOption,
  type ChatCompletionFunctionMessageParam,
@@ -24,6 +27,7 @@ export {
  type ChatCompletionPredictionContent,
  type ChatCompletionReasoningEffort,
  type ChatCompletionRole,
+  type ChatCompletionStoreMessage,
  type ChatCompletionStreamOptions,
  type ChatCompletionSystemMessageParam,
  type ChatCompletionTokenLogprob,
@@ -38,4 +42,8 @@ export {
  type CompletionCreateParamsNonStreaming,
  type ChatCompletionCreateParamsStreaming,
  type CompletionCreateParamsStreaming,
-} from './completions';
+  type ChatCompletionUpdateParams,
+  type CompletionUpdateParams,
+  type ChatCompletionListParams,
+  type CompletionListParams,
+} from './completions/index';
diff --git src/resources/completions.ts src/resources/completions.ts
index be75a46f0..664e39d9d 100644
--- src/resources/completions.ts
+++ src/resources/completions.ts
@@ -4,7 +4,7 @@ import { APIResource } from '../resource';
import { APIPromise } from '../core';
import * as Core from '../core';
import * as CompletionsAPI from './completions';
-import * as ChatCompletionsAPI from './chat/completions';
+import * as CompletionsCompletionsAPI from './chat/completions/completions';
import { Stream } from '../streaming';

export class Completions extends APIResource {
@@ -311,7 +311,7 @@ export interface CompletionCreateParamsBase {
  /**
   * Options for streaming response. Only set this when you set `stream: true`.
   */
-  stream_options?: ChatCompletionsAPI.ChatCompletionStreamOptions | null;
+  stream_options?: CompletionsCompletionsAPI.ChatCompletionStreamOptions | null;

  /**
   * The suffix that comes after a completion of inserted text.
diff --git src/resources/moderations.ts src/resources/moderations.ts
index f7b16166d..86e90376d 100644
--- src/resources/moderations.ts
+++ src/resources/moderations.ts
@@ -75,14 +75,14 @@ export namespace Moderation {
     * execution of wrongdoing, or that gives advice or instruction on how to commit
     * illicit acts. For example, "how to shoplift" would fit this category.
     */
-    illicit: boolean;
+    illicit: boolean | null;

    /**
     * Content that includes instructions or advice that facilitate the planning or
     * execution of wrongdoing that also includes violence, or that gives advice or
     * instruction on the procurement of any weapon.
     */
-    'illicit/violent': boolean;
+    'illicit/violent': boolean | null;

    /**
     * Content that promotes, encourages, or depicts acts of self-harm, such as
diff --git src/streaming.ts src/streaming.ts
index 6a57a50a0..52266154c 100644
--- src/streaming.ts
+++ src/streaming.ts
@@ -1,6 +1,6 @@
import { ReadableStream, type Response } from './_shims/index';
import { OpenAIError } from './error';
-import { LineDecoder } from './internal/decoders/line';
+import { findDoubleNewlineIndex, LineDecoder } from './internal/decoders/line';
import { ReadableStreamToAsyncIterable } from './internal/stream-utils';

import { APIError } from './error';
@@ -259,37 +259,6 @@ async function* iterSSEChunks(iterator: AsyncIterableIterator<Bytes>): AsyncGene
  }
}

-function findDoubleNewlineIndex(buffer: Uint8Array): number {
-  // This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
-  // and returns the index right after the first occurrence of any pattern,
-  // or -1 if none of the patterns are found.
-  const newline = 0x0a; // \n
-  const carriage = 0x0d; // \r
-
-  for (let i = 0; i < buffer.length - 2; i++) {
-    if (buffer[i] === newline && buffer[i + 1] === newline) {
-      // \n\n
-      return i + 2;
-    }
-    if (buffer[i] === carriage && buffer[i + 1] === carriage) {
-      // \r\r
-      return i + 2;
-    }
-    if (
-      buffer[i] === carriage &&
-      buffer[i + 1] === newline &&
-      i + 3 < buffer.length &&
-      buffer[i + 2] === carriage &&
-      buffer[i + 3] === newline
-    ) {
-      // \r\n\r\n
-      return i + 4;
-    }
-  }
-
-  return -1;
-}
-
class SSEDecoder {
  private data: string[];
  private event: string | null;
@@ -345,17 +314,6 @@ class SSEDecoder {
  }
}

-/** This is an internal helper function that's just used for testing */
-export function _decodeChunks(chunks: string[]): string[] {
-  const decoder = new LineDecoder();
-  const lines: string[] = [];
-  for (const chunk of chunks) {
-    lines.push(...decoder.decode(chunk));
-  }
-
-  return lines;
-}
-
function partition(str: string, delimiter: string): [string, string, string] {
  const index = str.indexOf(delimiter);
  if (index !== -1) {
diff --git src/version.ts src/version.ts
index 13c764d7d..4fdc11dc7 100644
--- src/version.ts
+++ src/version.ts
@@ -1 +1 @@
-export const VERSION = '4.83.0'; // x-release-please-version
+export const VERSION = '4.85.2'; // x-release-please-version
diff --git tests/api-resources/beta/assistants.test.ts tests/api-resources/beta/assistants.test.ts
index 88a10ba8f..16bc9f942 100644
--- tests/api-resources/beta/assistants.test.ts
+++ tests/api-resources/beta/assistants.test.ts
@@ -27,6 +27,7 @@ describe('resource assistants', () => {
      instructions: 'instructions',
      metadata: { foo: 'string' },
      name: 'name',
+      reasoning_effort: 'low',
      response_format: 'auto',
      temperature: 1,
      tool_resources: {
diff --git tests/api-resources/beta/threads/runs/runs.test.ts tests/api-resources/beta/threads/runs/runs.test.ts
index 9b728403f..13ae89a00 100644
--- tests/api-resources/beta/threads/runs/runs.test.ts
+++ tests/api-resources/beta/threads/runs/runs.test.ts
@@ -39,6 +39,7 @@ describe('resource runs', () => {
      metadata: { foo: 'string' },
      model: 'gpt-4o',
      parallel_tool_calls: true,
+      reasoning_effort: 'low',
      response_format: 'auto',
      stream: false,
      temperature: 1,
diff --git tests/api-resources/chat/completions.test.ts tests/api-resources/chat/completions.test.ts
deleted file mode 100644
index 8f1bc7d4c..000000000
--- tests/api-resources/chat/completions.test.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-import OpenAI from 'openai';
-import { Response } from 'node-fetch';
-
-const client = new OpenAI({
-  apiKey: 'My API Key',
-  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
-});
-
-describe('resource completions', () => {
-  test('create: only required params', async () => {
-    const responsePromise = client.chat.completions.create({
-      messages: [{ content: 'string', role: 'developer' }],
-      model: 'gpt-4o',
-    });
-    const rawResponse = await responsePromise.asResponse();
-    expect(rawResponse).toBeInstanceOf(Response);
-    const response = await responsePromise;
-    expect(response).not.toBeInstanceOf(Response);
-    const dataAndResponse = await responsePromise.withResponse();
-    expect(dataAndResponse.data).toBe(response);
-    expect(dataAndResponse.response).toBe(rawResponse);
-  });
-
-  test('create: required and optional params', async () => {
-    const response = await client.chat.completions.create({
-      messages: [{ content: 'string', role: 'developer', name: 'name' }],
-      model: 'gpt-4o',
-      audio: { format: 'wav', voice: 'alloy' },
-      frequency_penalty: -2,
-      function_call: 'none',
-      functions: [{ name: 'name', description: 'description', parameters: { foo: 'bar' } }],
-      logit_bias: { foo: 0 },
-      logprobs: true,
-      max_completion_tokens: 0,
-      max_tokens: 0,
-      metadata: { foo: 'string' },
-      modalities: ['text'],
-      n: 1,
-      parallel_tool_calls: true,
-      prediction: { content: 'string', type: 'content' },
-      presence_penalty: -2,
-      reasoning_effort: 'low',
-      response_format: { type: 'text' },
-      seed: 0,
-      service_tier: 'auto',
-      stop: 'string',
-      store: true,
-      stream: false,
-      stream_options: { include_usage: true },
-      temperature: 1,
-      tool_choice: 'none',
-      tools: [
-        {
-          function: { name: 'name', description: 'description', parameters: { foo: 'bar' }, strict: true },
-          type: 'function',
-        },
-      ],
-      top_logprobs: 0,
-      top_p: 1,
-      user: 'user-1234',
-    });
-  });
-});
diff --git a/tests/api-resources/chat/completions/completions.test.ts b/tests/api-resources/chat/completions/completions.test.ts
new file mode 100644
index 000000000..acdd631db
--- /dev/null
+++ tests/api-resources/chat/completions/completions.test.ts
@@ -0,0 +1,144 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import OpenAI from 'openai';
+import { Response } from 'node-fetch';
+
+const client = new OpenAI({
+  apiKey: 'My API Key',
+  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
+});
+
+describe('resource completions', () => {
+  test('create: only required params', async () => {
+    const responsePromise = client.chat.completions.create({
+      messages: [{ content: 'string', role: 'developer' }],
+      model: 'gpt-4o',
+    });
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('create: required and optional params', async () => {
+    const response = await client.chat.completions.create({
+      messages: [{ content: 'string', role: 'developer', name: 'name' }],
+      model: 'gpt-4o',
+      audio: { format: 'wav', voice: 'alloy' },
+      frequency_penalty: -2,
+      function_call: 'none',
+      functions: [{ name: 'name', description: 'description', parameters: { foo: 'bar' } }],
+      logit_bias: { foo: 0 },
+      logprobs: true,
+      max_completion_tokens: 0,
+      max_tokens: 0,
+      metadata: { foo: 'string' },
+      modalities: ['text'],
+      n: 1,
+      parallel_tool_calls: true,
+      prediction: { content: 'string', type: 'content' },
+      presence_penalty: -2,
+      reasoning_effort: 'low',
+      response_format: { type: 'text' },
+      seed: 0,
+      service_tier: 'auto',
+      stop: 'string',
+      store: true,
+      stream: false,
+      stream_options: { include_usage: true },
+      temperature: 1,
+      tool_choice: 'none',
+      tools: [
+        {
+          function: { name: 'name', description: 'description', parameters: { foo: 'bar' }, strict: true },
+          type: 'function',
+        },
+      ],
+      top_logprobs: 0,
+      top_p: 1,
+      user: 'user-1234',
+    });
+  });
+
+  test('retrieve', async () => {
+    const responsePromise = client.chat.completions.retrieve('completion_id');
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('retrieve: request options instead of params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.retrieve('completion_id', { path: '/_stainless_unknown_path' }),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+
+  test('update: only required params', async () => {
+    const responsePromise = client.chat.completions.update('completion_id', { metadata: { foo: 'string' } });
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('update: required and optional params', async () => {
+    const response = await client.chat.completions.update('completion_id', { metadata: { foo: 'string' } });
+  });
+
+  test('list', async () => {
+    const responsePromise = client.chat.completions.list();
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('list: request options instead of params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(client.chat.completions.list({ path: '/_stainless_unknown_path' })).rejects.toThrow(
+      OpenAI.NotFoundError,
+    );
+  });
+
+  test('list: request options and params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.list(
+        { after: 'after', limit: 0, metadata: { foo: 'string' }, model: 'model', order: 'asc' },
+        { path: '/_stainless_unknown_path' },
+      ),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+
+  test('del', async () => {
+    const responsePromise = client.chat.completions.del('completion_id');
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('del: request options instead of params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.del('completion_id', { path: '/_stainless_unknown_path' }),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+});
diff --git a/tests/api-resources/chat/completions/messages.test.ts b/tests/api-resources/chat/completions/messages.test.ts
new file mode 100644
index 000000000..664106cb9
--- /dev/null
+++ tests/api-resources/chat/completions/messages.test.ts
@@ -0,0 +1,40 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import OpenAI from 'openai';
+import { Response } from 'node-fetch';
+
+const client = new OpenAI({
+  apiKey: 'My API Key',
+  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
+});
+
+describe('resource messages', () => {
+  test('list', async () => {
+    const responsePromise = client.chat.completions.messages.list('completion_id');
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('list: request options instead of params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.messages.list('completion_id', { path: '/_stainless_unknown_path' }),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+
+  test('list: request options and params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.messages.list(
+        'completion_id',
+        { after: 'after', limit: 0, order: 'asc' },
+        { path: '/_stainless_unknown_path' },
+      ),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+});
diff --git a/tests/internal/decoders/line.test.ts b/tests/internal/decoders/line.test.ts
new file mode 100644
index 000000000..e76858e55
--- /dev/null
+++ tests/internal/decoders/line.test.ts
@@ -0,0 +1,128 @@
+import { findDoubleNewlineIndex, LineDecoder } from 'openai/internal/decoders/line';
+
+function decodeChunks(chunks: string[], { flush }: { flush: boolean } = { flush: false }): string[] {
+  const decoder = new LineDecoder();
+  const lines: string[] = [];
+  for (const chunk of chunks) {
+    lines.push(...decoder.decode(chunk));
+  }
+
+  if (flush) {
+    lines.push(...decoder.flush());
+  }
+
+  return lines;
+}
+
+describe('line decoder', () => {
+  test('basic', () => {
+    // baz is not included because the line hasn't ended yet
+    expect(decodeChunks(['foo', ' bar\nbaz'])).toEqual(['foo bar']);
+  });
+
+  test('basic with \\r', () => {
+    expect(decodeChunks(['foo', ' bar\r\nbaz'])).toEqual(['foo bar']);
+    expect(decodeChunks(['foo', ' bar\r\nbaz'], { flush: true })).toEqual(['foo bar', 'baz']);
+  });
+
+  test('trailing new lines', () => {
+    expect(decodeChunks(['foo', ' bar', 'baz\n', 'thing\n'])).toEqual(['foo barbaz', 'thing']);
+  });
+
+  test('trailing new lines with \\r', () => {
+    expect(decodeChunks(['foo', ' bar', 'baz\r\n', 'thing\r\n'])).toEqual(['foo barbaz', 'thing']);
+  });
+
+  test('escaped new lines', () => {
+    expect(decodeChunks(['foo', ' bar\\nbaz\n'])).toEqual(['foo bar\\nbaz']);
+  });
+
+  test('escaped new lines with \\r', () => {
+    expect(decod,eChunks(['foo', ' bar\\r\\nbaz\n'])).toEqual(['foo bar\\r\\nbaz']);
+  });
+
+  test('\\r & \\n split across multiple chunks', () => {
+    expect(decodeChunks(['foo\r', '\n', 'bar'], { flush: true })).toEqual(['foo', 'bar']);
+  });
+
+  test('single \\r', () => {
+    expect(decodeChunks(['foo\r', 'bar'], { flush: true })).toEqual(['foo', 'bar']);
+  });
+
+  test('double \\r', () => {
+    expect(decodeChunks(['foo\r', 'bar\r'], { flush: true })).toEqual(['foo', 'bar']);
+    expect(decodeChunks(['foo\r', '\r', 'bar'], { flush: true })).toEqual(['foo', '', 'bar']);
+    // implementation detail that we don't yield the single \r line until a new \r or \n is encountered
+    expect(decodeChunks(['foo\r', '\r', 'bar'], { flush: false })).toEqual(['foo']);
+  });
+
+  test('double \\r then \\r\\n', () => {
+    expect(decodeChunks(['foo\r', '\r', '\r', '\n', 'bar', '\n'])).toEqual(['foo', '', '', 'bar']);
+    expect(decodeChunks(['foo\n', '\n', '\n', 'bar', '\n'])).toEqual(['foo', '', '', 'bar']);
+  });
+
+  test('double newline', () => {
+    expect(decodeChunks(['foo\n\nbar'], { flush: true })).toEqual(['foo', '', 'bar']);
+    expect(decodeChunks(['foo', '\n', '\nbar'], { flush: true })).toEqual(['foo', '', 'bar']);
+    expect(decodeChunks(['foo\n', '\n', 'bar'], { flush: true })).toEqual(['foo', '', 'bar']);
+    expect(decodeChunks(['foo', '\n', '\n', 'bar'], { flush: true })).toEqual(['foo', '', 'bar']);
+  });
+
+  test('multi-byte characters across chunks', () => {
+    const decoder = new LineDecoder();
+
+    // bytes taken from the string 'известни' and arbitrarily split
+    // so that some multi-byte characters span multiple chunks
+    expect(decoder.decode(new Uint8Array([0xd0]))).toHaveLength(0);
+    expect(decoder.decode(new Uint8Array([0xb8, 0xd0, 0xb7, 0xd0]))).toHaveLength(0);
+    expect(
+      decoder.decode(new Uint8Array([0xb2, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0xd0, 0xbd, 0xd0, 0xb8])),
+    ).toHaveLength(0);
+
+    const decoded = decoder.decode(new Uint8Array([0xa]));
+    expect(decoded).toEqual(['известни']);
+  });
+
+  test('flushing trailing newlines', () => {
+    expect(decodeChunks(['foo\n', '\nbar'], { flush: true })).toEqual(['foo', '', 'bar']);
+  });
+
+  test('flushing empty buffer', () => {
+    expect(decodeChunks([], { flush: true })).toEqual([]);
+  });
+});
+
+describe('findDoubleNewlineIndex', () => {
+  test('finds \\n\\n', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\n\nbar'))).toBe(5);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\n\nbar'))).toBe(2);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\n\n'))).toBe(5);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\n\n'))).toBe(2);
+  });
+
+  test('finds \\r\\r', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\rbar'))).toBe(5);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\r\rbar'))).toBe(2);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\r'))).toBe(5);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\r\r'))).toBe(2);
+  });
+
+  test('finds \\r\\n\\r\\n', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\n\r\nbar'))).toBe(7);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\r\n\r\nbar'))).toBe(4);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\n\r\n'))).toBe(7);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\r\n\r\n'))).toBe(4);
+  });
+
+  test('returns -1 when no double newline found', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\nbar'))).toBe(-1);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\rbar'))).toBe(-1);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\nbar'))).toBe(-1);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode(''))).toBe(-1);
+  });
+
+  test('handles incomplete patterns', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\n\r'))).toBe(-1);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\n'))).toBe(-1);
+  });
+});
diff --git tests/streaming.test.ts tests/streaming.test.ts
index 6fe9a5781..b9a38f208 100644
--- tests/streaming.test.ts
+++ tests/streaming.test.ts
@@ -1,35 +1,7 @@
import { Response } from 'node-fetch';
import { PassThrough } from 'stream';
import assert from 'assert';
-import { _iterSSEMessages, _decodeChunks as decodeChunks } from 'openai/streaming';
-
-describe('line decoder', () => {
-  test('basic', () => {
-    // baz is not included because the line hasn't ended yet
-    expect(decodeChunks(['foo', ' bar\nbaz'])).toEqual(['foo bar']);
-  });
-
-  test('basic with \\r', () => {
-    // baz is not included because the line hasn't ended yet
-    expect(decodeChunks(['foo', ' bar\r\nbaz'])).toEqual(['foo bar']);
-  });
-
-  test('trailing new lines', () => {
-    expect(decodeChunks(['foo', ' bar', 'baz\n', 'thing\n'])).toEqual(['foo barbaz', 'thing']);
-  });
-
-  test('trailing new lines with \\r', () => {
-    expect(decodeChunks(['foo', ' bar', 'baz\r\n', 'thing\r\n'])).toEqual(['foo barbaz', 'thing']);
-  });
-
-  test('escaped new lines', () => {
-    expect(decodeChunks(['foo', ' bar\\nbaz\n'])).toEqual(['foo bar\\nbaz']);
-  });
-
-  test('escaped new lines with \\r', () => {
-    expect(decodeChunks(['foo', ' bar\\r\\nbaz\n'])).toEqual(['foo bar\\r\\nbaz']);
-  });
-});
+import { _iterSSEMessages } from 'openai/streaming';

describe('streaming decoding', () => {
  test('basic', async () => {


Description

This PR introduces several significant changes to the OpenAI Node.js SDK, including:

  1. Addition of stored chat completion functionality (retrieve, list, update, delete)
  2. Improvements to chunk reading and text decoding for streaming responses
  3. Better ecosystem test configuration and setup
  4. Reorganization of documentation into multiple files for better maintainability

Possible Issues

  1. The text decoding changes in LineDecoder involve complex buffer manipulation which could introduce edge cases in multi-byte character handling
  2. The dependency on Cloudflare Workers tokens (.dev.vars) is hard-coded which could make local testing more difficult

Security Hotspots

  1. The token handling in ecosystem tests exposes credentials through environment variables which could potentially leak if not properly managed
Changes

Changes

By filename:

.github/workflows/ci.yml:

  • Added new ecosystem test job that runs tests using Node 20, Deno, and Bun

.gitignore:

  • Added .dev.vars for Cloudflare Workers development variables

src/lib/AssistantStream.ts:

  • Added support for 'thread.run.incomplete' event handling
  • Added type safety improvements

src/lib/LineDecoder.ts:

  • Complete rewrite of text chunk decoding logic to handle multi-byte characters correctly
  • Improved buffer management for streaming text

src/resources/chat/completions/:

  • Added new endpoints for stored chat completions (CRUD operations)
  • Split completions code into multiple files for better organization
  • Added new types for chat completion storage

Documentation:

  • Split README.md into multiple focused files (azure.md, realtime.md, helpers.md)
  • Improved documentation organization and readability
sequenceDiagram
    participant Client
    participant ChatCompletions
    participant LineDecoder
    participant Server

    Client->>ChatCompletions: Create completion request
    ChatCompletions->>Server: Send HTTP request
    Server-->>ChatCompletions: Stream response chunks
    loop For each chunk
        ChatCompletions->>LineDecoder: Process chunk
        LineDecoder-->>ChatCompletions: Decoded text
        ChatCompletions-->>Client: Emit completion event
    end
    ChatCompletions-->>Client: Complete stream
Loading

Copy link

bedrock debug - [puLL-Merge] - openai/[email protected]

Diff
diff --git .github/workflows/ci.yml .github/workflows/ci.yml
index d6798e38a..85d792c44 100644
--- .github/workflows/ci.yml
+++ .github/workflows/ci.yml
@@ -64,3 +64,36 @@ jobs:
 
       - name: Run tests
         run: ./scripts/test
+
+  ecosystem_tests:
+    name: ecosystem tests (v${{ matrix.node-version }})
+    runs-on: ubuntu-latest
+    if: github.repository == 'openai/openai-node'
+    timeout-minutes: 20
+    strategy:
+      fail-fast: false
+      matrix:
+        node-version: ['20']
+
+    steps:
+      - uses: actions/checkout@v4
+
+      - name: Set up Node
+        uses: actions/setup-node@v4
+        with:
+          node-version: '${{ matrix.node-version }}'
+
+      - uses: denoland/setup-deno@v1
+        with:
+          deno-version: v1.39.0
+
+      - uses: oven-sh/setup-bun@v2
+
+      - name: Bootstrap
+        run: ./scripts/bootstrap
+
+      - name: Run ecosystem tests
+        run: |
+          yarn tsn ecosystem-tests/cli.ts --live --verbose --parallel --jobs=4 --retry=3
+        env:
+          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
diff --git .gitignore .gitignore
index 81c4c41ca..3fdab1cb7 100644
--- .gitignore
+++ .gitignore
@@ -11,4 +11,4 @@ tmp
 .pack
 ecosystem-tests/deno/package.json
 ecosystem-tests/*/openai.tgz
-
+.dev.vars
diff --git .release-please-manifest.json .release-please-manifest.json
index 6eb0f130e..541794534 100644
--- .release-please-manifest.json
+++ .release-please-manifest.json
@@ -1,3 +1,3 @@
 {
-  ".": "4.83.0"
+  ".": "4.85.2"
 }
diff --git .stats.yml .stats.yml
index df7877dfd..658877d3b 100644
--- .stats.yml
+++ .stats.yml
@@ -1,2 +1,2 @@
-configured_endpoints: 69
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-fc5dbc19505b0035f9e7f88868619f4fb519b048bde011f6154f3132d4be71fb.yml
+configured_endpoints: 74
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-4aa6ee65ba9efc789e05e6a5ef0883b2cadf06def8efd863dbf75e9e233067e1.yml
diff --git CHANGELOG.md CHANGELOG.md
index f61def5e4..70a447b0a 100644
--- CHANGELOG.md
+++ CHANGELOG.md
@@ -1,5 +1,73 @@
 # Changelog
 
+## 4.85.2 (2025-02-18)
+
+Full Changelog: [v4.85.1...v4.85.2](https://github.com/openai/openai-node/compare/v4.85.1...v4.85.2)
+
+### Bug Fixes
+
+* optimize sse chunk reading off-by-one error ([#1339](https://github.com/openai/openai-node/issues/1339)) ([c82795b](https://github.com/openai/openai-node/commit/c82795b189c73d1c0e3bc3a40d0d4a2558b0483a))
+
+## 4.85.1 (2025-02-14)
+
+Full Changelog: [v4.85.0...v4.85.1](https://github.com/openai/openai-node/compare/v4.85.0...v4.85.1)
+
+### Bug Fixes
+
+* **client:** fix export map for index exports ([#1328](https://github.com/openai/openai-node/issues/1328)) ([647ba7a](https://github.com/openai/openai-node/commit/647ba7a52311928f604c72b2cc95698c0837887f))
+* **package:** add chat/completions.ts back in ([#1333](https://github.com/openai/openai-node/issues/1333)) ([e4b5546](https://github.com/openai/openai-node/commit/e4b554632ab1646da831f29413fefb3378c49cc1))
+
+
+### Chores
+
+* **internal:** add missing return type annotation ([#1334](https://github.com/openai/openai-node/issues/1334)) ([53e0856](https://github.com/openai/openai-node/commit/53e0856ec4d36deee4d71b5aaf436df0a59b9402))
+
+## 4.85.0 (2025-02-13)
+
+Full Changelog: [v4.84.1...v4.85.0](https://github.com/openai/openai-node/compare/v4.84.1...v4.85.0)
+
+### Features
+
+* **api:** add support for storing chat completions ([#1327](https://github.com/openai/openai-node/issues/1327)) ([8d77f8e](https://github.com/openai/openai-node/commit/8d77f8e3c4801b7fa1e7c6f50b48c1de1f43f3e6))
+
+
+### Bug Fixes
+
+* **realtime:** call .toString() on WebSocket url ([#1324](https://github.com/openai/openai-node/issues/1324)) ([09bc50d](https://github.com/openai/openai-node/commit/09bc50d439679b6acfd2441e69ee5aa18c00e5d9))
+
+## 4.84.1 (2025-02-13)
+
+Full Changelog: [v4.84.0...v4.84.1](https://github.com/openai/openai-node/compare/v4.84.0...v4.84.1)
+
+### Bug Fixes
+
+* **realtime:** correct websocket type var constraint ([#1321](https://github.com/openai/openai-node/issues/1321)) ([afb17ea](https://github.com/openai/openai-node/commit/afb17ea6497b860ebbe5d8e68e4a97681dd307ff))
+
+## 4.84.0 (2025-02-12)
+
+Full Changelog: [v4.83.0...v4.84.0](https://github.com/openai/openai-node/compare/v4.83.0...v4.84.0)
+
+### Features
+
+* **pagination:** avoid fetching when has_more: false ([#1305](https://github.com/openai/openai-node/issues/1305)) ([b6944c6](https://github.com/openai/openai-node/commit/b6944c634b53c9084f2ccf777c2491e89b2cc7af))
+
+
+### Bug Fixes
+
+* **api:** add missing reasoning effort + model enums ([#1302](https://github.com/openai/openai-node/issues/1302)) ([14c55c3](https://github.com/openai/openai-node/commit/14c55c312e31f1ed46d02f39a99049f785504a53))
+* **assistants:** handle `thread.run.incomplete` event ([7032cc4](https://github.com/openai/openai-node/commit/7032cc40b8aa0a58459cf114bceb8028a8517400))
+* correctly decode multi-byte characters over multiple chunks ([#1316](https://github.com/openai/openai-node/issues/1316)) ([dd776c4](https://github.com/openai/openai-node/commit/dd776c4867401f527f699bd4b9e567890256e849))
+
+
+### Chores
+
+* **internal:** remove segfault-handler dependency ([3521ca3](https://github.com/openai/openai-node/commit/3521ca34e7f5bd51542084e27c084a5d7cc5448b))
+
+
+### Documentation
+
+* **readme:** cleanup into multiple files ([da94424](https://github.com/openai/openai-node/commit/da944242e542e9e5e51cb11853c621fc6825ac02))
+
 ## 4.83.0 (2025-02-05)
 
 Full Changelog: [v4.82.0...v4.83.0](https://github.com/openai/openai-node/compare/v4.82.0...v4.83.0)
diff --git README.md README.md
index a1f4bf760..166e35e22 100644
--- README.md
+++ README.md
@@ -40,7 +40,7 @@ import OpenAI from 'jsr:@openai/openai';
 The full API of this library can be found in [api.md file](api.md) along with many [code examples](https://github.com/openai/openai-node/tree/master/examples). The code below shows how to get started using the chat completions API.
 
 <!-- prettier-ignore -->
-\`\`\`js
+```ts
 import OpenAI from 'openai';
 
 const client = new OpenAI({
@@ -80,189 +80,11 @@ async function main() {
 main();

-If you need to cancel a stream, you can break from the loop
-or call stream.controller.abort().

-## Realtime API beta

-The Realtime API enables you to build low-latency, multi-modal conversational experiences. It currently supports text and audio as both input and output, as well as function calling through a WebSocket connection.

-The Realtime API works through a combination of client-sent events and server-sent events. Clients can send events to do things like update session configuration or send text and audio inputs. Server events confirm when audio responses have completed, or when a text response from the model has been received. A full event reference can be found here and a guide can be found here.

-This SDK supports accessing the Realtime API through the WebSocket API or with ws.

-Basic text based example with ws:

-```ts
-// requires yarn add ws @types/ws
-import { OpenAIRealtimeWS } from 'openai/beta/realtime/ws';

-const rt = new OpenAIRealtimeWS({ model: 'gpt-4o-realtime-preview-2024-12-17' });

-// access the underlying ws.WebSocket instance
-rt.socket.on('open', () => {

  • console.log('Connection opened!');
  • rt.send({
  • type: 'session.update',
  • session: {
  •  modalities: ['text'],
    
  •  model: 'gpt-4o-realtime-preview',
    
  • },
  • });
  • rt.send({
  • type: 'conversation.item.create',
  • item: {
  •  type: 'message',
    
  •  role: 'user',
    
  •  content: [{ type: 'input_text', text: 'Say a couple paragraphs!' }],
    
  • },
  • });
  • rt.send({ type: 'response.create' });
    -});

-rt.on('error', (err) => {

  • // in a real world scenario this should be logged somewhere as you
  • // likely want to continue procesing events regardless of any errors
  • throw err;
    -});

-rt.on('session.created', (event) => {

  • console.log('session created!', event.session);
  • console.log();
    -});

-rt.on('response.text.delta', (event) => process.stdout.write(event.delta));
-rt.on('response.text.done', () => console.log());

-rt.on('response.done', () => rt.close());

-rt.socket.on('close', () => console.log('\nConnection closed!'));
-```

-To use the web API WebSocket implementation, replace OpenAIRealtimeWS with OpenAIRealtimeWebSocket and adjust any rt.socket access:

-```ts
-import { OpenAIRealtimeWebSocket } from 'openai/beta/realtime/websocket';

-const rt = new OpenAIRealtimeWebSocket({ model: 'gpt-4o-realtime-preview-2024-12-17' });
-// ...
-rt.socket.addEventListener('open', () => {

  • // ...
    -});
    -```

-A full example can be found here.

-### Realtime error handling

-When an error is encountered, either on the client side or returned from the server through the error event, the error event listener will be fired. However, if you haven't registered an error event listener then an unhandled Promise rejection error will be thrown.

-It is highly recommended that you register an error event listener and handle errors approriately as typically the underlying connection is still usable.

-```ts
-const rt = new OpenAIRealtimeWS({ model: 'gpt-4o-realtime-preview-2024-12-17' });
-rt.on('error', (err) => {

  • // in a real world scenario this should be logged somewhere as you
  • // likely want to continue procesing events regardless of any errors
  • throw err;
    -});
    -```

-### Request & Response types

-This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:

-
-```ts
-import OpenAI from 'openai';

-const client = new OpenAI({

  • apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
    -});

-async function main() {

  • const params: OpenAI.Chat.ChatCompletionCreateParams = {
  • messages: [{ role: 'user', content: 'Say this is a test' }],
  • model: 'gpt-4o',
  • };
  • const chatCompletion: OpenAI.Chat.ChatCompletion = await client.chat.completions.create(params);
    -}

-main();
-```

-Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.

-> [!IMPORTANT]
-> Previous versions of this SDK used a Configuration class. See the v3 to v4 migration guide.

-### Polling Helpers

-When interacting with the API some actions such as starting a Run and adding files to vector stores are asynchronous and take time to complete. The SDK includes
-helper functions which will poll the status until it reaches a terminal state and then return the resulting object.
-If an API method results in an action which could benefit from polling there will be a corresponding version of the
-method ending in 'AndPoll'.

-For instance to create a Run and poll until it reaches a terminal state you can run:

-```ts
-const run = await openai.beta.threads.runs.createAndPoll(thread.id, {

  • assistant_id: assistantId,
    -});
    -```

-More information on the lifecycle of a Run can be found in the Run Lifecycle Documentation

-### Bulk Upload Helpers

-When creating and interacting with vector stores, you can use the polling helpers to monitor the status of operations.
-For convenience, we also provide a bulk upload helper to allow you to simultaneously upload several files at once.

-```ts
-const fileList = [

  • createReadStream('/home/data/example.pdf'),
  • ...
    -];

-const batch = await openai.vectorStores.fileBatches.uploadAndPoll(vectorStore.id, {files: fileList});
-```

-### Streaming Helpers

-The SDK also includes helpers to process streams and handle the incoming events.

-```ts
-const run = openai.beta.threads.runs

  • .stream(thread.id, {
  • assistant_id: assistant.id,
  • })
  • .on('textCreated', (text) => process.stdout.write('\nassistant > '))
  • .on('textDelta', (textDelta, snapshot) => process.stdout.write(textDelta.value))
  • .on('toolCallCreated', (toolCall) => process.stdout.write(\nassistant > ${toolCall.type}\n\n))
  • .on('toolCallDelta', (toolCallDelta, snapshot) => {
  • if (toolCallDelta.type === 'code_interpreter') {
  •  if (toolCallDelta.code_interpreter.input) {
    
  •    process.stdout.write(toolCallDelta.code_interpreter.input);
    
  •  }
    
  •  if (toolCallDelta.code_interpreter.outputs) {
    
  •    process.stdout.write('\noutput >\n');
    
  •    toolCallDelta.code_interpreter.outputs.forEach((output) => {
    
  •      if (output.type === 'logs') {
    
  •        process.stdout.write(`\n${output.logs}\n`);
    
  •      }
    
  •    });
    
  •  }
    
  • }
  • });
    -```

-More information on streaming helpers can be found in the dedicated documentation: helpers.md
+If you need to cancel a stream, you can break from the loop or call stream.controller.abort().

-### Streaming responses
+### Chat Completion streaming helpers

-This library provides several conveniences for streaming chat completions, for example:
+This library also provides several conveniences for streaming chat completions, for example:

import OpenAI from 'openai';
@@ -292,98 +114,32 @@ async function main() {
main();

-Streaming with openai.beta.chat.completions.stream({…}) exposes
-various helpers for your convenience including event handlers and promises.

-Alternatively, you can use openai.chat.completions.create({ stream: true, … })
-which only returns an async iterable of the chunks in the stream and thus uses less memory
-(it does not build up a final chat completion object for you).

-If you need to cancel a stream, you can break from a for await loop or call stream.abort().

-### Automated function calls
+See helpers.md for more details.

-We provide the openai.beta.chat.completions.runTools({…})
-convenience helper for using function tool calls with the /chat/completions endpoint
-which automatically call the JavaScript functions you provide
-and sends their results back to the /chat/completions endpoint,
-looping as long as the model requests tool calls.

-If you pass a parse function, it will automatically parse the arguments for you
-and returns any parsing errors to the model to attempt auto-recovery.
-Otherwise, the args will be passed to the function you provide as a string.
+### Request & Response types

-If you pass tool_choice: {function: {name: …}} instead of auto,
-it returns immediately after calling that function (and only loops to auto-recover parsing errors).
+This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:

+

import OpenAI from 'openai';

-const client = new OpenAI();
+const client = new OpenAI({
+  apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
+});

async function main() {
-  const runner = client.beta.chat.completions
-    .runTools({
-      model: 'gpt-4o',
-      messages: [{ role: 'user', content: 'How is the weather this week?' }],
-      tools: [
-        {
-          type: 'function',
-          function: {
-            function: getCurrentLocation,
-            parameters: { type: 'object', properties: {} },
-          },
-        },
-        {
-          type: 'function',
-          function: {
-            function: getWeather,
-            parse: JSON.parse, // or use a validation library like zod for typesafe parsing.
-            parameters: {
-              type: 'object',
-              properties: {
-                location: { type: 'string' },
-              },
-            },
-          },
-        },
-      ],
-    })
-    .on('message', (message) => console.log(message));
-
-  const finalContent = await runner.finalContent();
-  console.log();
-  console.log('Final content:', finalContent);
-}
-
-async function getCurrentLocation() {
-  return 'Boston'; // Simulate lookup
-}
-
-async function getWeather(args: { location: string }) {
-  const { location } = args;
-  // … do lookup …
-  return { temperature, precipitation };
+  const params: OpenAI.Chat.ChatCompletionCreateParams = {
+    messages: [{ role: 'user', content: 'Say this is a test' }],
+    model: 'gpt-4o',
+  };
+  const chatCompletion: OpenAI.Chat.ChatCompletion = await client.chat.completions.create(params);
}

main();
-
-// {role: "user",      content: "How's the weather this week?"}
-// {role: "assistant", tool_calls: [{type: "function", function: {name: "getCurrentLocation", arguments: "{}"}, id: "123"}
-// {role: "tool",      name: "getCurrentLocation", content: "Boston", tool_call_id: "123"}
-// {role: "assistant", tool_calls: [{type: "function", function: {name: "getWeather", arguments: '{"location": "Boston"}'}, id: "1234"}]}
-// {role: "tool",      name: "getWeather", content: '{"temperature": "50degF", "preciptation": "high"}', tool_call_id: "1234"}
-// {role: "assistant", content: "It's looking cold and rainy - you might want to wear a jacket!"}
-//
-// Final content: "It's looking cold and rainy - you might want to wear a jacket!"

-Like with .stream(), we provide a variety of helpers and events.

-Note that runFunctions was previously available as well, but has been deprecated in favor of runTools.

-Read more about various examples such as with integrating with zod,
-next.js, and proxying a stream to the browser.
+Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.

File uploads

@@ -434,6 +190,7 @@ async function main() {
.create({ model: 'gpt-4o', training_file: 'file-abc123' })
.catch(async (err) => {
if (err instanceof OpenAI.APIError) {

  •    console.log(err.request_id);
       console.log(err.status); // 400
       console.log(err.name); // BadRequestError
       console.log(err.headers); // {server: 'nginx', ...}
    

@@ -459,76 +216,6 @@ Error codes are as followed:
| >=500 | InternalServerError |
| N/A | APIConnectionError |

-## Request IDs

-> For more information on debugging requests, see these docs

-All object responses in the SDK provide a _request_id property which is added from the x-request-id response header so that you can quickly log failing requests and report them back to OpenAI.

-ts -const completion = await client.chat.completions.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-4o' }); -console.log(completion._request_id) // req_123 -

-You can also access the Request ID using the .withResponse() method:

-```ts
-const { data: stream, request_id } = await openai.chat.completions

  • .create({
  • model: 'gpt-4',
  • messages: [{ role: 'user', content: 'Say this is a test' }],
  • stream: true,
  • })
  • .withResponse();
    -```

-## Microsoft Azure OpenAI

-To use this library with Azure OpenAI, use the AzureOpenAI
-class instead of the OpenAI class.

-> [!IMPORTANT]
-> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params
-> won't always be correct.

-```ts
-import { AzureOpenAI } from 'openai';
-import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';

-const credential = new DefaultAzureCredential();
-const scope = 'https://cognitiveservices.azure.com/.default';
-const azureADTokenProvider = getBearerTokenProvider(credential, scope);

-const openai = new AzureOpenAI({ azureADTokenProvider, apiVersion: "<The API version, e.g. 2024-10-01-preview>" });

-const result = await openai.chat.completions.create({

  • model: 'gpt-4o',
  • messages: [{ role: 'user', content: 'Say hello!' }],
    -});

-console.log(result.choices[0]!.message?.content);
-```

-### Realtime API
-This SDK provides real-time streaming capabilities for Azure OpenAI through the OpenAIRealtimeWS and OpenAIRealtimeWebSocket clients described previously.

-To utilize the real-time features, begin by creating a fully configured AzureOpenAI client and passing it into either OpenAIRealtimeWS.azure or OpenAIRealtimeWebSocket.azure. For example:

-```ts
-const cred = new DefaultAzureCredential();
-const scope = 'https://cognitiveservices.azure.com/.default';
-const deploymentName = 'gpt-4o-realtime-preview-1001';
-const azureADTokenProvider = getBearerTokenProvider(cred, scope);
-const client = new AzureOpenAI({

  • azureADTokenProvider,
  • apiVersion: '2024-10-01-preview',
  • deployment: deploymentName,
    -});
    -const rt = await OpenAIRealtimeWS.azure(client);
    -```

-Once the instance has been created, you can then begin sending requests and receiving streaming responses in real time.

Retries

Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
@@ -571,6 +258,29 @@ On timeout, an APIConnectionTimeoutError is thrown.

Note that requests which time out will be retried twice by default.

+## Request IDs
+
+> For more information on debugging requests, see these docs
+
+All object responses in the SDK provide a _request_id property which is added from the x-request-id response header so that you can quickly log failing requests and report them back to OpenAI.
+
+ts +const completion = await client.chat.completions.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-4o' }); +console.log(completion._request_id) // req_123 +
+
+You can also access the Request ID using the .withResponse() method:
+
+```ts
+const { data: stream, request_id } = await openai.chat.completions

  • .create({
  • model: 'gpt-4',
  • messages: [{ role: 'user', content: 'Say this is a test' }],
  • stream: true,
  • })
  • .withResponse();
    +```

Auto-pagination

List methods in the OpenAI API are paginated.
@@ -602,6 +312,55 @@ while (page.hasNextPage()) {
}


+## Realtime API Beta
+
+The Realtime API enables you to build low-latency, multi-modal conversational experiences. It currently supports text and audio as both input and output, as well as [function calling](https://platform.openai.com/docs/guides/function-calling) through a `WebSocket` connection.
+
+```ts
+import { OpenAIRealtimeWebSocket } from 'openai/beta/realtime/websocket';
+
+const rt = new OpenAIRealtimeWebSocket({ model: 'gpt-4o-realtime-preview-2024-12-17' });
+
+rt.on('response.text.delta', (event) => process.stdout.write(event.delta));
+```
+
+For more information see [realtime.md](realtime.md).
+
+## Microsoft Azure OpenAI
+
+To use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the `AzureOpenAI`
+class instead of the `OpenAI` class.
+
+> [!IMPORTANT]
+> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params
+> won't always be correct.
+
+```ts
+import { AzureOpenAI } from 'openai';
+import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';
+
+const credential = new DefaultAzureCredential();
+const scope = 'https://cognitiveservices.azure.com/.default';
+const azureADTokenProvider = getBearerTokenProvider(credential, scope);
+
+const openai = new AzureOpenAI({ azureADTokenProvider, apiVersion: "<The API version, e.g. 2024-10-01-preview>" });
+
+const result = await openai.chat.completions.create({
+  model: 'gpt-4o',
+  messages: [{ role: 'user', content: 'Say hello!' }],
+});
+
+console.log(result.choices[0]!.message?.content);
+```
+
+For more information on support for the Azure API, see [azure.md](azure.md).
+
+## Automated function calls
+
+We provide the `openai.beta.chat.completions.runTools({…})` convenience helper for using function tool calls with the `/chat/completions` endpoint which automatically call the JavaScript functions you provide and sends their results back to the `/chat/completions` endpoint, looping as long as the model requests tool calls.
+
+For more information see [helpers.md](helpers.md#automated-function-calls).
+
## Advanced Usage

### Accessing raw Response data (e.g., headers)
diff --git api.md api.md
index 01854a8e0..63f239628 100644
--- api.md
+++ api.md
@@ -32,39 +32,51 @@ Types:

Types:

-- <code><a href="./src/resources/chat/completions.ts">ChatCompletion</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionAssistantMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionAudio</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionAudioParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionChunk</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPart</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPartImage</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPartInputAudio</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPartRefusal</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPartText</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionDeveloperMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionFunctionCallOption</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionFunctionMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionMessage</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionMessageToolCall</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionModality</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionNamedToolChoice</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionPredictionContent</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionReasoningEffort</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionRole</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionStreamOptions</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionSystemMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionTokenLogprob</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionTool</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionToolChoiceOption</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionToolMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionUserMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">CreateChatCompletionRequestMessage</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletion</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionAssistantMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionAudio</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionAudioParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionChunk</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPart</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPartImage</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPartInputAudio</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPartRefusal</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPartText</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionDeleted</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionDeveloperMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionFunctionCallOption</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionFunctionMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionMessage</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionMessageToolCall</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionModality</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionNamedToolChoice</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionPredictionContent</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionReasoningEffort</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionRole</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionStoreMessage</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionStreamOptions</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionSystemMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionTokenLogprob</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionTool</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionToolChoiceOption</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionToolMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionUserMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">CreateChatCompletionRequestMessage</a></code>

Methods:

-- <code title="post /chat/completions">client.chat.completions.<a href="./src/resources/chat/completions.ts">create</a>({ ...params }) -> ChatCompletion</code>
+- <code title="post /chat/completions">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">create</a>({ ...params }) -> ChatCompletion</code>
+- <code title="get /chat/completions/{completion_id}">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">retrieve</a>(completionId) -> ChatCompletion</code>
+- <code title="post /chat/completions/{completion_id}">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">update</a>(completionId, { ...params }) -> ChatCompletion</code>
+- <code title="get /chat/completions">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">list</a>({ ...params }) -> ChatCompletionsPage</code>
+- <code title="delete /chat/completions/{completion_id}">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">del</a>(completionId) -> ChatCompletionDeleted</code>
+
+### Messages
+
+Methods:
+
+- <code title="get /chat/completions/{completion_id}/messages">client.chat.completions.messages.<a href="./src/resources/chat/completions/messages.ts">list</a>(completionId, { ...params }) -> ChatCompletionStoreMessagesPage</code>

# Embeddings

diff --git a/azure.md b/azure.md
new file mode 100644
index 000000000..df06c2985
--- /dev/null
+++ azure.md
@@ -0,0 +1,49 @@
+# Microsoft Azure OpenAI
+
+To use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the `AzureOpenAI`
+class instead of the `OpenAI` class.
+
+> [!IMPORTANT]
+> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params
+> won't always be correct.
+
+```ts
+import { AzureOpenAI } from 'openai';
+import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';
+
+const credential = new DefaultAzureCredential();
+const scope = 'https://cognitiveservices.azure.com/.default';
+const azureADTokenProvider = getBearerTokenProvider(credential, scope);
+
+const openai = new AzureOpenAI({ azureADTokenProvider, apiVersion: "<The API version, e.g. 2024-10-01-preview>" });
+
+const result = await openai.chat.completions.create({
+  model: 'gpt-4o',
+  messages: [{ role: 'user', content: 'Say hello!' }],
+});
+
+console.log(result.choices[0]!.message?.content);
+```
+
+For more information on support for the Azure API, see [azure.md](azure.md).
+
+## Realtime API
+
+This SDK provides real-time streaming capabilities for Azure OpenAI through the `OpenAIRealtimeWS` and `OpenAIRealtimeWebSocket` clients described previously.
+
+To utilize the real-time features, begin by creating a fully configured `AzureOpenAI` client and passing it into either `OpenAIRealtimeWS.azure` or `OpenAIRealtimeWebSocket.azure`. For example:
+
+```ts
+const cred = new DefaultAzureCredential();
+const scope = 'https://cognitiveservices.azure.com/.default';
+const deploymentName = 'gpt-4o-realtime-preview-1001';
+const azureADTokenProvider = getBearerTokenProvider(cred, scope);
+const client = new AzureOpenAI({
+  azureADTokenProvider,
+  apiVersion: '2024-10-01-preview',
+  deployment: deploymentName,
+});
+const rt = await OpenAIRealtimeWS.azure(client);
+```
+
+Once the instance has been created, you can then begin sending requests and receiving streaming responses in real time.
diff --git ecosystem-tests/cli.ts ecosystem-tests/cli.ts
index 00120e5f9..77faddec5 100644
--- ecosystem-tests/cli.ts
+++ ecosystem-tests/cli.ts
@@ -4,10 +4,6 @@ import yargs from 'yargs';
import assert from 'assert';
import path from 'path';

-// @ts-ignore
-var SegfaultHandler = require('segfault-handler');
-SegfaultHandler.registerHandler('crash.log');
-
const TAR_NAME = 'openai.tgz';
const PACK_FOLDER = '.pack';
const PACK_FILE = `${PACK_FOLDER}/${TAR_NAME}`;
@@ -74,6 +70,7 @@ const projectRunners = {
  'cloudflare-worker': async () => {
    await installPackage();

+    await fs.writeFile('.dev.vars', `OPENAI_API_KEY='${process.env['OPENAI_API_KEY']}'`);
    await run('npm', ['run', 'tsc']);

    if (state.live) {
diff --git helpers.md helpers.md
index 16bc1f277..41b352e5e 100644
--- helpers.md
+++ helpers.md
@@ -142,9 +142,7 @@ More information can be found in the documentation: [Assistant Streaming](https:

```ts
const run = openai.beta.threads.runs
-  .stream(thread.id, {
-    assistant_id: assistant.id,
-  })
+  .stream(thread.id, { assistant_id: assistant.id })
  .on('textCreated', (text) => process.stdout.write('\nassistant > '))
  .on('textDelta', (textDelta, snapshot) => process.stdout.write(textDelta.value))
  .on('toolCallCreated', (toolCall) => process.stdout.write(`\nassistant > ${toolCall.type}\n\n`))
@@ -304,47 +302,87 @@ If you need to cancel a stream, you can `break` from a `for await` loop or call

See an example of streaming helpers in action in [`examples/stream.ts`](examples/stream.ts).

-### Automated Function Calls
+### Automated function calls

-```ts
-openai.chat.completions.runTools({ stream: false, … }, options?): ChatCompletionRunner
-openai.chat.completions.runTools({ stream: true, … }, options?): ChatCompletionStreamingRunner
-```
+We provide the `openai.beta.chat.completions.runTools({…})`
+convenience helper for using function tool calls with the `/chat/completions` endpoint
+which automatically call the JavaScript functions you provide
+and sends their results back to the `/chat/completions` endpoint,
+looping as long as the model requests tool calls.

-`openai.chat.completions.runTools()` returns a Runner
-for automating function calls with chat completions.
-The runner automatically calls the JavaScript functions you provide and sends their results back
-to the API, looping as long as the model requests function calls.
+If you pass a `parse` function, it will automatically parse the `arguments` for you
+and returns any parsing errors to the model to attempt auto-recovery.
+Otherwise, the args will be passed to the function you provide as a string.

-If you pass a `parse` function, it will automatically parse the `arguments` for you and returns any parsing
-errors to the model to attempt auto-recovery. Otherwise, the args will be passed to the function you provide
-as a string.
+If you pass `tool_choice: {function: {name: …}}` instead of `auto`,
+it returns immediately after calling that function (and only loops to auto-recover parsing errors).

```ts
-client.chat.completions.runTools({
-  model: 'gpt-3.5-turbo',
-  messages: [{ role: 'user', content: 'How is the weather this week?' }],
-  tools: [
-    {
-      type: 'function',
-      function: {
-        function: getWeather as (args: { location: string; time: Date }) => any,
-        parse: parseFunction as (args: strings) => { location: string; time: Date },
-        parameters: {
-          type: 'object',
-          properties: {
-            location: { type: 'string' },
-            time: { type: 'string', format: 'date-time' },
+import OpenAI from 'openai';
+
+const client = new OpenAI();
+
+async function main() {
+  const runner = client.beta.chat.completions
+    .runTools({
+      model: 'gpt-4o',
+      messages: [{ role: 'user', content: 'How is the weather this week?' }],
+      tools: [
+        {
+          type: 'function',
+          function: {
+            function: getCurrentLocation,
+            parameters: { type: 'object', properties: {} },
          },
        },
-      },
-    },
-  ],
-});
+        {
+          type: 'function',
+          function: {
+            function: getWeather,
+            parse: JSON.parse, // or use a validation library like zod for typesafe parsing.
+            parameters: {
+              type: 'object',
+              properties: {
+                location: { type: 'string' },
+              },
+            },
+          },
+        },
+      ],
+    })
+    .on('message', (message) => console.log(message));
+
+  const finalContent = await runner.finalContent();
+  console.log();
+  console.log('Final content:', finalContent);
+}
+
+async function getCurrentLocation() {
+  return 'Boston'; // Simulate lookup
+}
+
+async function getWeather(args: { location: string }) {
+  const { location } = args;
+  // … do lookup …
+  return { temperature, precipitation };
+}
+
+main();
+
+// {role: "user",      content: "How's the weather this week?"}
+// {role: "assistant", tool_calls: [{type: "function", function: {name: "getCurrentLocation", arguments: "{}"}, id: "123"}
+// {role: "tool",      name: "getCurrentLocation", content: "Boston", tool_call_id: "123"}
+// {role: "assistant", tool_calls: [{type: "function", function: {name: "getWeather", arguments: '{"location": "Boston"}'}, id: "1234"}]}
+// {role: "tool",      name: "getWeather", content: '{"temperature": "50degF", "preciptation": "high"}', tool_call_id: "1234"}
+// {role: "assistant", content: "It's looking cold and rainy - you might want to wear a jacket!"}
+//
+// Final content: "It's looking cold and rainy - you might want to wear a jacket!"

-If you pass function_call: {name: …} instead of auto, it returns immediately after calling that
-function (and only loops to auto-recover parsing errors).
+Like with .stream(), we provide a variety of helpers and events.
+
+Read more about various examples such as with integrating with zod,
+next.js, and proxying a stream to the browser.

By default, we run the loop up to 10 chat completions from the API. You can change this behavior by
adjusting maxChatCompletions in the request options object. Note that max_tokens is the limit per
@@ -662,3 +700,17 @@ client.beta.vectorStores.files.createAndPoll((...)
client.beta.vectorStores.fileBatches.createAndPoll((...)
client.beta.vectorStores.fileBatches.uploadAndPoll((...)

+
+# Bulk Upload Helpers
+
+When creating and interacting with vector stores, you can use the polling helpers to monitor the status of operations.
+For convenience, we also provide a bulk upload helper to allow you to simultaneously upload several files at once.
+
+```ts
+const fileList = [
+  createReadStream('/home/data/example.pdf'),
+  ...
+];
+
+const batch = await openai.vectorStores.fileBatches.uploadAndPoll(vectorStore.id, {files: fileList});
+```
diff --git jsr.json jsr.json
index 6fa05e624..8f83c0ff2 100644
--- jsr.json
+++ jsr.json
@@ -1,6 +1,6 @@
{
  "name": "@openai/openai",
-  "version": "4.83.0",
+  "version": "4.85.2",
  "exports": {
    ".": "./index.ts",
    "./helpers/zod": "./helpers/zod.ts",
diff --git package.json package.json
index bd507e9f8..661bc2938 100644
--- package.json
+++ package.json
@@ -1,6 +1,6 @@
{
  "name": "openai",
-  "version": "4.83.0",
+  "version": "4.85.2",
  "description": "The official TypeScript library for the OpenAI API",
  "author": "OpenAI <[email protected]>",
  "types": "dist/index.d.ts",
@@ -47,7 +47,6 @@
    "jest": "^29.4.0",
    "prettier": "^3.0.0",
    "prettier-2": "npm:prettier@^2",
-    "segfault-handler": "^1.3.0",
    "ts-jest": "^29.1.0",
    "ts-node": "^10.5.0",
    "tsc-multi": "^1.1.0",
@@ -113,17 +112,38 @@
      "default": "./dist/index.mjs"
    },
    "./*.mjs": {
-      "types": "./dist/*.d.ts",
-      "default": "./dist/*.mjs"
+      "types": [
+        "./dist/*.d.ts",
+        "./dist/*/index.d.ts"
+      ],
+      "default": [
+        "./dist/*.mjs",
+        "./dist/*/index.mjs"
+      ]
    },
    "./*.js": {
-      "types": "./dist/*.d.ts",
-      "default": "./dist/*.js"
+      "types": [
+        "./dist/*.d.ts",
+        "./dist/*/index.d.ts"
+      ],
+      "default": [
+        "./dist/*.js",
+        "./dist/*/index.js"
+      ]
    },
    "./*": {
-      "types": "./dist/*.d.ts",
-      "require": "./dist/*.js",
-      "default": "./dist/*.mjs"
+      "types": [
+        "./dist/*.d.ts",
+        "./dist/*/index.d.ts"
+      ],
+      "require": [
+        "./dist/*.js",
+        "./dist/*/index.js"
+      ],
+      "default": [
+        "./dist/*.mjs",
+        "./dist/*/index.mjs"
+      ]
    }
  },
  "bin": "./bin/cli",
diff --git a/realtime.md b/realtime.md
new file mode 100644
index 000000000..2fcd17e9e
--- /dev/null
+++ realtime.md
@@ -0,0 +1,87 @@
+## Realtime API beta
+
+The Realtime API enables you to build low-latency, multi-modal conversational experiences. It currently supports text and audio as both input and output, as well as [function calling](https://platform.openai.com/docs/guides/function-calling) through a `WebSocket` connection.
+
+The Realtime API works through a combination of client-sent events and server-sent events. Clients can send events to do things like update session configuration or send text and audio inputs. Server events confirm when audio responses have completed, or when a text response from the model has been received. A full event reference can be found [here](https://platform.openai.com/docs/api-reference/realtime-client-events) and a guide can be found [here](https://platform.openai.com/docs/guides/realtime).
+
+This SDK supports accessing the Realtime API through the [WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) or with [ws](https://github.com/websockets/ws).
+
+Basic text based example with `ws`:
+
+```ts
+// requires `yarn add ws @types/ws`
+import { OpenAIRealtimeWS } from 'openai/beta/realtime/ws';
+
+const rt = new OpenAIRealtimeWS({ model: 'gpt-4o-realtime-preview-2024-12-17' });
+
+// access the underlying `ws.WebSocket` instance
+rt.socket.on('open', () => {
+  console.log('Connection opened!');
+  rt.send({
+    type: 'session.update',
+    session: {
+      modalities: ['text'],
+      model: 'gpt-4o-realtime-preview',
+    },
+  });
+
+  rt.send({
+    type: 'conversation.item.create',
+    item: {
+      type: 'message',
+      role: 'user',
+      content: [{ type: 'input_text', text: 'Say a couple paragraphs!' }],
+    },
+  });
+
+  rt.send({ type: 'response.create' });
+});
+
+rt.on('error', (err) => {
+  // in a real world scenario this should be logged somewhere as you
+  // likely want to continue procesing events regardless of any errors
+  throw err;
+});
+
+rt.on('session.created', (event) => {
+  console.log('session created!', event.session);
+  console.log();
+});
+
+rt.on('response.text.delta', (event) => process.stdout.write(event.delta));
+rt.on('response.text.done', () => console.log());
+
+rt.on('response.done', () => rt.close());
+
+rt.socket.on('close', () => console.log('\nConnection closed!'));
+```
+
+To use the web API `WebSocket` implementation, replace `OpenAIRealtimeWS` with `OpenAIRealtimeWebSocket` and adjust any `rt.socket` access:
+
+```ts
+import { OpenAIRealtimeWebSocket } from 'openai/beta/realtime/websocket';
+
+const rt = new OpenAIRealtimeWebSocket({ model: 'gpt-4o-realtime-preview-2024-12-17' });
+// ...
+rt.socket.addEventListener('open', () => {
+ // ...
+});
+```
+
+A full example can be found [here](https://github.com/openai/openai-node/blob/master/examples/realtime/websocket.ts).
+
+### Realtime error handling
+
+When an error is encountered, either on the client side or returned from the server through the [`error` event](https://platform.openai.com/docs/guides/realtime-model-capabilities#error-handling), the `error` event listener will be fired. However, if you haven't registered an `error` event listener then an `unhandled Promise rejection` error will be thrown.
+
+It is **highly recommended** that you register an `error` event listener and handle errors approriately as typically the underlying connection is still usable.
+
+```ts
+const rt = new OpenAIRealtimeWS({ model: 'gpt-4o-realtime-preview-2024-12-17' });
+rt.on('error', (err) => {
+  // in a real world scenario this should be logged somewhere as you
+  // likely want to continue procesing events regardless of any errors
+  throw err;
+});
+```
+
diff --git src/beta/realtime/websocket.ts src/beta/realtime/websocket.ts
index 349cf5760..e8900e809 100644
--- src/beta/realtime/websocket.ts
+++ src/beta/realtime/websocket.ts
@@ -11,7 +11,7 @@ interface MessageEvent {
type _WebSocket =
  typeof globalThis extends (
    {
-      WebSocket: infer ws;
+      WebSocket: infer ws extends abstract new (...args: any) => any;
    }
  ) ?
    // @ts-ignore
@@ -53,7 +53,7 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
    props.onURL?.(this.url);

    // @ts-ignore
-    this.socket = new WebSocket(this.url, [
+    this.socket = new WebSocket(this.url.toString(), [
      'realtime',
      ...(isAzure(client) ? [] : [`openai-insecure-api-key.${client.apiKey}`]),
      'openai-beta.realtime-v1',
@@ -95,7 +95,7 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
  }

  static async azure(
-    client: AzureOpenAI,
+    client: Pick<AzureOpenAI, '_getAzureADToken' | 'apiVersion' | 'apiKey' | 'baseURL' | 'deploymentName'>,
    options: { deploymentName?: string; dangerouslyAllowBrowser?: boolean } = {},
  ): Promise<OpenAIRealtimeWebSocket> {
    const token = await client._getAzureADToken();
diff --git src/beta/realtime/ws.ts src/beta/realtime/ws.ts
index 51339089c..3f51dfc4b 100644
--- src/beta/realtime/ws.ts
+++ src/beta/realtime/ws.ts
@@ -52,7 +52,7 @@ export class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {
  }

  static async azure(
-    client: AzureOpenAI,
+    client: Pick<AzureOpenAI, '_getAzureADToken' | 'apiVersion' | 'apiKey' | 'baseURL' | 'deploymentName'>,
    options: { deploymentName?: string; options?: WS.ClientOptions | undefined } = {},
  ): Promise<OpenAIRealtimeWS> {
    const deploymentName = options.deploymentName ?? client.deploymentName;
@@ -82,7 +82,7 @@ export class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {
  }
}

-async function getAzureHeaders(client: AzureOpenAI) {
+async function getAzureHeaders(client: Pick<AzureOpenAI, '_getAzureADToken' | 'apiKey'>) {
  if (client.apiKey !== '<Missing Key>') {
    return { 'api-key': client.apiKey };
  } else {
diff --git src/index.ts src/index.ts
index f4e940af8..debefce8c 100644
--- src/index.ts
+++ src/index.ts
@@ -66,6 +66,13 @@ import {
import { Audio, AudioModel, AudioResponseFormat } from './resources/audio/audio';
import { Beta } from './resources/beta/beta';
import { Chat, ChatModel } from './resources/chat/chat';
+import { FineTuning } from './resources/fine-tuning/fine-tuning';
+import {
+  Upload,
+  UploadCompleteParams,
+  UploadCreateParams,
+  Uploads as UploadsAPIUploads,
+} from './resources/uploads/uploads';
import {
  ChatCompletion,
  ChatCompletionAssistantMessageParam,
@@ -80,9 +87,11 @@ import {
  ChatCompletionCreateParams,
  ChatCompletionCreateParamsNonStreaming,
  ChatCompletionCreateParamsStreaming,
+  ChatCompletionDeleted,
  ChatCompletionDeveloperMessageParam,
  ChatCompletionFunctionCallOption,
  ChatCompletionFunctionMessageParam,
+  ChatCompletionListParams,
  ChatCompletionMessage,
  ChatCompletionMessageParam,
  ChatCompletionMessageToolCall,
@@ -91,21 +100,17 @@ import {
  ChatCompletionPredictionContent,
  ChatCompletionReasoningEffort,
  ChatCompletionRole,
+  ChatCompletionStoreMessage,
  ChatCompletionStreamOptions,
  ChatCompletionSystemMessageParam,
  ChatCompletionTokenLogprob,
  ChatCompletionTool,
  ChatCompletionToolChoiceOption,
  ChatCompletionToolMessageParam,
+  ChatCompletionUpdateParams,
  ChatCompletionUserMessageParam,
-} from './resources/chat/completions';
-import { FineTuning } from './resources/fine-tuning/fine-tuning';
-import {
-  Upload,
-  UploadCompleteParams,
-  UploadCreateParams,
-  Uploads as UploadsAPIUploads,
-} from './resources/uploads/uploads';
+  ChatCompletionsPage,
+} from './resources/chat/completions/completions';

export interface ClientOptions {
  /**
@@ -310,6 +315,7 @@ export class OpenAI extends Core.APIClient {

OpenAI.Completions = Completions;
OpenAI.Chat = Chat;
+OpenAI.ChatCompletionsPage = ChatCompletionsPage;
OpenAI.Embeddings = Embeddings;
OpenAI.Files = Files;
OpenAI.FileObjectsPage = FileObjectsPage;
@@ -355,6 +361,7 @@ export declare namespace OpenAI {
    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,
    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,
    type ChatCompletionContentPartText as ChatCompletionContentPartText,
+    type ChatCompletionDeleted as ChatCompletionDeleted,
    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,
    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
@@ -366,6 +373,7 @@ export declare namespace OpenAI {
    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,
    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,
    type ChatCompletionRole as ChatCompletionRole,
+    type ChatCompletionStoreMessage as ChatCompletionStoreMessage,
    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,
    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
@@ -373,9 +381,12 @@ export declare namespace OpenAI {
    type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,
    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
+    ChatCompletionsPage as ChatCompletionsPage,
    type ChatCompletionCreateParams as ChatCompletionCreateParams,
    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,
    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,
+    type ChatCompletionUpdateParams as ChatCompletionUpdateParams,
+    type ChatCompletionListParams as ChatCompletionListParams,
  };

  export {
diff --git src/internal/decoders/line.ts src/internal/decoders/line.ts
index 34e41d1dc..947f240b3 100644
--- src/internal/decoders/line.ts
+++ src/internal/decoders/line.ts
@@ -13,52 +13,58 @@ export class LineDecoder {
  static NEWLINE_CHARS = new Set(['\n', '\r']);
  static NEWLINE_REGEXP = /\r\n|[\n\r]/g;

-  buffer: string[];
-  trailingCR: boolean;
+  buffer: Uint8Array;
+  #carriageReturnIndex: number | null;
  textDecoder: any; // TextDecoder found in browsers; not typed to avoid pulling in either "dom" or "node" types.

  constructor() {
-    this.buffer = [];
-    this.trailingCR = false;
+    this.buffer = new Uint8Array();
+    this.#carriageReturnIndex = null;
  }

  decode(chunk: Bytes): string[] {
-    let text = this.decodeText(chunk);
-
-    if (this.trailingCR) {
-      text = '\r' + text;
-      this.trailingCR = false;
-    }
-    if (text.endsWith('\r')) {
-      this.trailingCR = true;
-      text = text.slice(0, -1);
-    }
-
-    if (!text) {
+    if (chunk == null) {
      return [];
    }

-    const trailingNewline = LineDecoder.NEWLINE_CHARS.has(text[text.length - 1] || '');
-    let lines = text.split(LineDecoder.NEWLINE_REGEXP);
+    const binaryChunk =
+      chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
+      : typeof chunk === 'string' ? new TextEncoder().encode(chunk)
+      : chunk;
+
+    let newData = new Uint8Array(this.buffer.length + binaryChunk.length);
+    newData.set(this.buffer);
+    newData.set(binaryChunk, this.buffer.length);
+    this.buffer = newData;
+
+    const lines: string[] = [];
+    let patternIndex;
+    while ((patternIndex = findNewlineIndex(this.buffer, this.#carriageReturnIndex)) != null) {
+      if (patternIndex.carriage && this.#carriageReturnIndex == null) {
+        // skip until we either get a corresponding `\n`, a new `\r` or nothing
+        this.#carriageReturnIndex = patternIndex.index;
+        continue;
+      }

-    // if there is a trailing new line then the last entry will be an empty
-    // string which we don't care about
-    if (trailingNewline) {
-      lines.pop();
-    }
+      // we got double \r or \rtext\n
+      if (
+        this.#carriageReturnIndex != null &&
+        (patternIndex.index !== this.#carriageReturnIndex + 1 || patternIndex.carriage)
+      ) {
+        lines.push(this.decodeText(this.buffer.slice(0, this.#carriageReturnIndex - 1)));
+        this.buffer = this.buffer.slice(this.#carriageReturnIndex);
+        this.#carriageReturnIndex = null;
+        continue;
+      }

-    if (lines.length === 1 && !trailingNewline) {
-      this.buffer.push(lines[0]!);
-      return [];
-    }
+      const endIndex =
+        this.#carriageReturnIndex !== null ? patternIndex.preceding - 1 : patternIndex.preceding;

-    if (this.buffer.length > 0) {
-      lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
-      this.buffer = [];
-    }
+      const line = this.decodeText(this.buffer.slice(0, endIndex));
+      lines.push(line);

-    if (!trailingNewline) {
-      this.buffer = [lines.pop() || ''];
+      this.buffer = this.buffer.slice(patternIndex.index);
+      this.#carriageReturnIndex = null;
    }

    return lines;
@@ -102,13 +108,69 @@ export class LineDecoder {
  }

  flush(): string[] {
-    if (!this.buffer.length && !this.trailingCR) {
+    if (!this.buffer.length) {
      return [];
    }
+    return this.decode('\n');
+  }
+}

-    const lines = [this.buffer.join('')];
-    this.buffer = [];
-    this.trailingCR = false;
-    return lines;
+/**
+ * This function searches the buffer for the end patterns, (\r or \n)
+ * and returns an object with the index preceding the matched newline and the
+ * index after the newline char. `null` is returned if no new line is found.
+ *
+ * ```ts
+ * findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 }
+ * ```
+ */
+function findNewlineIndex(
+  buffer: Uint8Array,
+  startIndex: number | null,
+): { preceding: number; index: number; carriage: boolean } | null {
+  const newline = 0x0a; // \n
+  const carriage = 0x0d; // \r
+
+  for (let i = startIndex ?? 0; i < buffer.length; i++) {
+    if (buffer[i] === newline) {
+      return { preceding: i, index: i + 1, carriage: false };
+    }
+
+    if (buffer[i] === carriage) {
+      return { preceding: i, index: i + 1, carriage: true };
+    }
  }
+
+  return null;
+}
+
+export function findDoubleNewlineIndex(buffer: Uint8Array): number {
+  // This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
+  // and returns the index right after the first occurrence of any pattern,
+  // or -1 if none of the patterns are found.
+  const newline = 0x0a; // \n
+  const carriage = 0x0d; // \r
+
+  for (let i = 0; i < buffer.length - 1; i++) {
+    if (buffer[i] === newline && buffer[i + 1] === newline) {
+      // \n\n
+      return i + 2;
+    }
+    if (buffer[i] === carriage && buffer[i + 1] === carriage) {
+      // \r\r
+      return i + 2;
+    }
+    if (
+      buffer[i] === carriage &&
+      buffer[i + 1] === newline &&
+      i + 3 < buffer.length &&
+      buffer[i + 2] === carriage &&
+      buffer[i + 3] === newline
+    ) {
+      // \r\n\r\n
+      return i + 4;
+    }
+  }
+
+  return -1;
}
diff --git src/lib/AssistantStream.ts src/lib/AssistantStream.ts
index caf68e7dd..9b6cc20c5 100644
--- src/lib/AssistantStream.ts
+++ src/lib/AssistantStream.ts
@@ -370,6 +370,7 @@ export class AssistantStream
      case 'thread.run.in_progress':
      case 'thread.run.requires_action':
      case 'thread.run.completed':
+      case 'thread.run.incomplete':
      case 'thread.run.failed':
      case 'thread.run.cancelling':
      case 'thread.run.cancelled':
@@ -400,6 +401,8 @@ export class AssistantStream
        throw new Error(
          'Encountered an error event in event processing - errors should be processed earlier',
        );
+      default:
+        assertNever(event);
    }
  }

@@ -772,3 +775,5 @@ export class AssistantStream
    return await this._createToolAssistantStream(runs, threadId, runId, params, options);
  }
}
+
+function assertNever(_x: never) {}
diff --git src/lib/ChatCompletionStream.ts src/lib/ChatCompletionStream.ts
index 6c846f70b..35648c27b 100644
--- src/lib/ChatCompletionStream.ts
+++ src/lib/ChatCompletionStream.ts
@@ -13,7 +13,7 @@ import {
  type ChatCompletionCreateParamsStreaming,
  type ChatCompletionCreateParamsBase,
  type ChatCompletionRole,
-} from '../resources/chat/completions';
+} from '../resources/chat/completions/completions';
import {
  AbstractChatCompletionRunner,
  type AbstractChatCompletionRunnerEvents,
diff --git src/pagination.ts src/pagination.ts
index 63644e333..7a513fc44 100644
--- src/pagination.ts
+++ src/pagination.ts
@@ -43,6 +43,8 @@ export class Page<Item> extends AbstractPage<Item> implements PageResponse<Item>

export interface CursorPageResponse<Item> {
  data: Array<Item>;
+
+  has_more: boolean;
}

export interface CursorPageParams {
@@ -57,6 +59,8 @@ export class CursorPage<Item extends { id: string }>
{
  data: Array<Item>;

+  has_more: boolean;
+
  constructor(
    client: APIClient,
    response: Response,
@@ -66,12 +70,21 @@ export class CursorPage<Item extends { id: string }>
    super(client, response, body, options);

    this.data = body.data || [];
+    this.has_more = body.has_more || false;
  }

  getPaginatedItems(): Item[] {
    return this.data ?? [];
  }

+  override hasNextPage(): boolean {
+    if (this.has_more === false) {
+      return false;
+    }
+
+    return super.hasNextPage();
+  }
+
  // @deprecated Please use `nextPageInfo()` instead
  nextPageParams(): Partial<CursorPageParams> | null {
    const info = this.nextPageInfo();
diff --git src/resources/beta/assistants.ts src/resources/beta/assistants.ts
index 69a5db520..0cc63d691 100644
--- src/resources/beta/assistants.ts
+++ src/resources/beta/assistants.ts
@@ -1133,6 +1133,16 @@ export interface AssistantCreateParams {
   */
  name?: string | null;

+  /**
+   * **o1 and o3-mini models only**
+   *
+   * Constrains effort on reasoning for
+   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+   * result in faster responses and fewer tokens used on reasoning in a response.
+   */
+  reasoning_effort?: 'low' | 'medium' | 'high' | null;
+
  /**
   * Specifies the format that the model must output. Compatible with
   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
@@ -1288,13 +1298,52 @@ export interface AssistantUpdateParams {
   * [Model overview](https://platform.openai.com/docs/models) for descriptions of
   * them.
   */
-  model?: string;
+  model?:
+    | (string & {})
+    | 'o3-mini'
+    | 'o3-mini-2025-01-31'
+    | 'o1'
+    | 'o1-2024-12-17'
+    | 'gpt-4o'
+    | 'gpt-4o-2024-11-20'
+    | 'gpt-4o-2024-08-06'
+    | 'gpt-4o-2024-05-13'
+    | 'gpt-4o-mini'
+    | 'gpt-4o-mini-2024-07-18'
+    | 'gpt-4-turbo'
+    | 'gpt-4-turbo-2024-04-09'
+    | 'gpt-4-0125-preview'
+    | 'gpt-4-turbo-preview'
+    | 'gpt-4-1106-preview'
+    | 'gpt-4-vision-preview'
+    | 'gpt-4'
+    | 'gpt-4-0314'
+    | 'gpt-4-0613'
+    | 'gpt-4-32k'
+    | 'gpt-4-32k-0314'
+    | 'gpt-4-32k-0613'
+    | 'gpt-3.5-turbo'
+    | 'gpt-3.5-turbo-16k'
+    | 'gpt-3.5-turbo-0613'
+    | 'gpt-3.5-turbo-1106'
+    | 'gpt-3.5-turbo-0125'
+    | 'gpt-3.5-turbo-16k-0613';

  /**
   * The name of the assistant. The maximum length is 256 characters.
   */
  name?: string | null;

+  /**
+   * **o1 and o3-mini models only**
+   *
+   * Constrains effort on reasoning for
+   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+   * result in faster responses and fewer tokens used on reasoning in a response.
+   */
+  reasoning_effort?: 'low' | 'medium' | 'high' | null;
+
  /**
   * Specifies the format that the model must output. Compatible with
   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
diff --git src/resources/beta/threads/runs/runs.ts src/resources/beta/threads/runs/runs.ts
index 84ba7b63c..8ab94cc99 100644
--- src/resources/beta/threads/runs/runs.ts
+++ src/resources/beta/threads/runs/runs.ts
@@ -731,6 +731,16 @@ export interface RunCreateParamsBase {
   */
  parallel_tool_calls?: boolean;

+  /**
+   * Body param: **o1 and o3-mini models only**
+   *
+   * Constrains effort on reasoning for
+   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+   * result in faster responses and fewer tokens used on reasoning in a response.
+   */
+  reasoning_effort?: 'low' | 'medium' | 'high' | null;
+
  /**
   * Body param: Specifies the format that the model must output. Compatible with
   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
diff --git src/resources/chat/chat.ts src/resources/chat/chat.ts
index d4a18929c..5bceec45a 100644
--- src/resources/chat/chat.ts
+++ src/resources/chat/chat.ts
@@ -1,7 +1,7 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../resource';
-import * as CompletionsAPI from './completions';
+import * as CompletionsAPI from './completions/completions';
import {
  ChatCompletion,
  ChatCompletionAssistantMessageParam,
@@ -16,9 +16,11 @@ import {
  ChatCompletionCreateParams,
  ChatCompletionCreateParamsNonStreaming,
  ChatCompletionCreateParamsStreaming,
+  ChatCompletionDeleted,
  ChatCompletionDeveloperMessageParam,
  ChatCompletionFunctionCallOption,
  ChatCompletionFunctionMessageParam,
+  ChatCompletionListParams,
  ChatCompletionMessage,
  ChatCompletionMessageParam,
  ChatCompletionMessageToolCall,
@@ -27,19 +29,24 @@ import {
  ChatCompletionPredictionContent,
  Cha,tCompletionReasoningEffort,
  ChatCompletionRole,
+  ChatCompletionStoreMessage,
  ChatCompletionStreamOptions,
  ChatCompletionSystemMessageParam,
  ChatCompletionTokenLogprob,
  ChatCompletionTool,
  ChatCompletionToolChoiceOption,
  ChatCompletionToolMessageParam,
+  ChatCompletionUpdateParams,
  ChatCompletionUserMessageParam,
+  ChatCompletionsPage,
  CompletionCreateParams,
  CompletionCreateParamsNonStreaming,
  CompletionCreateParamsStreaming,
+  CompletionListParams,
+  CompletionUpdateParams,
  Completions,
  CreateChatCompletionRequestMessage,
-} from './completions';
+} from './completions/completions';

export class Chat extends APIResource {
  completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this._client);
@@ -87,6 +94,7 @@ export type ChatModel =
  | 'gpt-3.5-turbo-16k-0613';

Chat.Completions = Completions;
+Chat.ChatCompletionsPage = ChatCompletionsPage;

export declare namespace Chat {
  export { type ChatModel as ChatModel };
@@ -103,6 +111,7 @@ export declare namespace Chat {
    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,
    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,
    type ChatCompletionContentPartText as ChatCompletionContentPartText,
+    type ChatCompletionDeleted as ChatCompletionDeleted,
    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,
    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
@@ -114,6 +123,7 @@ export declare namespace Chat {
    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,
    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,
    type ChatCompletionRole as ChatCompletionRole,
+    type ChatCompletionStoreMessage as ChatCompletionStoreMessage,
    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,
    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
@@ -122,11 +132,16 @@ export declare namespace Chat {
    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
    type CreateChatCompletionRequestMessage as CreateChatCompletionRequestMessage,
+    ChatCompletionsPage as ChatCompletionsPage,
    type ChatCompletionCreateParams as ChatCompletionCreateParams,
    type CompletionCreateParams as CompletionCreateParams,
    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,
    type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,
    type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
+    type ChatCompletionUpdateParams as ChatCompletionUpdateParams,
+    type CompletionUpdateParams as CompletionUpdateParams,
+    type ChatCompletionListParams as ChatCompletionListParams,
+    type CompletionListParams as CompletionListParams,
  };
}
diff --git src/resources/chat/completions.ts src/resources/chat/completions.ts
index 55b008cf0..55b151e8b 100644
--- src/resources/chat/completions.ts
+++ src/resources/chat/completions.ts
@@ -1,1313 +1 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-import { APIResource } from '../../resource';
-import { APIPromise } from '../../core';
-import * as Core from '../../core';
-import * as ChatCompletionsAPI from './completions';
-import * as CompletionsAPI from '../completions';
-import * as Shared from '../shared';
-import * as ChatAPI from './chat';
-import { Stream } from '../../streaming';
-
-export class Completions extends APIResource {
-  /**
-   * Creates a model response for the given chat conversation. Learn more in the
-   * [text generation](https://platform.openai.com/docs/guides/text-generation),
-   * [vision](https://platform.openai.com/docs/guides/vision), and
-   * [audio](https://platform.openai.com/docs/guides/audio) guides.
-   *
-   * Parameter support can differ depending on the model used to generate the
-   * response, particularly for newer reasoning models. Parameters that are only
-   * supported for reasoning models are noted below. For the current state of
-   * unsupported parameters in reasoning models,
-   * [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).
-   */
-  create(
-    body: ChatCompletionCreateParamsNonStreaming,
-    options?: Core.RequestOptions,
-  ): APIPromise<ChatCompletion>;
-  create(
-    body: ChatCompletionCreateParamsStreaming,
-    options?: Core.RequestOptions,
-  ): APIPromise<Stream<ChatCompletionChunk>>;
-  create(
-    body: ChatCompletionCreateParamsBase,
-    options?: Core.RequestOptions,
-  ): APIPromise<Stream<ChatCompletionChunk> | ChatCompletion>;
-  create(
-    body: ChatCompletionCreateParams,
-    options?: Core.RequestOptions,
-  ): APIPromise<ChatCompletion> | APIPromise<Stream<ChatCompletionChunk>> {
-    return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false }) as
-      | APIPromise<ChatCompletion>
-      | APIPromise<Stream<ChatCompletionChunk>>;
-  }
-}
-
-/**
- * Represents a chat completion response returned by model, based on the provided
- * input.
- */
-export interface ChatCompletion {
-  /**
-   * A unique identifier for the chat completion.
-   */
-  id: string;
-
-  /**
-   * A list of chat completion choices. Can be more than one if `n` is greater
-   * than 1.
-   */
-  choices: Array<ChatCompletion.Choice>;
-
-  /**
-   * The Unix timestamp (in seconds) of when the chat completion was created.
-   */
-  created: number;
-
-  /**
-   * The model used for the chat completion.
-   */
-  model: string;
-
-  /**
-   * The object type, which is always `chat.completion`.
-   */
-  object: 'chat.completion';
-
-  /**
-   * The service tier used for processing the request.
-   */
-  service_tier?: 'scale' | 'default' | null;
-
-  /**
-   * This fingerprint represents the backend configuration that the model runs with.
-   *
-   * Can be used in conjunction with the `seed` request parameter to understand when
-   * backend changes have been made that might impact determinism.
-   */
-  system_fingerprint?: string;
-
-  /**
-   * Usage statistics for the completion request.
-   */
-  usage?: CompletionsAPI.CompletionUsage;
-}
-
-export namespace ChatCompletion {
-  export interface Choice {
-    /**
-     * The reason the model stopped generating tokens. This will be `stop` if the model
-     * hit a natural stop point or a provided stop sequence, `length` if the maximum
-     * number of tokens specified in the request was reached, `content_filter` if
-     * content was omitted due to a flag from our content filters, `tool_calls` if the
-     * model called a tool, or `function_call` (deprecated) if the model called a
-     * function.
-     */
-    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
-
-    /**
-     * The index of the choice in the list of choices.
-     */
-    index: number;
-
-    /**
-     * Log probability information for the choice.
-     */
-    logprobs: Choice.Logprobs | null;
-
-    /**
-     * A chat completion message generated by the model.
-     */
-    message: ChatCompletionsAPI.ChatCompletionMessage;
-  }
-
-  export namespace Choice {
-    /**
-     * Log probability information for the choice.
-     */
-    export interface Logprobs {
-      /**
-       * A list of message content tokens with log probability information.
-       */
-      content: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
-
-      /**
-       * A list of message refusal tokens with log probability information.
-       */
-      refusal: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
-    }
-  }
-}
-
-/**
- * Messages sent by the model in response to user messages.
- */
-export interface ChatCompletionAssistantMessageParam {
-  /**
-   * The role of the messages author, in this case `assistant`.
-   */
-  role: 'assistant';
-
-  /**
-   * Data about a previous audio response from the model.
-   * [Learn more](https://platform.openai.com/docs/guides/audio).
-   */
-  audio?: ChatCompletionAssistantMessageParam.Audio | null;
-
-  /**
-   * The contents of the assistant message. Required unless `tool_calls` or
-   * `function_call` is specified.
-   */
-  content?: string | Array<ChatCompletionContentPartText | ChatCompletionContentPartRefusal> | null;
-
-  /**
-   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-   * function that should be called, as generated by the model.
-   */
-  function_call?: ChatCompletionAssistantMessageParam.FunctionCall | null;
-
-  /**
-   * An optional name for the participant. Provides the model information to
-   * differentiate between participants of the same role.
-   */
-  name?: string;
-
-  /**
-   * The refusal message by the assistant.
-   */
-  refusal?: string | null;
-
-  /**
-   * The tool calls generated by the model, such as function calls.
-   */
-  tool_calls?: Array<ChatCompletionMessageToolCall>;
-}
-
-export namespace ChatCompletionAssistantMessageParam {
-  /**
-   * Data about a previous audio response from the model.
-   * [Learn more](https://platform.openai.com/docs/guides/audio).
-   */
-  export interface Audio {
-    /**
-     * Unique identifier for a previous audio response from the model.
-     */
-    id: string;
-  }
-
-  /**
-   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-   * function that should be called, as generated by the model.
-   */
-  export interface FunctionCall {
-    /**
-     * The arguments to call the function with, as generated by the model in JSON
-     * format. Note that the model does not always generate valid JSON, and may
-     * hallucinate parameters not defined by your function schema. Validate the
-     * arguments in your code before calling your function.
-     */
-    arguments: string;
-
-    /**
-     * The name of the function to call.
-     */
-    name: string;
-  }
-}
-
-/**
- * If the audio output modality is requested, this object contains data about the
- * audio response from the model.
- * [Learn more](https://platform.openai.com/docs/guides/audio).
- */
-export interface ChatCompletionAudio {
-  /**
-   * Unique identifier for this audio response.
-   */
-  id: string;
-
-  /**
-   * Base64 encoded audio bytes generated by the model, in the format specified in
-   * the request.
-   */
-  data: string;
-
-  /**
-   * The Unix timestamp (in seconds) for when this audio response will no longer be
-   * accessible on the server for use in multi-turn conversations.
-   */
-  expires_at: number;
-
-  /**
-   * Transcript of the audio generated by the model.
-   */
-  transcript: string;
-}
-
-/**
- * Parameters for audio output. Required when audio output is requested with
- * `modalities: ["audio"]`.
- * [Learn more](https://platform.openai.com/docs/guides/audio).
- */
-export interface ChatCompletionAudioParam {
-  /**
-   * Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
-   * or `pcm16`.
-   */
-  format: 'wav' | 'mp3' | 'flac' | 'opus' | 'pcm16';
-
-  /**
-   * The voice the model uses to respond. Supported voices are `ash`, `ballad`,
-   * `coral`, `sage`, and `verse` (also supported but not recommended are `alloy`,
-   * `echo`, and `shimmer`; these voices are less expressive).
-   */
-  voice: 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';
-}
-
-/**
- * Represents a streamed chunk of a chat completion response returned by model,
- * based on the provided input.
- */
-export interface ChatCompletionChunk {
-  /**
-   * A unique identifier for the chat completion. Each chunk has the same ID.
-   */
-  id: string;
-
-  /**
-   * A list of chat completion choices. Can contain more than one elements if `n` is
-   * greater than 1. Can also be empty for the last chunk if you set
-   * `stream_options: {"include_usage": true}`.
-   */
-  choices: Array<ChatCompletionChunk.Choice>;
-
-  /**
-   * The Unix timestamp (in seconds) of when the chat completion was created. Each
-   * chunk has the same timestamp.
-   */
-  created: number;
-
-  /**
-   * The model to generate the completion.
-   */
-  model: string;
-
-  /**
-   * The object type, which is always `chat.completion.chunk`.
-   */
-  object: 'chat.completion.chunk';
-
-  /**
-   * The service tier used for processing the request.
-   */
-  service_tier?: 'scale' | 'default' | null;
-
-  /**
-   * This fingerprint represents the backend configuration that the model runs with.
-   * Can be used in conjunction with the `seed` request parameter to understand when
-   * backend changes have been made that might impact determinism.
-   */
-  system_fingerprint?: string;
-
-  /**
-   * An optional field that will only be present when you set
-   * `stream_options: {"include_usage": true}` in your request. When present, it
-   * contains a null value except for the last chunk which contains the token usage
-   * statistics for the entire request.
-   */
-  usage?: CompletionsAPI.CompletionUsage | null;
-}
-
-export namespace ChatCompletionChunk {
-  export interface Choice {
-    /**
-     * A chat completion delta generated by streamed model responses.
-     */
-    delta: Choice.Delta;
-
-    /**
-     * The reason the model stopped generating tokens. This will be `stop` if the model
-     * hit a natural stop point or a provided stop sequence, `length` if the maximum
-     * number of tokens specified in the request was reached, `content_filter` if
-     * content was omitted due to a flag from our content filters, `tool_calls` if the
-     * model called a tool, or `function_call` (deprecated) if the model called a
-     * function.
-     */
-    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call' | null;
-
-    /**
-     * The index of the choice in the list of choices.
-     */
-    index: number;
-
-    /**
-     * Log probability information for the choice.
-     */
-    logprobs?: Choice.Logprobs | null;
-  }
-
-  export namespace Choice {
-    /**
-     * A chat completion delta generated by streamed model responses.
-     */
-    export interface Delta {
-      /**
-       * The contents of the chunk message.
-       */
-      content?: string | null;
-
-      /**
-       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-       * function that should be called, as generated by the model.
-       */
-      function_call?: Delta.FunctionCall;
-
-      /**
-       * The refusal message generated by the model.
-       */
-      refusal?: string | null;
-
-      /**
-       * The role of the author of this message.
-       */
-      role?: 'developer' | 'system' | 'user' | 'assistant' | 'tool';
-
-      tool_calls?: Array<Delta.ToolCall>;
-    }
-
-    export namespace Delta {
-      /**
-       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-       * function that should be called, as generated by the model.
-       */
-      export interface FunctionCall {
-        /**
-         * The arguments to call the function with, as generated by the model in JSON
-         * format. Note that the model does not always generate valid JSON, and may
-         * hallucinate parameters not defined by your function schema. Validate the
-         * arguments in your code before calling your function.
-         */
-        arguments?: string;
-
-        /**
-         * The name of the function to call.
-         */
-        name?: string;
-      }
-
-      export interface ToolCall {
-        index: number;
-
-        /**
-         * The ID of the tool call.
-         */
-        id?: string;
-
-        function?: ToolCall.Function;
-
-        /**
-         * The type of the tool. Currently, only `function` is supported.
-         */
-        type?: 'function';
-      }
-
-      export namespace ToolCall {
-        export interface Function {
-          /**
-           * The arguments to call the function with, as generated by the model in JSON
-           * format. Note that the model does not always generate valid JSON, and may
-           * hallucinate parameters not defined by your function schema. Validate the
-           * arguments in your code before calling your function.
-           */
-          arguments?: string;
-
-          /**
-           * The name of the function to call.
-           */
-          name?: string;
-        }
-      }
-    }
-
-    /**
-     * Log probability information for the choice.
-     */
-    export interface Logprobs {
-      /**
-       * A list of message content tokens with log probability information.
-       */
-      content: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
-
-      /**
-       * A list of message refusal tokens with log probability information.
-       */
-      refusal: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
-    }
-  }
-}
-
-/**
- * Learn about
- * [text inputs](https://platform.openai.com/docs/guides/text-generation).
- */
-export type ChatCompletionContentPart =
-  | ChatCompletionContentPartText
-  | ChatCompletionContentPartImage
-  | ChatCompletionContentPartInputAudio;
-
-/**
- * Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
- */
-export interface ChatCompletionContentPartImage {
-  image_url: ChatCompletionContentPartImage.ImageURL;
-
-  /**
-   * The type of the content part.
-   */
-  type: 'image_url';
-}
-
-export namespace ChatCompletionContentPartImage {
-  export interface ImageURL {
-    /**
-     * Either a URL of the image or the base64 encoded image data.
-     */
-    url: string;
-
-    /**
-     * Specifies the detail level of the image. Learn more in the
-     * [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
-     */
-    detail?: 'auto' | 'low' | 'high';
-  }
-}
-
-/**
- * Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
- */
-export interface ChatCompletionContentPartInputAudio {
-  input_audio: ChatCompletionContentPartInputAudio.InputAudio;
-
-  /**
-   * The type of the content part. Always `input_audio`.
-   */
-  type: 'input_audio';
-}
-
-export namespace ChatCompletionContentPartInputAudio {
-  export interface InputAudio {
-    /**
-     * Base64 encoded audio data.
-     */
-    data: string;
-
-    /**
-     * The format of the encoded audio data. Currently supports "wav" and "mp3".
-     */
-    format: 'wav' | 'mp3';
-  }
-}
-
-export interface ChatCompletionContentPartRefusal {
-  /**
-   * The refusal message generated by the model.
-   */
-  refusal: string;
-
-  /**
-   * The type of the content part.
-   */
-  type: 'refusal';
-}
-
-/**
- * Learn about
- * [text inputs](https://platform.openai.com/docs/guides/text-generation).
- */
-export interface ChatCompletionContentPartText {
-  /**
-   * The text content.
-   */
-  text: string;
-
-  /**
-   * The type of the content part.
-   */
-  type: 'text';
-}
-
-/**
- * Developer-provided instructions that the model should follow, regardless of
- * messages sent by the user. With o1 models and newer, `developer` messages
- * replace the previous `system` messages.
- */
-export interface ChatCompletionDeveloperMessageParam {
-  /**
-   * The contents of the developer message.
-   */
-  content: string | Array<ChatCompletionContentPartText>;
-
-  /**
-   * The role of the messages author, in this case `developer`.
-   */
-  role: 'developer';
-
-  /**
-   * An optional name for the participant. Provides the model information to
-   * differentiate between participants of the same role.
-   */
-  name?: string;
-}
-
-/**
- * Specifying a particular function via `{"name": "my_function"}` forces the model
- * to call that function.
- */
-export interface ChatCompletionFunctionCallOption {
-  /**
-   * The name of the function to call.
-   */
-  name: string;
-}
-
-/**
- * @deprecated
- */
-export interface ChatCompletionFunctionMessageParam {
-  /**
-   * The contents of the function message.
-   */
-  content: string | null;
-
-  /**
-   * The name of the function to call.
-   */
-  name: string;
-
-  /**
-   * The role of the messages author, in this case `function`.
-   */
-  role: 'function';
-}
-
-/**
- * A chat completion message generated by the model.
- */
-export interface ChatCompletionMessage {
-  /**
-   * The contents of the message.
-   */
-  content: string | null;
-
-  /**
-   * The refusal message generated by the model.
-   */
-  refusal: string | null;
-
-  /**
-   * The role of the author of this message.
-   */
-  role: 'assistant';
-
-  /**
-   * If the audio output modality is requested, this object contains data about the
-   * audio response from the model.
-   * [Learn more](https://platform.openai.com/docs/guides/audio).
-   */
-  audio?: ChatCompletionAudio | null;
-
-  /**
-   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-   * function that should be called, as generated by the model.
-   */
-  function_call?: ChatCompletionMessage.FunctionCall | null;
-
-  /**
-   * The tool calls generated by the model, such as function calls.
-   */
-  tool_calls?: Array<ChatCompletionMessageToolCall>;
-}
-
-export namespace ChatCompletionMessage {
-  /**
-   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-   * function that should be called, as generated by the model.
-   */
-  export interface FunctionCall {
-    /**
-     * The arguments to call the function with, as generated by the model in JSON
-     * format. Note that the model does not always generate valid JSON, and may
-     * hallucinate parameters not defined by your function schema. Validate the
-     * arguments in your code before calling your function.
-     */
-    arguments: string;
-
-    /**
-     * The name of the function to call.
-     */
-    name: string;
-  }
-}
-
-/**
- * Developer-provided instructions that the model should follow, regardless of
- * messages sent by the user. With o1 models and newer, `developer` messages
- * replace the previous `system` messages.
- */
-export type ChatCompletionMessageParam =
-  | ChatCompletionDeveloperMessageParam
-  | ChatCompletionSystemMessageParam
-  | ChatCompletionUserMessageParam
-  | ChatCompletionAssistantMessageParam
-  | ChatCompletionToolMessageParam
-  | ChatCompletionFunctionMessageParam;
-
-export interface ChatCompletionMessageToolCall {
-  /**
-   * The ID of the tool call.
-   */
-  id: string;
-
-  /**
-   * The function that the model called.
-   */
-  function: ChatCompletionMessageToolCall.Function;
-
-  /**
-   * The type of the tool. Currently, only `function` is supported.
-   */
-  type: 'function';
-}
-
-export namespace ChatCompletionMessageToolCall {
-  /**
-   * The function that the model called.
-   */
-  export interface Function {
-    /**
-     * The arguments to call the function with, as generated by the model in JSON
-     * format. Note that the model does not always generate valid JSON, and may
-     * hallucinate parameters not defined by your function schema. Validate the
-     * arguments in your code before calling your function.
-     */
-    arguments: string;
-
-    /**
-     * The name of the function to call.
-     */
-    name: string;
-  }
-}
-
-export type ChatCompletionModality = 'text' | 'audio';
-
-/**
- * Specifies a tool the model should use. Use to force the model to call a specific
- * function.
- */
-export interface ChatCompletionNamedToolChoice {
-  function: ChatCompletionNamedToolChoice.Function;
-
-  /**
-   * The type of the tool. Currently, only `function` is supported.
-   */
-  type: 'function';
-}
-
-export namespace ChatCompletionNamedToolChoice {
-  export interface Function {
-    /**
-     * The name of the function to call.
-     */
-    name: string;
-  }
-}
-
-/**
- * Static predicted output content, such as the content of a text file that is
- * being regenerated.
- */
-export interface ChatCompletionPredictionContent {
-  /**
-   * The content that should be matched when generating a model response. If
-   * generated tokens would match this content, the entire model response can be
-   * returned much more quickly.
-   */
-  content: string | Array<ChatCompletionContentPartText>;
-
-  /**
-   * The type of the predicted content you want to provide. This type is currently
-   * always `content`.
-   */
-  type: 'content';
-}
-
-/**
- * **o1 models only**
- *
- * Constrains effort on reasoning for
- * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
- * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
- * result in faster responses and fewer tokens used on reasoning in a response.
- */
-export type ChatCompletionReasoningEffort = 'low' | 'medium' | 'high';
-
-/**
- * The role of the author of a message
- */
-export type ChatCompletionRole = 'developer' | 'system' | 'user' | 'assistant' | 'tool' | 'function';
-
-/**
- * Options for streaming response. Only set this when you set `stream: true`.
- */
-export interface ChatCompletionStreamOptions {
-  /**
-   * If set, an additional chunk will be streamed before the `data: [DONE]` message.
-   * The `usage` field on this chunk shows the token usage statistics for the entire
-   * request, and the `choices` field will always be an empty array. All other chunks
-   * will also include a `usage` field, but with a null value.
-   */
-  include_usage?: boolean;
-}
-
-/**
- * Developer-provided instructions that the model should follow, regardless of
- * messages sent by the user. With o1 models and newer, use `developer` messages
- * for this purpose instead.
- */
-export interface ChatCompletionSystemMessageParam {
-  /**
-   * The contents of the system message.
-   */
-  content: string | Array<ChatCompletionContentPartText>;
-
-  /**
-   * The role of the messages author, in this case `system`.
-   */
-  role: 'system';
-
-  /**
-   * An optional name for the participant. Provides the model information to
-   * differentiate between participants of the same role.
-   */
-  name?: string;
-}
-
-export interface ChatCompletionTokenLogprob {
-  /**
-   * The token.
-   */
-  token: string;
-
-  /**
-   * A list of integers representing the UTF-8 bytes representation of the token.
-   * Useful in instances where characters are represented by multiple tokens and
-   * their byte representations must be combined to generate the correct text
-   * representation. Can be `null` if there is no bytes representation for the token.
-   */
-  bytes: Array<number> | null;
-
-  /**
-   * The log probability of this token, if it is within the top 20 most likely
-   * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
-   * unlikely.
-   */
-  logprob: number;
-
-  /**
-   * List of the most likely tokens and their log probability, at this token
-   * position. In rare cases, there may be fewer than the number of requested
-   * `top_logprobs` returned.
-   */
-  top_logprobs: Array<ChatCompletionTokenLogprob.TopLogprob>;
-}
-
-export namespace ChatCompletionTokenLogprob {
-  export interface TopLogprob {
-    /**
-     * The token.
-     */
-    token: string;
-
-    /**
-     * A list of integers representing the UTF-8 bytes representation of the token.
-     * Useful in instances where characters are represented by multiple tokens and
-     * their byte representations must be combined to generate the correct text
-     * representation. Can be `null` if there is no bytes representation for the token.
-     */
-    bytes: Array<number> | null;
-
-    /**
-     * The log probability of this token, if it is within the top 20 most likely
-     * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
-     * unlikely.
-     */
-    logprob: number;
-  }
-}
-
-export interface ChatCompletionTool {
-  function: Shared.FunctionDefinition;
-
-  /**
-   * The type of the tool. Currently, only `function` is supported.
-   */
-  type: 'function';
-}
-
-/**
- * Controls which (if any) tool is called by the model. `none` means the model will
- * not call any tool and instead generates a message. `auto` means the model can
- * pick between generating a message or calling one or more tools. `required` means
- * the model must call one or more tools. Specifying a particular tool via
- * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
- * call that tool.
- *
- * `none` is the default when no tools are present. `auto` is the default if tools
- * are present.
- */
-export type ChatCompletionToolChoiceOption = 'none' | 'auto' | 'required' | ChatCompletionNamedToolChoice;
-
-export interface ChatCompletionToolMessageParam {
-  /**
-   * The contents of the tool message.
-   */
-  content: string | Array<ChatCompletionContentPartText>;
-
-  /**
-   * The role of the messages author, in this case `tool`.
-   */
-  role: 'tool';
-
-  /**
-   * Tool call that this message is responding to.
-   */
-  tool_call_id: string;
-}
-
-/**
- * Messages sent by an end user, containing prompts or additional context
- * information.
- */
-export interface ChatCompletionUserMessageParam {
-  /**
-   * The contents of the user message.
-   */
-  content: string | Array<ChatCompletionContentPart>;
-
-  /**
-   * The role of the messages author, in this case `user`.
-   */
-  role: 'user';
-
-  /**
-   * An optional name for the participant. Provides the model information to
-   * differentiate between participants of the same role.
-   */
-  name?: string;
-}
-
-/**
- * @deprecated ChatCompletionMessageParam should be used instead
- */
-export type CreateChatCompletionRequestMessage = ChatCompletionMessageParam;
-
-export type ChatCompletionCreateParams =
-  | ChatCompletionCreateParamsNonStreaming
-  | ChatCompletionCreateParamsStreaming;
-
-export interface ChatCompletionCreateParamsBase {
-  /**
-   * A list of messages comprising the conversation so far. Depending on the
-   * [model](https://platform.openai.com/docs/models) you use, different message
-   * types (modalities) are supported, like
-   * [text](https://platform.openai.com/docs/guides/text-generation),
-   * [images](https://platform.openai.com/docs/guides/vision), and
-   * [audio](https://platform.openai.com/docs/guides/audio).
-   */
-  messages: Array<ChatCompletionMessageParam>;
-
-  /**
-   * ID of the model to use. See the
-   * [model endpoint compatibility](https://platform.openai.com/docs/models#model-endpoint-compatibility)
-   * table for details on which models work with the Chat API.
-   */
-  model: (string & {}) | ChatAPI.ChatModel;
-
-  /**
-   * Parameters for audio output. Required when audio output is requested with
-   * `modalities: ["audio"]`.
-   * [Learn more](https://platform.openai.com/docs/guides/audio).
-   */
-  audio?: ChatCompletionAudioParam | null;
-
-  /**
-   * Number between -2.0 and 2.0. Positive values penalize new tokens based on their
-   * existing frequency in the text so far, decreasing the model's likelihood to
-   * repeat the same line verbatim.
-   */
-  frequency_penalty?: number | null;
-
-  /**
-   * Deprecated in favor of `tool_choice`.
-   *
-   * Controls which (if any) function is called by the model.
-   *
-   * `none` means the model will not call a function and instead generates a message.
-   *
-   * `auto` means the model can pick between generating a message or calling a
-   * function.
-   *
-   * Specifying a particular function via `{"name": "my_function"}` forces the model
-   * to call that function.
-   *
-   * `none` is the default when no functions are present. `auto` is the default if
-   * functions are present.
-   */
-  function_call?: 'none' | 'auto' | ChatCompletionFunctionCallOption;
-
-  /**
-   * Deprecated in favor of `tools`.
-   *
-   * A list of functions the model may generate JSON inputs for.
-   */
-  functions?: Array<ChatCompletionCreateParams.Function>;
-
-  /**
-   * Modify the likelihood of specified tokens appearing in the completion.
-   *
-   * Accepts a JSON object that maps tokens (specified by their token ID in the
-   * tokenizer) to an associated bias value from -100 to 100. Mathematically, the
-   * bias is added to the logits generated by the model prior to sampling. The exact
-   * effect will vary per model, but values between -1 and 1 should decrease or
-   * increase likelihood of selection; values like -100 or 100 should result in a ban
-   * or exclusive selection of the relevant token.
-   */
-  logit_bias?: Record<string, number> | null;
-
-  /**
-   * Whether to return log probabilities of the output tokens or not. If true,
-   * returns the log probabilities of each output token returned in the `content` of
-   * `message`.
-   */
-  logprobs?: boolean | null;
-
-  /**
-   * An upper bound for the number of tokens that can be generated for a completion,
-   * including visible output tokens and
-   * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
-   */
-  max_completion_tokens?: number | null;
-
-  /**
-   * The maximum number of [tokens](/tokenizer) that can be generated in the chat
-   * completion. This value can be used to control
-   * [costs](https://openai.com/api/pricing/) for text generated via API.
-   *
-   * This value is now deprecated in favor of `max_completion_tokens`, and is not
-   * compatible with
-   * [o1 series models](https://platform.openai.com/docs/guides/reasoning).
-   */
-  max_tokens?: number | null;
-
-  /**
-   * Set of 16 key-value pairs that can be attached to an object. This can be useful
-   * for storing additional information about the object in a structured format, and
-   * querying for objects via API or the dashboard.
-   *
-   * Keys are strings with a maximum length of 64 characters. Values are strings with
-   * a maximum length of 512 characters.
-   */
-  metadata?: Shared.Metadata | null;
-
-  /**
-   * Output types that you would like the model to generate for this request. Most
-   * models are capable of generating text, which is the default:
-   *
-   * `["text"]`
-   *
-   * The `gpt-4o-audio-preview` model can also be used to
-   * [generate audio](https://platform.openai.com/docs/guides/audio). To request that
-   * this model generate both text and audio responses, you can use:
-   *
-   * `["text", "audio"]`
-   */
-  modalities?: Array<ChatCompletionModality> | null;
-
-  /**
-   * How many chat completion choices to generate for each input message. Note that
-   * you will be charged based on the number of generated tokens across all of the
-   * choices. Keep `n` as `1` to minimize costs.
-   */
-  n?: number | null;
-
-  /**
-   * Whether to enable
-   * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
-   * during tool use.
-   */
-  parallel_tool_calls?: boolean;
-
-  /**
-   * Static predicted output content, such as the content of a text file that is
-   * being regenerated.
-   */
-  prediction?: ChatCompletionPredictionContent | null;
-
-  /**
-   * Number between -2.0 and 2.0. Positive values penalize new tokens based on
-   * whether they appear in the text so far, increasing the model's likelihood to
-   * talk about new topics.
-   */
-  presence_penalty?: number | null;
-
-  /**
-   * **o1 models only**
-   *
-   * Constrains effort on reasoning for
-   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
-   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
-   * result in faster responses and fewer tokens used on reasoning in a response.
-   */
-  reasoning_effort?: ChatCompletionReasoningEffort;
-
-  /**
-   * An object specifying the format that the model must output.
-   *
-   * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
-   * Outputs which ensures the model will match your supplied JSON schema. Learn more
-   * in the
-   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
-   *
-   * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
-   * message the model generates is valid JSON.
-   *
-   * **Important:** when using JSON mode, you **must** also instruct the model to
-   * produce JSON yourself via a system or user message. Without this, the model may
-   * generate an unending stream of whitespace until the generation reaches the token
-   * limit, resulting in a long-running and seemingly "stuck" request. Also note that
-   * the message content may be partially cut off if `finish_reason="length"`, which
-   * indicates the generation exceeded `max_tokens` or the conversation exceeded the
-   * max context length.
-   */
-  response_format?:
-    | Shared.ResponseFormatText
-    | Shared.ResponseFormatJSONObject
-    | Shared.ResponseFormatJSONSchema;
-
-  /**
-   * This feature is in Beta. If specified, our system will make a best effort to
-   * sample deterministically, such that repeated requests with the same `seed` and
-   * parameters should return the same result. Determinism is not guaranteed, and you
-   * should refer to the `system_fingerprint` response parameter to monitor changes
-   * in the backend.
-   */
-  seed?: number | null;
-
-  /**
-   * Specifies the latency tier to use for processing the request. This parameter is
-   * relevant for customers subscribed to the scale tier service:
-   *
-   * - If set to 'auto', and the Project is Scale tier enabled, the system will
-   *   utilize scale tier credits until they are exhausted.
-   * - If set to 'auto', and the Project is not Scale tier enabled, the request will
-   *   be processed using the default service tier with a lower uptime SLA and no
-   *   latency guarantee.
-   * - If set to 'default', the request will be processed using the default service
-   *   tier with a lower uptime SLA and no latency guarantee.
-   * - When not set, the default behavior is 'auto'.
-   */
-  service_tier?: 'auto' | 'default' | null;
-
-  /**
-   * Up to 4 sequences where the API will stop generating further tokens.
-   */
-  stop?: string | null | Array<string>;
-
-  /**
-   * Whether or not to store the output of this chat completion request for use in
-   * our [model distillation](https://platform.openai.com/docs/guides/distillation)
-   * or [evals](https://platform.openai.com/docs/guides/evals) products.
-   */
-  store?: boolean | null;
-
-  /**
-   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
-   * sent as data-only
-   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
-   * as they become available, with the stream terminated by a `data: [DONE]`
-   * message.
-   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
-   */
-  stream?: boolean | null;
-
-  /**
-   * Options for streaming response. Only set this when you set `stream: true`.
-   */
-  stream_options?: ChatCompletionStreamOptions | null;
-
-  /**
-   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
-   * make the output more random, while lower values like 0.2 will make it more
-   * focused and deterministic. We generally recommend altering this or `top_p` but
-   * not both.
-   */
-  temperature?: number | null;
-
-  /**
-   * Controls which (if any) tool is called by the model. `none` means the model will
-   * not call any tool and instead generates a message. `auto` means the model can
-   * pick between generating a message or calling one or more tools. `required` means
-   * the model must call one or more tools. Specifying a particular tool via
-   * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
-   * call that tool.
-   *
-   * `none` is the default when no tools are present. `auto` is the default if tools
-   * are present.
-   */
-  tool_choice?: ChatCompletionToolChoiceOption;
-
-  /**
-   * A list of tools the model may call. Currently, only functions are supported as a
-   * tool. Use this to provide a list of functions the model may generate JSON inputs
-   * for. A max of 128 functions are supported.
-   */
-  tools?: Array<ChatCompletionTool>;
-
-  /**
-   * An integer between 0 and 20 specifying the number of most likely tokens to
-   * return at each token position, each with an associated log probability.
-   * `logprobs` must be set to `true` if this parameter is used.
-   */
-  top_logprobs?: number | null;
-
-  /**
-   * An alternative to sampling with temperature, called nucleus sampling, where the
-   * model considers the results of the tokens with top_p probability mass. So 0.1
-   * means only the tokens comprising the top 10% probability mass are considered.
-   *
-   * We generally recommend altering this or `temperature` but not both.
-   */
-  top_p?: number | null;
-
-  /**
-   * A unique identifier representing your end-user, which can help OpenAI to monitor
-   * and detect abuse.
-   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
-   */
-  user?: string;
-}
-
-export namespace ChatCompletionCreateParams {
-  /**
-   * @deprecated
-   */
-  export interface Function {
-    /**
-     * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
-     * underscores and dashes, with a maximum length of 64.
-     */
-    name: string;
-
-    /**
-     * A description of what the function does, used by the model to choose when and
-     * how to call the function.
-     */
-    description?: string;
-
-    /**
-     * The parameters the functions accepts, described as a JSON Schema object. See the
-     * [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
-     * and the
-     * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
-     * documentation about the format.
-     *
-     * Omitting `parameters` defines a function with an empty parameter list.
-     */
-    parameters?: Shared.FunctionParameters;
-  }
-
-  export type ChatCompletionCreateParamsNonStreaming =
-    ChatCompletionsAPI.ChatCompletionCreateParamsNonStreaming;
-  export type ChatCompletionCreateParamsStreaming = ChatCompletionsAPI.ChatCompletionCreateParamsStreaming;
-}
-
-/**
- * @deprecated Use ChatCompletionCreateParams instead
- */
-export type CompletionCreateParams = ChatCompletionCreateParams;
-
-export interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase {
-  /**
-   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
-   * sent as data-only
-   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
-   * as they become available, with the stream terminated by a `data: [DONE]`
-   * message.
-   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
-   */
-  stream?: false | null;
-}
-
-/**
- * @deprecated Use ChatCompletionCreateParamsNonStreaming instead
- */
-export type CompletionCreateParamsNonStreaming = ChatCompletionCreateParamsNonStreaming;
-
-export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreateParamsBase {
-  /**
-   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
-   * sent as data-only
-   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
-   * as they become available, with the stream terminated by a `data: [DONE]`
-   * message.
-   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
-   */
-  stream: true;
-}
-
-/**
- * @deprecated Use ChatCompletionCreateParamsStreaming instead
- */
-export type CompletionCreateParamsStreaming = ChatCompletionCreateParamsStreaming;
-
-export declare namespace Completions {
-  export {
-    type ChatCompletion as ChatCompletion,
-    type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,
-    type ChatCompletionAudio as ChatCompletionAudio,
-    type ChatCompletionAudioParam as ChatCompletionAudioParam,
-    type ChatCompletionChunk as ChatCompletionChunk,
-    type ChatCompletionContentPart as ChatCompletionContentPart,
-    type ChatCompletionContentPartImage as ChatCompletionContentPartImage,
-    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,
-    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,
-    type ChatCompletionContentPartText as ChatCompletionContentPartText,
-    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,
-    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
-    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
-    type ChatCompletionMessage as ChatCompletionMessage,
-    type ChatCompletionMessageParam as ChatCompletionMessageParam,
-    type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,
-    type ChatCompletionModality as ChatCompletionModality,
-    type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,
-    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,
-    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,
-    type ChatCompletionRole as ChatCompletionRole,
-    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,
-    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
-    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
-    type ChatCompletionTool as ChatCompletionTool,
-    type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,
-    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
-    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
-    type CreateChatCompletionRequestMessage as CreateChatCompletionRequestMessage,
-    type ChatCompletionCreateParams as ChatCompletionCreateParams,
-    type CompletionCreateParams as CompletionCreateParams,
-    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,
-    type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
-    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,
-    type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
-  };
-}
+export * from './completions/completions';
diff --git a/src/resources/chat/completions/completions.ts b/src/resources/chat/completions/completions.ts
new file mode 100644
index 000000000..3af4a3a1d
--- /dev/null
+++ src/resources/chat/completions/completions.ts
@@ -0,0 +1,1453 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import { APIResource } from '../../../resource';
+import { isRequestOptions } from '../../../core';
+import { APIPromise } from '../../../core';
+import * as Core from '../../../core';
+import * as CompletionsCompletionsAPI from './completions';
+import * as CompletionsAPI from '../../completions';
+import * as Shared from '../../shared';
+import * as ChatAPI from '../chat';
+import * as MessagesAPI from './messages';
+import { MessageListParams, Messages } from './messages';
+import { CursorPage, type CursorPageParams } from '../../../pagination';
+import { Stream } from '../../../streaming';
+
+export class Completions extends APIResource {
+  messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);
+
+  /**
+   * Creates a model response for the given chat conversation. Learn more in the
+   * [text generation](https://platform.openai.com/docs/guides/text-generation),
+   * [vision](https://platform.openai.com/docs/guides/vision), and
+   * [audio](https://platform.openai.com/docs/guides/audio) guides.
+   *
+   * Parameter support can differ depending on the model used to generate the
+   * response, particularly for newer reasoning models. Parameters that are only
+   * supported for reasoning models are noted below. For the current state of
+   * unsupported parameters in reasoning models,
+   * [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).
+   */
+  create(
+    body: ChatCompletionCreateParamsNonStreaming,
+    options?: Core.RequestOptions,
+  ): APIPromise<ChatCompletion>;
+  create(
+    body: ChatCompletionCreateParamsStreaming,
+    options?: Core.RequestOptions,
+  ): APIPromise<Stream<ChatCompletionChunk>>;
+  create(
+    body: ChatCompletionCreateParamsBase,
+    options?: Core.RequestOptions,
+  ): APIPromise<Stream<ChatCompletionChunk> | ChatCompletion>;
+  create(
+    body: ChatCompletionCreateParams,
+    options?: Core.RequestOptions,
+  ): APIPromise<ChatCompletion> | APIPromise<Stream<ChatCompletionChunk>> {
+    return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false }) as
+      | APIPromise<ChatCompletion>
+      | APIPromise<Stream<ChatCompletionChunk>>;
+  }
+
+  /**
+   * Get a stored chat completion. Only chat completions that have been created with
+   * the `store` parameter set to `true` will be returned.
+   */
+  retrieve(completionId: string, options?: Core.RequestOptions): Core.APIPromise<ChatCompletion> {
+    return this._client.get(`/chat/completions/${completionId}`, options);
+  }
+
+  /**
+   * Modify a stored chat completion. Only chat completions that have been created
+   * with the `store` parameter set to `true` can be modified. Currently, the only
+   * supported modification is to update the `metadata` field.
+   */
+  update(
+    completionId: string,
+    body: ChatCompletionUpdateParams,
+    options?: Core.RequestOptions,
+  ): Core.APIPromise<ChatCompletion> {
+    return this._client.post(`/chat/completions/${completionId}`, { body, ...options });
+  }
+
+  /**
+   * List stored chat completions. Only chat completions that have been stored with
+   * the `store` parameter set to `true` will be returned.
+   */
+  list(
+    query?: ChatCompletionListParams,
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionsPage, ChatCompletion>;
+  list(options?: Core.RequestOptions): Core.PagePromise<ChatCompletionsPage, ChatCompletion>;
+  list(
+    query: ChatCompletionListParams | Core.RequestOptions = {},
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionsPage, ChatCompletion> {
+    if (isRequestOptions(query)) {
+      return this.list({}, query);
+    }
+    return this._client.getAPIList('/chat/completions', ChatCompletionsPage, { query, ...options });
+  }
+
+  /**
+   * Delete a stored chat completion. Only chat completions that have been created
+   * with the `store` parameter set to `true` can be deleted.
+   */
+  del(completionId: string, options?: Core.RequestOptions): Core.APIPromise<ChatCompletionDeleted> {
+    return this._client.delete(`/chat/completions/${completionId}`, options);
+  }
+}
+
+export class ChatCompletionsPage extends CursorPage<ChatCompletion> {}
+
+export class ChatCompletionStoreMessagesPage extends CursorPage<ChatCompletionStoreMessage> {}
+
+/**
+ * Represents a chat completion response returned by model, based on the provided
+ * input.
+ */
+export interface ChatCompletion {
+  /**
+   * A unique identifier for the chat completion.
+   */
+  id: string;
+
+  /**
+   * A list of chat completion choices. Can be more than one if `n` is greater
+   * than 1.
+   */
+  choices: Array<ChatCompletion.Choice>;
+
+  /**
+   * The Unix timestamp (in seconds) of when the chat completion was created.
+   */
+  created: number;
+
+  /**
+   * The model used for the chat completion.
+   */
+  model: string;
+
+  /**
+   * The object type, which is always `chat.completion`.
+   */
+  object: 'chat.completion';
+
+  /**
+   * The service tier used for processing the request.
+   */
+  service_tier?: 'scale' | 'default' | null;
+
+  /**
+   * This fingerprint represents the backend configuration that the model runs with.
+   *
+   * Can be used in conjunction with the `seed` request parameter to understand when
+   * backend changes have been made that might impact determinism.
+   */
+  system_fingerprint?: string;
+
+  /**
+   * Usage statistics for the completion request.
+   */
+  usage?: CompletionsAPI.CompletionUsage;
+}
+
+export namespace ChatCompletion {
+  export interface Choice {
+    /**
+     * The reason the model stopped generating tokens. This will be `stop` if the model
+     * hit a natural stop point or a provided stop sequence, `length` if the maximum
+     * number of tokens specified in the request was reached, `content_filter` if
+     * content was omitted due to a flag from our content filters, `tool_calls` if the
+     * model called a tool, or `function_call` (deprecated) if the model called a
+     * function.
+     */
+    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
+
+    /**
+     * The index of the choice in the list of choices.
+     */
+    index: number;
+
+    /**
+     * Log probability information for the choice.
+     */
+    logprobs: Choice.Logprobs | null;
+
+    /**
+     * A chat completion message generated by the model.
+     */
+    message: CompletionsCompletionsAPI.ChatCompletionMessage;
+  }
+
+  export namespace Choice {
+    /**
+     * Log probability information for the choice.
+     */
+    export interface Logprobs {
+      /**
+       * A list of message content tokens with log probability information.
+       */
+      content: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
+
+      /**
+       * A list of message refusal tokens with log probability information.
+       */
+      refusal: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
+    }
+  }
+}
+
+/**
+ * Messages sent by the model in response to user messages.
+ */
+export interface ChatCompletionAssistantMessageParam {
+  /**
+   * The role of the messages author, in this case `assistant`.
+   */
+  role: 'assistant';
+
+  /**
+   * Data about a previous audio response from the model.
+   * [Learn more](https://platform.openai.com/docs/guides/audio).
+   */
+  audio?: ChatCompletionAssistantMessageParam.Audio | null;
+
+  /**
+   * The contents of the assistant message. Required unless `tool_calls` or
+   * `function_call` is specified.
+   */
+  content?: string | Array<ChatCompletionContentPartText | ChatCompletionContentPartRefusal> | null;
+
+  /**
+   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+   * function that should be called, as generated by the model.
+   */
+  function_call?: ChatCompletionAssistantMessageParam.FunctionCall | null;
+
+  /**
+   * An optional name for the participant. Provides the model information to
+   * differentiate between participants of the same role.
+   */
+  name?: string;
+
+  /**
+   * The refusal message by the assistant.
+   */
+  refusal?: string | null;
+
+  /**
+   * The tool calls generated by the model, such as function calls.
+   */
+  tool_calls?: Array<ChatCompletionMessageToolCall>;
+}
+
+export namespace ChatCompletionAssistantMessageParam {
+  /**
+   * Data about a previous audio response from the model.
+   * [Learn more](https://platform.openai.com/docs/guides/audio).
+   */
+  export interface Audio {
+    /**
+     * Unique identifier for a previous audio response from the model.
+     */
+    id: string;
+  }
+
+  /**
+   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+   * function that should be called, as generated by the model.
+   */
+  export interface FunctionCall {
+    /**
+     * The arguments to call the function with, as generated by the model in JSON
+     * format. Note that the model does not always generate valid JSON, and may
+     * hallucinate parameters not defined by your function schema. Validate the
+     * arguments in your code before calling your function.
+     */
+    arguments: string;
+
+    /**
+     * The name of the function to call.
+     */
+    name: string;
+  }
+}
+
+/**
+ * If the audio output modality is requested, this object contains data about the
+ * audio response from the model.
+ * [Learn more](https://platform.openai.com/docs/guides/audio).
+ */
+export interface ChatCompletionAudio {
+  /**
+   * Unique identifier for this audio response.
+   */
+  id: string;
+
+  /**
+   * Base64 encoded audio bytes generated by the model, in the format specified in
+   * the request.
+   */
+  data: string;
+
+  /**
+   * The Unix timestamp (in seconds) for when this audio response will no longer be
+   * accessible on the server for use in multi-turn conversations.
+   */
+  expires_at: number;
+
+  /**
+   * Transcript of the audio generated by the model.
+   */
+  transcript: string;
+}
+
+/**
+ * Parameters for audio output. Required when audio output is requested with
+ * `modalities: ["audio"]`.
+ * [Learn more](https://platform.openai.com/docs/guides/audio).
+ */
+export interface ChatCompletionAudioParam {
+  /**
+   * Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
+   * or `pcm16`.
+   */
+  format: 'wav' | 'mp3' | 'flac' | 'opus' | 'pcm16';
+
+  /**
+   * The voice the model uses to respond. Supported voices are `ash`, `ballad`,
+   * `coral`, `sage`, and `verse` (also supported but not recommended are `alloy`,
+   * `echo`, and `shimmer`; these voices are less expressive).
+   */
+  voice: 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';
+}
+
+/**
+ * Represents a streamed chunk of a chat completion response returned by model,
+ * based on the provided input.
+ */
+export interface ChatCompletionChunk {
+  /**
+   * A unique identifier for the chat completion. Each chunk has the same ID.
+   */
+  id: string;
+
+  /**
+   * A list of chat completion choices. Can contain more than one elements if `n` is
+   * greater than 1. Can also be empty for the last chunk if you set
+   * `stream_options: {"include_usage": true}`.
+   */
+  choices: Array<ChatCompletionChunk.Choice>;
+
+  /**
+   * The Unix timestamp (in seconds) of when the chat completion was created. Each
+   * chunk has the same timestamp.
+   */
+  created: number;
+
+  /**
+   * The model to generate the completion.
+   */
+  model: string;
+
+  /**
+   * The object type, which is always `chat.completion.chunk`.
+   */
+  object: 'chat.completion.chunk';
+
+  /**
+   * The service tier used for processing the request.
+   */
+  service_tier?: 'scale' | 'default' | null;
+
+  /**
+   * This fingerprint represents the backend configuration that the model runs with.
+   * Can be used in conjunction with the `seed` request parameter to understand when
+   * backend changes have been made that might impact determinism.
+   */
+  system_fingerprint?: string;
+
+  /**
+   * An optional field that will only be present when you set
+   * `stream_options: {"include_usage": true}` in your request. When present, it
+   * contains a null value except for the last chunk which contains the token usage
+   * statistics for the entire request.
+   */
+  usage?: CompletionsAPI.CompletionUsage | null;
+}
+
+export namespace ChatCompletionChunk {
+  export interface Choice {
+    /**
+     * A chat completion delta generated by streamed model responses.
+     */
+    delta: Choice.Delta;
+
+    /**
+     * The reason the model stopped generating tokens. This will be `stop` if the model
+     * hit a natural stop point or a provided stop sequence, `length` if the maximum
+     * number of tokens specified in the request was reached, `content_filter` if
+     * content was omitted due to a flag from our content filters, `tool_calls` if the
+     * model called a tool, or `function_call` (deprecated) if the model called a
+     * function.
+     */
+    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call' | null;
+
+    /**
+     * The index of the choice in the list of choices.
+     */
+    index: number;
+
+    /**
+     * Log probability information for the choice.
+     */
+    logprobs?: Choice.Logprobs | null;
+  }
+
+  export namespace Choice {
+    /**
+     * A chat completion delta generated by streamed model responses.
+     */
+    export interface Delta {
+      /**
+       * The contents of the chunk message.
+       */
+      content?: string | null;
+
+      /**
+       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+       * function that should be called, as generated by the model.
+       */
+      function_call?: Delta.FunctionCall;
+
+      /**
+       * The refusal message generated by the model.
+       */
+      refusal?: string | null;
+
+      /**
+       * The role of the author of this message.
+       */
+      role?: 'developer' | 'system' | 'user' | 'assistant' | 'tool';
+
+      tool_calls?: Array<Delta.ToolCall>;
+    }
+
+    export namespace Delta {
+      /**
+       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+       * function that should be called, as generated by the model.
+       */
+      export interface FunctionCall {
+        /**
+         * The arguments to call the function with, as generated by the model in JSON
+         * format. Note that the model does not always generate valid JSON, and may
+         * hallucinate parameters not defined by your function schema. Validate the
+         * arguments in your code before calling your function.
+         */
+        arguments?: string;
+
+        /**
+         * The name of the function to call.
+         */
+        name?: string;
+      }
+
+      export interface ToolCall {
+        index: number;
+
+        /**
+         * The ID of the tool call.
+         */
+        id?: string;
+
+        function?: ToolCall.Function;
+
+        /**
+         * The type of the tool. Currently, only `function` is supported.
+         */
+        type?: 'function';
+      }
+
+      export namespace ToolCall {
+        export interface Function {
+          /**
+           * The arguments to call the function with, as generated by the model in JSON
+           * format. Note that the model does not always generate valid JSON, and may
+           * hallucinate parameters not defined by your function schema. Validate the
+           * arguments in your code before calling your function.
+           */
+          arguments?: string;
+
+          /**
+           * The name of the function to call.
+           */
+          name?: string;
+        }
+      }
+    }
+
+    /**
+     * Log probability information for the choice.
+     */
+    export interface Logprobs {
+      /**
+       * A list of message content tokens with log probability information.
+       */
+      content: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
+
+      /**
+       * A list of message refusal tokens with log probability information.
+       */
+      refusal: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
+    }
+  }
+}
+
+/**
+ * Learn about
+ * [text inputs](https://platform.openai.com/docs/guides/text-generation).
+ */
+export type ChatCompletionContentPart =
+  | ChatCompletionContentPartText
+  | ChatCompletionContentPartImage
+  | ChatCompletionContentPartInputAudio;
+
+/**
+ * Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
+ */
+export interface ChatCompletionContentPartImage {
+  image_url: ChatCompletionContentPartImage.ImageURL;
+
+  /**
+   * The type of the content part.
+   */
+  type: 'image_url';
+}
+
+export namespace ChatCompletionContentPartImage {
+  export interface ImageURL {
+    /**
+     * Either a URL of the image or the base64 encoded image data.
+     */
+    url: string;
+
+    /**
+     * Specifies the detail level of the image. Learn more in the
+     * [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
+     */
+    detail?: 'auto' | 'low' | 'high';
+  }
+}
+
+/**
+ * Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
+ */
+export interface ChatCompletionContentPartInputAudio {
+  input_audio: ChatCompletionContentPartInputAudio.InputAudio;
+
+  /**
+   * The type of the content part. Always `input_audio`.
+   */
+  type: 'input_audio';
+}
+
+export namespace ChatCompletionContentPartInputAudio {
+  export interface InputAudio {
+    /**
+     * Base64 encoded audio data.
+     */
+    data: string;
+
+    /**
+     * The format of the encoded audio data. Currently supports "wav" and "mp3".
+     */
+    format: 'wav' | 'mp3';
+  }
+}
+
+export interface ChatCompletionContentPartRefusal {
+  /**
+   * The refusal message generated by the model.
+   */
+  refusal: string;
+
+  /**
+   * The type of the content part,.
+   */
+  type: 'refusal';
+}
+
+/**
+ * Learn about
+ * [text inputs](https://platform.openai.com/docs/guides/text-generation).
+ */
+export interface ChatCompletionContentPartText {
+  /**
+   * The text content.
+   */
+  text: string;
+
+  /**
+   * The type of the content part.
+   */
+  type: 'text';
+}
+
+export interface ChatCompletionDeleted {
+  /**
+   * The ID of the chat completion that was deleted.
+   */
+  id: string;
+
+  /**
+   * Whether the chat completion was deleted.
+   */
+  deleted: boolean;
+
+  /**
+   * The type of object being deleted.
+   */
+  object: 'chat.completion.deleted';
+}
+
+/**
+ * Developer-provided instructions that the model should follow, regardless of
+ * messages sent by the user. With o1 models and newer, `developer` messages
+ * replace the previous `system` messages.
+ */
+export interface ChatCompletionDeveloperMessageParam {
+  /**
+   * The contents of the developer message.
+   */
+  content: string | Array<ChatCompletionContentPartText>;
+
+  /**
+   * The role of the messages author, in this case `developer`.
+   */
+  role: 'developer';
+
+  /**
+   * An optional name for the participant. Provides the model information to
+   * differentiate between participants of the same role.
+   */
+  name?: string;
+}
+
+/**
+ * Specifying a particular function via `{"name": "my_function"}` forces the model
+ * to call that function.
+ */
+export interface ChatCompletionFunctionCallOption {
+  /**
+   * The name of the function to call.
+   */
+  name: string;
+}
+
+/**
+ * @deprecated
+ */
+export interface ChatCompletionFunctionMessageParam {
+  /**
+   * The contents of the function message.
+   */
+  content: string | null;
+
+  /**
+   * The name of the function to call.
+   */
+  name: string;
+
+  /**
+   * The role of the messages author, in this case `function`.
+   */
+  role: 'function';
+}
+
+/**
+ * A chat completion message generated by the model.
+ */
+export interface ChatCompletionMessage {
+  /**
+   * The contents of the message.
+   */
+  content: string | null;
+
+  /**
+   * The refusal message generated by the model.
+   */
+  refusal: string | null;
+
+  /**
+   * The role of the author of this message.
+   */
+  role: 'assistant';
+
+  /**
+   * If the audio output modality is requested, this object contains data about the
+   * audio response from the model.
+   * [Learn more](https://platform.openai.com/docs/guides/audio).
+   */
+  audio?: ChatCompletionAudio | null;
+
+  /**
+   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+   * function that should be called, as generated by the model.
+   */
+  function_call?: ChatCompletionMessage.FunctionCall | null;
+
+  /**
+   * The tool calls generated by the model, such as function calls.
+   */
+  tool_calls?: Array<ChatCompletionMessageToolCall>;
+}
+
+export namespace ChatCompletionMessage {
+  /**
+   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+   * function that should be called, as generated by the model.
+   */
+  export interface FunctionCall {
+    /**
+     * The arguments to call the function with, as generated by the model in JSON
+     * format. Note that the model does not always generate valid JSON, and may
+     * hallucinate parameters not defined by your function schema. Validate the
+     * arguments in your code before calling your function.
+     */
+    arguments: string;
+
+    /**
+     * The name of the function to call.
+     */
+    name: string;
+  }
+}
+
+/**
+ * Developer-provided instructions that the model should follow, regardless of
+ * messages sent by the user. With o1 models and newer, `developer` messages
+ * replace the previous `system` messages.
+ */
+export type ChatCompletionMessageParam =
+  | ChatCompletionDeveloperMessageParam
+  | ChatCompletionSystemMessageParam
+  | ChatCompletionUserMessageParam
+  | ChatCompletionAssistantMessageParam
+  | ChatCompletionToolMessageParam
+  | ChatCompletionFunctionMessageParam;
+
+export interface ChatCompletionMessageToolCall {
+  /**
+   * The ID of the tool call.
+   */
+  id: string;
+
+  /**
+   * The function that the model called.
+   */
+  function: ChatCompletionMessageToolCall.Function;
+
+  /**
+   * The type of the tool. Currently, only `function` is supported.
+   */
+  type: 'function';
+}
+
+export namespace ChatCompletionMessageToolCall {
+  /**
+   * The function that the model called.
+   */
+  export interface Function {
+    /**
+     * The arguments to call the function with, as generated by the model in JSON
+     * format. Note that the model does not always generate valid JSON, and may
+     * hallucinate parameters not defined by your function schema. Validate the
+     * arguments in your code before calling your function.
+     */
+    arguments: string;
+
+    /**
+     * The name of the function to call.
+     */
+    name: string;
+  }
+}
+
+export type ChatCompletionModality = 'text' | 'audio';
+
+/**
+ * Specifies a tool the model should use. Use to force the model to call a specific
+ * function.
+ */
+export interface ChatCompletionNamedToolChoice {
+  function: ChatCompletionNamedToolChoice.Function;
+
+  /**
+   * The type of the tool. Currently, only `function` is supported.
+   */
+  type: 'function';
+}
+
+export namespace ChatCompletionNamedToolChoice {
+  export interface Function {
+    /**
+     * The name of the function to call.
+     */
+    name: string;
+  }
+}
+
+/**
+ * Static predicted output content, such as the content of a text file that is
+ * being regenerated.
+ */
+export interface ChatCompletionPredictionContent {
+  /**
+   * The content that should be matched when generating a model response. If
+   * generated tokens would match this content, the entire model response can be
+   * returned much more quickly.
+   */
+  content: string | Array<ChatCompletionContentPartText>;
+
+  /**
+   * The type of the predicted content you want to provide. This type is currently
+   * always `content`.
+   */
+  type: 'content';
+}
+
+/**
+ * **o1 and o3-mini models only**
+ *
+ * Constrains effort on reasoning for
+ * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+ * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+ * result in faster responses and fewer tokens used on reasoning in a response.
+ */
+export type ChatCompletionReasoningEffort = 'low' | 'medium' | 'high' | null;
+
+/**
+ * The role of the author of a message
+ */
+export type ChatCompletionRole = 'developer' | 'system' | 'user' | 'assistant' | 'tool' | 'function';
+
+/**
+ * A chat completion message generated by the model.
+ */
+export interface ChatCompletionStoreMessage extends ChatCompletionMessage {
+  /**
+   * The identifier of the chat message.
+   */
+  id: string;
+}
+
+/**
+ * Options for streaming response. Only set this when you set `stream: true`.
+ */
+export interface ChatCompletionStreamOptions {
+  /**
+   * If set, an additional chunk will be streamed before the `data: [DONE]` message.
+   * The `usage` field on this chunk shows the token usage statistics for the entire
+   * request, and the `choices` field will always be an empty array. All other chunks
+   * will also include a `usage` field, but with a null value.
+   */
+  include_usage?: boolean;
+}
+
+/**
+ * Developer-provided instructions that the model should follow, regardless of
+ * messages sent by the user. With o1 models and newer, use `developer` messages
+ * for this purpose instead.
+ */
+export interface ChatCompletionSystemMessageParam {
+  /**
+   * The contents of the system message.
+   */
+  content: string | Array<ChatCompletionContentPartText>;
+
+  /**
+   * The role of the messages author, in this case `system`.
+   */
+  role: 'system';
+
+  /**
+   * An optional name for the participant. Provides the model information to
+   * differentiate between participants of the same role.
+   */
+  name?: string;
+}
+
+export interface ChatCompletionTokenLogprob {
+  /**
+   * The token.
+   */
+  token: string;
+
+  /**
+   * A list of integers representing the UTF-8 bytes representation of the token.
+   * Useful in instances where characters are represented by multiple tokens and
+   * their byte representations must be combined to generate the correct text
+   * representation. Can be `null` if there is no bytes representation for the token.
+   */
+  bytes: Array<number> | null;
+
+  /**
+   * The log probability of this token, if it is within the top 20 most likely
+   * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
+   * unlikely.
+   */
+  logprob: number;
+
+  /**
+   * List of the most likely tokens and their log probability, at this token
+   * position. In rare cases, there may be fewer than the number of requested
+   * `top_logprobs` returned.
+   */
+  top_logprobs: Array<ChatCompletionTokenLogprob.TopLogprob>;
+}
+
+export namespace ChatCompletionTokenLogprob {
+  export interface TopLogprob {
+    /**
+     * The token.
+     */
+    token: string;
+
+    /**
+     * A list of integers representing the UTF-8 bytes representation of the token.
+     * Useful in instances where characters are represented by multiple tokens and
+     * their byte representations must be combined to generate the correct text
+     * representation. Can be `null` if there is no bytes representation for the token.
+     */
+    bytes: Array<number> | null;
+
+    /**
+     * The log probability of this token, if it is within the top 20 most likely
+     * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
+     * unlikely.
+     */
+    logprob: number;
+  }
+}
+
+export interface ChatCompletionTool {
+  function: Shared.FunctionDefinition;
+
+  /**
+   * The type of the tool. Currently, only `function` is supported.
+   */
+  type: 'function';
+}
+
+/**
+ * Controls which (if any) tool is called by the model. `none` means the model will
+ * not call any tool and instead generates a message. `auto` means the model can
+ * pick between generating a message or calling one or more tools. `required` means
+ * the model must call one or more tools. Specifying a particular tool via
+ * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
+ * call that tool.
+ *
+ * `none` is the default when no tools are present. `auto` is the default if tools
+ * are present.
+ */
+export type ChatCompletionToolChoiceOption = 'none' | 'auto' | 'required' | ChatCompletionNamedToolChoice;
+
+export interface ChatCompletionToolMessageParam {
+  /**
+   * The contents of the tool message.
+   */
+  content: string | Array<ChatCompletionContentPartText>;
+
+  /**
+   * The role of the messages author, in this case `tool`.
+   */
+  role: 'tool';
+
+  /**
+   * Tool call that this message is responding to.
+   */
+  tool_call_id: string;
+}
+
+/**
+ * Messages sent by an end user, containing prompts or additional context
+ * information.
+ */
+export interface ChatCompletionUserMessageParam {
+  /**
+   * The contents of the user message.
+   */
+  content: string | Array<ChatCompletionContentPart>;
+
+  /**
+   * The role of the messages author, in this case `user`.
+   */
+  role: 'user';
+
+  /**
+   * An optional name for the participant. Provides the model information to
+   * differentiate between participants of the same role.
+   */
+  name?: string;
+}
+
+/**
+ * @deprecated ChatCompletionMessageParam should be used instead
+ */
+export type CreateChatCompletionRequestMessage = ChatCompletionMessageParam;
+
+export type ChatCompletionCreateParams =
+  | ChatCompletionCreateParamsNonStreaming
+  | ChatCompletionCreateParamsStreaming;
+
+export interface ChatCompletionCreateParamsBase {
+  /**
+   * A list of messages comprising the conversation so far. Depending on the
+   * [model](https://platform.openai.com/docs/models) you use, different message
+   * types (modalities) are supported, like
+   * [text](https://platform.openai.com/docs/guides/text-generation),
+   * [images](https://platform.openai.com/docs/guides/vision), and
+   * [audio](https://platform.openai.com/docs/guides/audio).
+   */
+  messages: Array<ChatCompletionMessageParam>;
+
+  /**
+   * ID of the model to use. See the
+   * [model endpoint compatibility](https://platform.openai.com/docs/models#model-endpoint-compatibility)
+   * table for details on which models work with the Chat API.
+   */
+  model: (string & {}) | ChatAPI.ChatModel;
+
+  /**
+   * Parameters for audio output. Required when audio output is requested with
+   * `modalities: ["audio"]`.
+   * [Learn more](https://platform.openai.com/docs/guides/audio).
+   */
+  audio?: ChatCompletionAudioParam | null;
+
+  /**
+   * Number between -2.0 and 2.0. Positive values penalize new tokens based on their
+   * existing frequency in the text so far, decreasing the model's likelihood to
+   * repeat the same line verbatim.
+   */
+  frequency_penalty?: number | null;
+
+  /**
+   * Deprecated in favor of `tool_choice`.
+   *
+   * Controls which (if any) function is called by the model.
+   *
+   * `none` means the model will not call a function and instead generates a message.
+   *
+   * `auto` means the model can pick between generating a message or calling a
+   * function.
+   *
+   * Specifying a particular function via `{"name": "my_function"}` forces the model
+   * to call that function.
+   *
+   * `none` is the default when no functions are present. `auto` is the default if
+   * functions are present.
+   */
+  function_call?: 'none' | 'auto' | ChatCompletionFunctionCallOption;
+
+  /**
+   * Deprecated in favor of `tools`.
+   *
+   * A list of functions the model may generate JSON inputs for.
+   */
+  functions?: Array<ChatCompletionCreateParams.Function>;
+
+  /**
+   * Modify the likelihood of specified tokens appearing in the completion.
+   *
+   * Accepts a JSON object that maps tokens (specified by their token ID in the
+   * tokenizer) to an associated bias value from -100 to 100. Mathematically, the
+   * bias is added to the logits generated by the model prior to sampling. The exact
+   * effect will vary per model, but values between -1 and 1 should decrease or
+   * increase likelihood of selection; values like -100 or 100 should result in a ban
+   * or exclusive selection of the relevant token.
+   */
+  logit_bias?: Record<string, number> | null;
+
+  /**
+   * Whether to return log probabilities of the output tokens or not. If true,
+   * returns the log probabilities of each output token returned in the `content` of
+   * `message`.
+   */
+  logprobs?: boolean | null;
+
+  /**
+   * An upper bound for the number of tokens that can be generated for a completion,
+   * including visible output tokens and
+   * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
+   */
+  max_completion_tokens?: number | null;
+
+  /**
+   * The maximum number of [tokens](/tokenizer) that can be generated in the chat
+   * completion. This value can be used to control
+   * [costs](https://openai.com/api/pricing/) for text generated via API.
+   *
+   * This value is now deprecated in favor of `max_completion_tokens`, and is not
+   * compatible with
+   * [o1 series models](https://platform.openai.com/docs/guides/reasoning).
+   */
+  max_tokens?: number | null;
+
+  /**
+   * Set of 16 key-value pairs that can be attached to an object. This can be useful
+   * for storing additional information about the object in a structured format, and
+   * querying for objects via API or the dashboard.
+   *
+   * Keys are strings with a maximum length of 64 characters. Values are strings with
+   * a maximum length of 512 characters.
+   */
+  metadata?: Shared.Metadata | null;
+
+  /**
+   * Output types that you would like the model to generate for this request. Most
+   * models are capable of generating text, which is the default:
+   *
+   * `["text"]`
+   *
+   * The `gpt-4o-audio-preview` model can also be used to
+   * [generate audio](https://platform.openai.com/docs/guides/audio). To request that
+   * this model generate both text and audio responses, you can use:
+   *
+   * `["text", "audio"]`
+   */
+  modalities?: Array<ChatCompletionModality> | null;
+
+  /**
+   * How many chat completion choices to generate for each input message. Note that
+   * you will be charged based on the number of generated tokens across all of the
+   * choices. Keep `n` as `1` to minimize costs.
+   */
+  n?: number | null;
+
+  /**
+   * Whether to enable
+   * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
+   * during tool use.
+   */
+  parallel_tool_calls?: boolean;
+
+  /**
+   * Static predicted output content, such as the content of a text file that is
+   * being regenerated.
+   */
+  prediction?: ChatCompletionPredictionContent | null;
+
+  /**
+   * Number between -2.0 and 2.0. Positive values penalize new tokens based on
+   * whether they appear in the text so far, increasing the model's likelihood to
+   * talk about new topics.
+   */
+  presence_penalty?: number | null;
+
+  /**
+   * **o1 and o3-mini models only**
+   *
+   * Constrains effort on reasoning for
+   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+   * result in faster responses and fewer tokens used on reasoning in a response.
+   */
+  reasoning_effort?: ChatCompletionReasoningEffort | null;
+
+  /**
+   * An object specifying the format that the model must output.
+   *
+   * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
+   * Outputs which ensures the model will match your supplied JSON schema. Learn more
+   * in the
+   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
+   *
+   * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
+   * message the model generates is valid JSON.
+   *
+   * **Important:** when using JSON mode, you **must** also instruct the model to
+   * produce JSON yourself via a system or user message. Without this, the model may
+   * generate an unending stream of whitespace until the generation reaches the token
+   * limit, resulting in a long-running and seemingly "stuck" request. Also note that
+   * the message content may be partially cut off if `finish_reason="length"`, which
+   * indicates the generation exceeded `max_tokens` or the conversation exceeded the
+   * max context length.
+   */
+  response_format?:
+    | Shared.ResponseFormatText
+    | Shared.ResponseFormatJSONObject
+    | Shared.ResponseFormatJSONSchema;
+
+  /**
+   * This feature is in Beta. If specified, our system will make a best effort to
+   * sample deterministically, such that repeated requests with the same `seed` and
+   * parameters should return the same result. Determinism is not guaranteed, and you
+   * should refer to the `system_fingerprint` response parameter to monitor changes
+   * in the backend.
+   */
+  seed?: number | null;
+
+  /**
+   * Specifies the latency tier to use for processing the request. This parameter is
+   * relevant for customers subscribed to the scale tier service:
+   *
+   * - If set to 'auto', and the Project is Scale tier enabled, the system will
+   *   utilize scale tier credits until they are exhausted.
+   * - If set to 'auto', and the Project is not Scale tier enabled, the request will
+   *   be processed using the default service tier with a lower uptime SLA and no
+   *   latency guarantee.
+   * - If set to 'default', the request will be processed using the default service
+   *   tier with a lower uptime SLA and no latency guarantee.
+   * - When not set, the default behavior is 'auto'.
+   */
+  service_tier?: 'auto' | 'default' | null;
+
+  /**
+   * Up to 4 sequences where the API will stop generating further tokens.
+   */
+  stop?: string | null | Array<string>;
+
+  /**
+   * Whether or not to store the output of this chat completion request for use in
+   * our [model distillation](https://platform.openai.com/docs/guides/distillation)
+   * or [evals](https://platform.openai.com/docs/guides/evals) products.
+   */
+  store?: boolean | null;
+
+  /**
+   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
+   * sent as data-only
+   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
+   * as they become available, with the stream terminated by a `data: [DONE]`
+   * message.
+   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
+   */
+  stream?: boolean | null;
+
+  /**
+   * Options for streaming response. Only set this when you set `stream: true`.
+   */
+  stream_options?: ChatCompletionStreamOptions | null;
+
+  /**
+   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
+   * make the output more random, while lower values like 0.2 will make it more
+   * focused and deterministic. We generally recommend altering this or `top_p` but
+   * not both.
+   */
+  temperature?: number | null;
+
+  /**
+   * Controls which (if any) tool is called by the model. `none` means the model will
+   * not call any tool and instead generates a message. `auto` means the model can
+   * pick between generating a message or calling one or more tools. `required` means
+   * the model must call one or more tools. Specifying a particular tool via
+   * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
+   * call that tool.
+   *
+   * `none` is the default when no tools are present. `auto` is the default if tools
+   * are present.
+   */
+  tool_choice?: ChatCompletionToolChoiceOption;
+
+  /**
+   * A list of tools the model may call. Currently, only functions are supported as a
+   * tool. Use this to provide a list of functions the model may generate JSON inputs
+   * for. A max of 128 functions are supported.
+   */
+  tools?: Array<ChatCompletionTool>;
+
+  /**
+   * An integer between 0 and 20 specifying the number of most likely tokens to
+   * return at each token position, each with an associated log probability.
+   * `logprobs` must be set to `true` if this parameter is used.
+   */
+  top_logprobs?: number | null;
+
+  /**
+   * An alternative to sampling with temperature, called nucleus sampling, where the
+   * model considers the results of the tokens with top_p probability mass. So 0.1
+   * means only the tokens comprising the top 10% probability mass are considered.
+   *
+   * We generally recommend altering this or `temperature` but not both.
+   */
+  top_p?: number | null;
+
+  /**
+   * A unique identifier representing your end-user, which can help OpenAI to monitor
+   * and detect abuse.
+   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
+   */
+  user?: string;
+}
+
+export namespace ChatCompletionCreateParams {
+  /**
+   * @deprecated
+   */
+  export interface Function {
+    /**
+     * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
+     * underscores and dashes, with a maximum length of 64.
+     */
+    name: string;
+
+    /**
+     * A description of what the function does, used by the model to choose when and
+     * how to call the function.
+     */
+    description?: string;
+
+    /**
+     * The parameters the functions accepts, described as a JSON Schema object. See the
+     * [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
+     * and the
+     * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
+     * documentation about the format.
+     *
+     * Omitting `parameters` defines a function with an empty parameter list.
+     */
+    parameters?: Shared.FunctionParameters;
+  }
+
+  export type ChatCompletionCreateParamsNonStreaming =
+    CompletionsCompletionsAPI.ChatCompletionCreateParamsNonStreaming;
+  export type ChatCompletionCreateParamsStreaming =
+    CompletionsCompletionsAPI.ChatCompletionCreateParamsStreaming;
+}
+
+/**
+ * @deprecated Use ChatCompletionCreateParams instead
+ */
+export type CompletionCreateParams = ChatCompletionCreateParams;
+
+export interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase {
+  /**
+   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
+   * sent as data-only
+   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
+   * as they become available, with the stream terminated by a `data: [DONE]`
+   * message.
+   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
+   */
+  stream?: false | null;
+}
+
+/**
+ * @deprecated Use ChatCompletionCreateParamsNonStreaming instead
+ */
+export type CompletionCreateParamsNonStreaming = ChatCompletionCreateParamsNonStreaming;
+
+export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreateParamsBase {
+  /**
+   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
+   * sent as data-only
+   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
+   * as they become available, with the stream terminated by a `data: [DONE]`
+   * message.
+   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
+   */
+  stream: true;
+}
+
+/**
+ * @deprecated Use ChatCompletionCreateParamsStreaming instead
+ */
+export type CompletionCreateParamsStreaming = ChatCompletionCreateParamsStreaming;
+
+export interface ChatCompletionUpdateParams {
+  /**
+   * Set of 16 key-value pairs that can be attached to an object. This can be useful
+   * for storing additional information about the object in a structured format, and
+   * querying for objects via API or the dashboard.
+   *
+   * Keys are strings with a maximum length of 64 characters. Values are strings with
+   * a maximum length of 512 characters.
+   */
+  metadata: Shared.Metadata | null;
+}
+
+/**
+ * @deprecated Use ChatCompletionUpdateParams instead
+ */
+export type CompletionUpdateParams = ChatCompletionUpdateParams;
+
+export interface ChatCompletionListParams extends CursorPageParams {
+  /**
+   * A list of metadata keys to filter the chat completions by. Example:
+   *
+   * `metadata[key1]=value1&metadata[key2]=value2`
+   */
+  metadata?: Shared.Metadata | null;
+
+  /**
+   * The model used to generate the chat completions.
+   */
+  model?: string;
+
+  /**
+   * Sort order for chat completions by timestamp. Use `asc` for ascending order or
+   * `desc` for descending order. Defaults to `asc`.
+   */
+  order?: 'asc' | 'desc';
+}
+
+/**
+ * @deprecated Use ChatCompletionListParams instead
+ */
+export type CompletionListParams = ChatCompletionListParams;
+
+Completions.ChatCompletionsPage = ChatCompletionsPage;
+Completions.Messages = Messages;
+
+export declare namespace Completions {
+  export {
+    type ChatCompletion as ChatCompletion,
+    type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,
+    type ChatCompletionAudio as ChatCompletionAudio,
+    type ChatCompletionAudioParam as ChatCompletionAudioParam,
+    type ChatCompletionChunk as ChatCompletionChunk,
+    type ChatCompletionContentPart as ChatCompletionContentPart,
+    type ChatCompletionContentPartImage as ChatCompletionContentPartImage,
+    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,
+    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,
+    type ChatCompletionContentPartText as ChatCompletionContentPartText,
+    type ChatCompletionDeleted as ChatCompletionDeleted,
+    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,
+    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
+    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
+    type ChatCompletionMessage as ChatCompletionMessage,
+    type ChatCompletionMessageParam as ChatCompletionMessageParam,
+    type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,
+    type ChatCompletionModality as ChatCompletionModality,
+    type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,
+    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,
+    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,
+    type ChatCompletionRole as ChatCompletionRole,
+    type ChatCompletionStoreMessage as ChatCompletionStoreMessage,
+    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,
+    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
+    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
+    type ChatCompletionTool as ChatCompletionTool,
+    type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,
+    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
+    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
+    type CreateChatCompletionRequestMessage as CreateChatCompletionRequestMessage,
+    ChatCompletionsPage as ChatCompletionsPage,
+    type ChatCompletionCreateParams as ChatCompletionCreateParams,
+    type CompletionCreateParams as CompletionCreateParams,
+    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,
+    type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
+    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,
+    type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
+    type ChatCompletionUpdateParams as ChatCompletionUpdateParams,
+    type CompletionUpdateParams as CompletionUpdateParams,
+    type ChatCompletionListParams as ChatCompletionListParams,
+    type CompletionListParams as CompletionListParams,
+  };
+
+  export { Messages as Messages, type MessageListParams as MessageListParams };
+}
diff --git a/src/resources/chat/completions/index.ts b/src/resources/chat/completions/index.ts
new file mode 100644
index 000000000..3691f41d8
--- /dev/null
+++ src/resources/chat/completions/index.ts
@@ -0,0 +1,49 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+export {
+  ChatCompletionStoreMessagesPage,
+  ChatCompletionsPage,
+  Completions,
+  type ChatCompletion,
+  type ChatCompletionAssistantMessageParam,
+  type ChatCompletionAudio,
+  type ChatCompletionAudioParam,
+  type ChatCompletionChunk,
+  type ChatCompletionContentPart,
+  type ChatCompletionContentPartImage,
+  type ChatCompletionContentPartInputAudio,
+  type ChatCompletionContentPartRefusal,
+  type ChatCompletionContentPartText,
+  type ChatCompletionDeleted,
+  type ChatCompletionDeveloperMessageParam,
+  type ChatCompletionFunctionCallOption,
+  type ChatCompletionFunctionMessageParam,
+  type ChatCompletionMessage,
+  type ChatCompletionMessageParam,
+  type ChatCompletionMessageToolCall,
+  type ChatCompletionModality,
+  type ChatCompletionNamedToolChoice,
+  type ChatCompletionPredictionContent,
+  type ChatCompletionReasoningEffort,
+  type ChatCompletionRole,
+  type ChatCompletionStoreMessage,
+  type ChatCompletionStreamOptions,
+  type ChatCompletionSystemMessageParam,
+  type ChatCompletionTokenLogprob,
+  type ChatCompletionTool,
+  type ChatCompletionToolChoiceOption,
+  type ChatCompletionToolMessageParam,
+  type ChatCompletionUserMessageParam,
+  type CreateChatCompletionRequestMessage,
+  type ChatCompletionCreateParams,
+  type CompletionCreateParams,
+  type ChatCompletionCreateParamsNonStreaming,
+  type CompletionCreateParamsNonStreaming,
+  type ChatCompletionCreateParamsStreaming,
+  type CompletionCreateParamsStreaming,
+  type ChatCompletionUpdateParams,
+  type CompletionUpdateParams,
+  type ChatCompletionListParams,
+  type CompletionListParams,
+} from './completions';
+export { Messages, type MessageListParams } from './messages';
diff --git a/src/resources/chat/completions/messages.ts b/src/resources/chat/completions/messages.ts
new file mode 100644
index 000000000..fc1cc5d94
--- /dev/null
+++ src/resources/chat/completions/messages.ts
@@ -0,0 +1,52 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import { APIResource } from '../../../resource';
+import { isRequestOptions } from '../../../core';
+import * as Core from '../../../core';
+import * as CompletionsAPI from './completions';
+import { ChatCompletionStoreMessagesPage } from './completions';
+import { type CursorPageParams } from '../../../pagination';
+
+export class Messages extends APIResource {
+  /**
+   * Get the messages in a stored chat completion. Only chat completions that have
+   * been created with the `store` parameter set to `true` will be returned.
+   */
+  list(
+    completionId: string,
+    query?: MessageListParams,
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionStoreMessagesPage, CompletionsAPI.ChatCompletionStoreMessage>;
+  list(
+    completionId: string,
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionStoreMessagesPage, CompletionsAPI.ChatCompletionStoreMessage>;
+  list(
+    completionId: string,
+    query: MessageListParams | Core.RequestOptions = {},
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionStoreMessagesPage, CompletionsAPI.ChatCompletionStoreMessage> {
+    if (isRequestOptions(query)) {
+      return this.list(completionId, {}, query);
+    }
+    return this._client.getAPIList(
+      `/chat/completions/${completionId}/messages`,
+      ChatCompletionStoreMessagesPage,
+      { query, ...options },
+    );
+  }
+}
+
+export interface MessageListParams extends CursorPageParams {
+  /**
+   * Sort order for messages by timestamp. Use `asc` for ascending order or `desc`
+   * for descending order. Defaults to `asc`.
+   */
+  order?: 'asc' | 'desc';
+}
+
+export declare namespace Messages {
+  export { type MessageListParams as MessageListParams };
+}
+
+export { ChatCompletionStoreMessagesPage };
diff --git src/resources/chat/index.ts src/resources/chat/index.ts
index c3be19402..a9b5b46fb 100644
--- src/resources/chat/index.ts
+++ src/resources/chat/index.ts
@@ -2,6 +2,8 @@

export { Chat, type ChatModel } from './chat';
export {
+  ChatCompletionStoreMessagesPage,
+  ChatCompletionsPage,
  Completions,
  type ChatCompletion,
  type ChatCompletionAssistantMessageParam,
@@ -13,6 +15,7 @@ export {
  type ChatCompletionContentPartInputAudio,
  type ChatCompletionContentPartRefusal,
  type ChatCompletionContentPartText,
+  type ChatCompletionDeleted,
  type ChatCompletionDeveloperMessageParam,
  type ChatCompletionFunctionCallOption,
  type ChatCompletionFunctionMessageParam,
@@ -24,6 +27,7 @@ export {
  type ChatCompletionPredictionContent,
  type ChatCompletionReasoningEffort,
  type ChatCompletionRole,
+  type ChatCompletionStoreMessage,
  type ChatCompletionStreamOptions,
  type ChatCompletionSystemMessageParam,
  type ChatCompletionTokenLogprob,
@@ -38,4 +42,8 @@ export {
  type CompletionCreateParamsNonStreaming,
  type ChatCompletionCreateParamsStreaming,
  type CompletionCreateParamsStreaming,
-} from './completions';
+  type ChatCompletionUpdateParams,
+  type CompletionUpdateParams,
+  type ChatCompletionListParams,
+  type CompletionListParams,
+} from './completions/index';
diff --git src/resources/completions.ts src/resources/completions.ts
index be75a46f0..664e39d9d 100644
--- src/resources/completions.ts
+++ src/resources/completions.ts
@@ -4,7 +4,7 @@ import { APIResource } from '../resource';
import { APIPromise } from '../core';
import * as Core from '../core';
import * as CompletionsAPI from './completions';
-import * as ChatCompletionsAPI from './chat/completions';
+import * as CompletionsCompletionsAPI from './chat/completions/completions';
import { Stream } from '../streaming';

export class Completions extends APIResource {
@@ -311,7 +311,7 @@ export interface CompletionCreateParamsBase {
  /**
   * Options for streaming response. Only set this when you set `stream: true`.
   */
-  stream_options?: ChatCompletionsAPI.ChatCompletionStreamOptions | null;
+  stream_options?: CompletionsCompletionsAPI.ChatCompletionStreamOptions | null;

  /**
   * The suffix that comes after a completion of inserted text.
diff --git src/resources/moderations.ts src/resources/moderations.ts
index f7b16166d..86e90376d 100644
--- src/resources/moderations.ts
+++ src/resources/moderations.ts
@@ -75,14 +75,14 @@ export namespace Moderation {
     * execution of wrongdoing, or that gives advice or instruction on how to commit
     * illicit acts. For example, "how to shoplift" would fit this category.
     */
-    illicit: boolean;
+    illicit: boolean | null;

    /**
     * Content that includes instructions or advice that facilitate the planning or
     * execution of wrongdoing that also includes violence, or that gives advice or
     * instruction on the procurement of any weapon.
     */
-    'illicit/violent': boolean;
+    'illicit/violent': boolean | null;

    /**
     * Content that promotes, encourages, or depicts acts of self-harm, such as
diff --git src/streaming.ts src/streaming.ts
index 6a57a50a0..52266154c 100644
--- src/streaming.ts
+++ src/streaming.ts
@@ -1,6 +1,6 @@
import { ReadableStream, type Response } from './_shims/index';
import { OpenAIError } from './error';
-import { LineDecoder } from './internal/decoders/line';
+import { findDoubleNewlineIndex, LineDecoder } from './internal/decoders/line';
import { ReadableStreamToAsyncIterable } from './internal/stream-utils';

import { APIError } from './error';
@@ -259,37 +259,6 @@ async function* iterSSEChunks(iterator: AsyncIterableIterator<Bytes>): AsyncGene
  }
}

-function findDoubleNewlineIndex(buffer: Uint8Array): number {
-  // This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
-  // and returns the index right after the first occurrence of any pattern,
-  // or -1 if none of the patterns are found.
-  const newline = 0x0a; // \n
-  const carriage = 0x0d; // \r
-
-  for (let i = 0; i < buffer.length - 2; i++) {
-    if (buffer[i] === newline && buffer[i + 1] === newline) {
-      // \n\n
-      return i + 2;
-    }
-    if (buffer[i] === carriage && buffer[i + 1] === carriage) {
-      // \r\r
-      return i + 2;
-    }
-    if (
-      buffer[i] === carriage &&
-      buffer[i + 1] === newline &&
-      i + 3 < buffer.length &&
-      buffer[i + 2] === carriage &&
-      buffer[i + 3] === newline
-    ) {
-      // \r\n\r\n
-      return i + 4;
-    }
-  }
-
-  return -1;
-}
-
class SSEDecoder {
  private data: string[];
  private event: string | null;
@@ -345,17 +314,6 @@ class SSEDecoder {
  }
}

-/** This is an internal helper function that's just used for testing */
-export function _decodeChunks(chunks: string[]): string[] {
-  const decoder = new LineDecoder();
-  const lines: string[] = [];
-  for (const chunk of chunks) {
-    lines.push(...decoder.decode(chunk));
-  }
-
-  return lines;
-}
-
function partition(str: string, delimiter: string): [string, string, string] {
  const index = str.indexOf(delimiter);
  if (index !== -1) {
diff --git src/version.ts src/version.ts
index 13c764d7d..4fdc11dc7 100644
--- src/version.ts
+++ src/version.ts
@@ -1 +1 @@
-export const VERSION = '4.83.0'; // x-release-please-version
+export const VERSION = '4.85.2'; // x-release-please-version
diff --git tests/api-resources/beta/assistants.test.ts tests/api-resources/beta/assistants.test.ts
index 88a10ba8f..16bc9f942 100644
--- tests/api-resources/beta/assistants.test.ts
+++ tests/api-resources/beta/assistants.test.ts
@@ -27,6 +27,7 @@ describe('resource assistants', () => {
      instructions: 'instructions',
      metadata: { foo: 'string' },
      name: 'name',
+      reasoning_effort: 'low',
      response_format: 'auto',
      temperature: 1,
      tool_resources: {
diff --git tests/api-resources/beta/threads/runs/runs.test.ts tests/api-resources/beta/threads/runs/runs.test.ts
index 9b728403f..13ae89a00 100644
--- tests/api-resources/beta/threads/runs/runs.test.ts
+++ tests/api-resources/beta/threads/runs/runs.test.ts
@@ -39,6 +39,7 @@ describe('resource runs', () => {
      metadata: { foo: 'string' },
      model: 'gpt-4o',
      parallel_tool_calls: true,
+      reasoning_effort: 'low',
      response_format: 'auto',
      stream: false,
      temperature: 1,
diff --git tests/api-resources/chat/completions.test.ts tests/api-resources/chat/completions.test.ts
deleted file mode 100644
index 8f1bc7d4c..000000000
--- tests/api-resources/chat/completions.test.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-import OpenAI from 'openai';
-import { Response } from 'node-fetch';
-
-const client = new OpenAI({
-  apiKey: 'My API Key',
-  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
-});
-
-describe('resource completions', () => {
-  test('create: only required params', async () => {
-    const responsePromise = client.chat.completions.create({
-      messages: [{ content: 'string', role: 'developer' }],
-      model: 'gpt-4o',
-    });
-    const rawResponse = await responsePromise.asResponse();
-    expect(rawResponse).toBeInstanceOf(Response);
-    const response = await responsePromise;
-    expect(response).not.toBeInstanceOf(Response);
-    const dataAndResponse = await responsePromise.withResponse();
-    expect(dataAndResponse.data).toBe(response);
-    expect(dataAndResponse.response).toBe(rawResponse);
-  });
-
-  test('create: required and optional params', async () => {
-    const response = await client.chat.completions.create({
-      messages: [{ content: 'string', role: 'developer', name: 'name' }],
-      model: 'gpt-4o',
-      audio: { format: 'wav', voice: 'alloy' },
-      frequency_penalty: -2,
-      function_call: 'none',
-      functions: [{ name: 'name', description: 'description', parameters: { foo: 'bar' } }],
-      logit_bias: { foo: 0 },
-      logprobs: true,
-      max_completion_tokens: 0,
-      max_tokens: 0,
-      metadata: { foo: 'string' },
-      modalities: ['text'],
-      n: 1,
-      parallel_tool_calls: true,
-      prediction: { content: 'string', type: 'content' },
-      presence_penalty: -2,
-      reasoning_effort: 'low',
-      response_format: { type: 'text' },
-      seed: 0,
-      service_tier: 'auto',
-      stop: 'string',
-      store: true,
-      stream: false,
-      stream_options: { include_usage: true },
-      temperature: 1,
-      tool_choice: 'none',
-      tools: [
-        {
-          function: { name: 'name', description: 'description', parameters: { foo: 'bar' }, strict: true },
-          type: 'function',
-        },
-      ],
-      top_logprobs: 0,
-      top_p: 1,
-      user: 'user-1234',
-    });
-  });
-});
diff --git a/tests/api-resources/chat/completions/completions.test.ts b/tests/api-resources/chat/completions/completions.test.ts
new file mode 100644
index 000000000..acdd631db
--- /dev/null
+++ tests/api-resources/chat/completions/completions.test.ts
@@ -0,0 +1,144 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import OpenAI from 'openai';
+import { Response } from 'node-fetch';
+
+const client = new OpenAI({
+  apiKey: 'My API Key',
+  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
+});
+
+describe('resource completions', () => {
+  test('create: only required params', async () => {
+    const responsePromise = client.chat.completions.create({
+      messages: [{ content: 'string', role: 'developer' }],
+      model: 'gpt-4o',
+    });
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('create: required and optional params', async () => {
+    const response = await client.chat.completions.create({
+      messages: [{ content: 'string', role: 'developer', name: 'name' }],
+      model: 'gpt-4o',
+      audio: { format: 'wav', voice: 'alloy' },
+      frequency_penalty: -2,
+      function_call: 'none',
+      functions: [{ name: 'name', description: 'description', parameters: { foo: 'bar' } }],
+      logit_bias: { foo: 0 },
+      logprobs: true,
+      max_completion_tokens: 0,
+      max_tokens: 0,
+      metadata: { foo: 'string' },
+      modalities: ['text'],
+      n: 1,
+      parallel_tool_calls: true,
+      prediction: { content: 'string', type: 'content' },
+      presence_penalty: -2,
+      reasoning_effort: 'low',
+      response_format: { type: 'text' },
+      seed: 0,
+      service_tier: 'auto',
+      stop: 'string',
+      store: true,
+      stream: false,
+      stream_options: { include_usage: true },
+      temperature: 1,
+      tool_choice: 'none',
+      tools: [
+        {
+          function: { name: 'name', description: 'description', parameters: { foo: 'bar' }, strict: true },
+          type: 'function',
+        },
+      ],
+      top_logprobs: 0,
+      top_p: 1,
+      user: 'user-1234',
+    });
+  });
+
+  test('retrieve', async () => {
+    const responsePromise = client.chat.completions.retrieve('completion_id');
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('retrieve: request options instead of params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.retrieve('completion_id', { path: '/_stainless_unknown_path' }),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+
+  test('update: only required params', async () => {
+    const responsePromise = client.chat.completions.update('completion_id', { metadata: { foo: 'string' } });
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('update: required and optional params', async () => {
+    const response = await client.chat.completions.update('completion_id', { metadata: { foo: 'string' } });
+  });
+
+  test('list', async () => {
+    const responsePromise = client.chat.completions.list();
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('list: request options instead of params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(client.chat.completions.list({ path: '/_stainless_unknown_path' })).rejects.toThrow(
+      OpenAI.NotFoundError,
+    );
+  });
+
+  test('list: request options and params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.list(
+        { after: 'after', limit: 0, metadata: { foo: 'string' }, model: 'model', order: 'asc' },
+        { path: '/_stainless_unknown_path' },
+      ),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+
+  test('del', async () => {
+    const responsePromise = client.chat.completions.del('completion_id');
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('del: request options instead of params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.del('completion_id', { path: '/_stainless_unknown_path' }),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+});
diff --git a/tests/api-resources/chat/completions/messages.test.ts b/tests/api-resources/chat/completions/messages.test.ts
new file mode 100644
index 000000000..664106cb9
--- /dev/null
+++ tests/api-resources/chat/completions/messages.test.ts
@@ -0,0 +1,40 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import OpenAI from 'openai';
+import { Response } from 'node-fetch';
+
+const client = new OpenAI({
+  apiKey: 'My API Key',
+  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
+});
+
+describe('resource messages', () => {
+  test('list', async () => {
+    const responsePromise = client.chat.completions.messages.list('completion_id');
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('list: request options instead of params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.messages.list('completion_id', { path: '/_stainless_unknown_path' }),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+
+  test('list: request options and params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.messages.list(
+        'completion_id',
+        { after: 'after', limit: 0, order: 'asc' },
+        { path: '/_stainless_unknown_path' },
+      ),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+});
diff --git a/tests/internal/decoders/line.test.ts b/tests/internal/decoders/line.test.ts
new file mode 100644
index 000000000..e76858e55
--- /dev/null
+++ tests/internal/decoders/line.test.ts
@@ -0,0 +1,128 @@
+import { findDoubleNewlineIndex, LineDecoder } from 'openai/internal/decoders/line';
+
+function decodeChunks(chunks: string[], { flush }: { flush: boolean } = { flush: false }): string[] {
+  const decoder = new LineDecoder();
+  const lines: string[] = [];
+  for (const chunk of chunks) {
+    lines.push(...decoder.decode(chunk));
+  }
+
+  if (flush) {
+    lines.push(...decoder.flush());
+  }
+
+  return lines;
+}
+
+describe('line decoder', () => {
+  test('basic', () => {
+    // baz is not included because the line hasn't ended yet
+    expect(decodeChunks(['foo', ' bar\nbaz'])).toEqual(['foo bar']);
+  });
+
+  test('basic with \\r', () => {
+    expect(decodeChunks(['foo', ' bar\r\nbaz'])).toEqual(['foo bar']);
+    expect(decodeChunks(['foo', ' bar\r\nbaz'], { flush: true })).toEqual(['foo bar', 'baz']);
+  });
+
+  test('trailing new lines', () => {
+    expect(decodeChunks(['foo', ' bar', 'baz\n', 'thing\n'])).toEqual(['foo barbaz', 'thing']);
+  });
+
+  test('trailing new lines with \\r', () => {
+    expect(decodeChunks(['foo', ' bar', 'baz\r\n', 'thing\r\n'])).toEqual(['foo barbaz', 'thing']);
+  });
+
+  test('escaped new lines', () => {
+    expect(decodeChunks(['foo', ' bar\\nbaz\n'])).toEqual(['foo bar\\nbaz']);
+  });
+
+  test('escaped new lines with \\r', () => {
+    expect(decod,eChunks(['foo', ' bar\\r\\nbaz\n'])).toEqual(['foo bar\\r\\nbaz']);
+  });
+
+  test('\\r & \\n split across multiple chunks', () => {
+    expect(decodeChunks(['foo\r', '\n', 'bar'], { flush: true })).toEqual(['foo', 'bar']);
+  });
+
+  test('single \\r', () => {
+    expect(decodeChunks(['foo\r', 'bar'], { flush: true })).toEqual(['foo', 'bar']);
+  });
+
+  test('double \\r', () => {
+    expect(decodeChunks(['foo\r', 'bar\r'], { flush: true })).toEqual(['foo', 'bar']);
+    expect(decodeChunks(['foo\r', '\r', 'bar'], { flush: true })).toEqual(['foo', '', 'bar']);
+    // implementation detail that we don't yield the single \r line until a new \r or \n is encountered
+    expect(decodeChunks(['foo\r', '\r', 'bar'], { flush: false })).toEqual(['foo']);
+  });
+
+  test('double \\r then \\r\\n', () => {
+    expect(decodeChunks(['foo\r', '\r', '\r', '\n', 'bar', '\n'])).toEqual(['foo', '', '', 'bar']);
+    expect(decodeChunks(['foo\n', '\n', '\n', 'bar', '\n'])).toEqual(['foo', '', '', 'bar']);
+  });
+
+  test('double newline', () => {
+    expect(decodeChunks(['foo\n\nbar'], { flush: true })).toEqual(['foo', '', 'bar']);
+    expect(decodeChunks(['foo', '\n', '\nbar'], { flush: true })).toEqual(['foo', '', 'bar']);
+    expect(decodeChunks(['foo\n', '\n', 'bar'], { flush: true })).toEqual(['foo', '', 'bar']);
+    expect(decodeChunks(['foo', '\n', '\n', 'bar'], { flush: true })).toEqual(['foo', '', 'bar']);
+  });
+
+  test('multi-byte characters across chunks', () => {
+    const decoder = new LineDecoder();
+
+    // bytes taken from the string 'известни' and arbitrarily split
+    // so that some multi-byte characters span multiple chunks
+    expect(decoder.decode(new Uint8Array([0xd0]))).toHaveLength(0);
+    expect(decoder.decode(new Uint8Array([0xb8, 0xd0, 0xb7, 0xd0]))).toHaveLength(0);
+    expect(
+      decoder.decode(new Uint8Array([0xb2, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0xd0, 0xbd, 0xd0, 0xb8])),
+    ).toHaveLength(0);
+
+    const decoded = decoder.decode(new Uint8Array([0xa]));
+    expect(decoded).toEqual(['известни']);
+  });
+
+  test('flushing trailing newlines', () => {
+    expect(decodeChunks(['foo\n', '\nbar'], { flush: true })).toEqual(['foo', '', 'bar']);
+  });
+
+  test('flushing empty buffer', () => {
+    expect(decodeChunks([], { flush: true })).toEqual([]);
+  });
+});
+
+describe('findDoubleNewlineIndex', () => {
+  test('finds \\n\\n', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\n\nbar'))).toBe(5);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\n\nbar'))).toBe(2);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\n\n'))).toBe(5);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\n\n'))).toBe(2);
+  });
+
+  test('finds \\r\\r', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\rbar'))).toBe(5);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\r\rbar'))).toBe(2);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\r'))).toBe(5);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\r\r'))).toBe(2);
+  });
+
+  test('finds \\r\\n\\r\\n', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\n\r\nbar'))).toBe(7);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\r\n\r\nbar'))).toBe(4);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\n\r\n'))).toBe(7);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\r\n\r\n'))).toBe(4);
+  });
+
+  test('returns -1 when no double newline found', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\nbar'))).toBe(-1);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\rbar'))).toBe(-1);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\nbar'))).toBe(-1);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode(''))).toBe(-1);
+  });
+
+  test('handles incomplete patterns', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\n\r'))).toBe(-1);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\n'))).toBe(-1);
+  });
+});
diff --git tests/streaming.test.ts tests/streaming.test.ts
index 6fe9a5781..b9a38f208 100644
--- tests/streaming.test.ts
+++ tests/streaming.test.ts
@@ -1,35 +1,7 @@
import { Response } from 'node-fetch';
import { PassThrough } from 'stream';
import assert from 'assert';
-import { _iterSSEMessages, _decodeChunks as decodeChunks } from 'openai/streaming';
-
-describe('line decoder', () => {
-  test('basic', () => {
-    // baz is not included because the line hasn't ended yet
-    expect(decodeChunks(['foo', ' bar\nbaz'])).toEqual(['foo bar']);
-  });
-
-  test('basic with \\r', () => {
-    // baz is not included because the line hasn't ended yet
-    expect(decodeChunks(['foo', ' bar\r\nbaz'])).toEqual(['foo bar']);
-  });
-
-  test('trailing new lines', () => {
-    expect(decodeChunks(['foo', ' bar', 'baz\n', 'thing\n'])).toEqual(['foo barbaz', 'thing']);
-  });
-
-  test('trailing new lines with \\r', () => {
-    expect(decodeChunks(['foo', ' bar', 'baz\r\n', 'thing\r\n'])).toEqual(['foo barbaz', 'thing']);
-  });
-
-  test('escaped new lines', () => {
-    expect(decodeChunks(['foo', ' bar\\nbaz\n'])).toEqual(['foo bar\\nbaz']);
-  });
-
-  test('escaped new lines with \\r', () => {
-    expect(decodeChunks(['foo', ' bar\\r\\nbaz\n'])).toEqual(['foo bar\\r\\nbaz']);
-  });
-});
+import { _iterSSEMessages } from 'openai/streaming';

describe('streaming decoding', () => {
  test('basic', async () => {


Description

This PR adds significant improvements to the OpenAI Node.js SDK, including new chat completion storage functionality, fixes for streaming and line decoding, and improved code organization. The changes also improve documentation and error handling.

Changes

Changes

By filename:

.github/workflows/ci.yml:

  • Added new ecosystem_tests workflow for testing across different Node.js environments (Deno, Bun)

src/internal/decoders/line.ts:

  • Improved line decoding logic, particularly for multi-byte character handling
  • Added new findNewlineIndex and findDoubleNewlineIndex helpers
  • Optimized buffer handling using Uint8Array

src/resources/chat/completions/:

  • Split completions code into multiple files for better organization
  • Added new endpoints for chat completion storage:
    • retrieve(): Get stored chat completions
    • update(): Modify stored completions
    • list(): List stored completions
    • del(): Delete stored completions
    • messages.list(): List messages in a stored completion

Documentation files:

  • Split README.md into multiple specialized docs (realtime.md, azure.md, helpers.md)
  • Improved documentation organization and clarity

Error handling:

  • AssistantStream now handles thread.run.incomplete event
  • Improved error handling in realtime API clients
sequenceDiagram
    participant Client
    participant API as OpenAI API
    participant Storage as Chat Storage

    Client->>API: Create chat completion
    API-->>Client: Return completion
    opt Store completion
        API->>Storage: Store completion & messages
    end
    
    alt Retrieve stored completion
        Client->>Storage: GET /chat/completions/{id}
        Storage-->>Client: Return stored completion
    else List stored messages
        Client->>Storage: GET /chat/completions/{id}/messages 
        Storage-->>Client: Return message list
    else Update stored completion
        Client->>Storage: POST /chat/completions/{id}
        Storage-->>Client: Return updated completion
    else Delete stored completion
        Client->>Storage: DELETE /chat/completions/{id}
        Storage-->>Client: Return deletion confirmation
    end
Loading

Security Hotspots

  • The change to store chat completions could potentially expose sensitive conversation data if proper access controls are not in place. However, this appears to be handled by requiring an API key.

Copy link

openai debug - [puLL-Merge] - openai/[email protected]

Diff
diff --git .github/workflows/ci.yml .github/workflows/ci.yml
index d6798e38a..85d792c44 100644
--- .github/workflows/ci.yml
+++ .github/workflows/ci.yml
@@ -64,3 +64,36 @@ jobs:
 
       - name: Run tests
         run: ./scripts/test
+
+  ecosystem_tests:
+    name: ecosystem tests (v${{ matrix.node-version }})
+    runs-on: ubuntu-latest
+    if: github.repository == 'openai/openai-node'
+    timeout-minutes: 20
+    strategy:
+      fail-fast: false
+      matrix:
+        node-version: ['20']
+
+    steps:
+      - uses: actions/checkout@v4
+
+      - name: Set up Node
+        uses: actions/setup-node@v4
+        with:
+          node-version: '${{ matrix.node-version }}'
+
+      - uses: denoland/setup-deno@v1
+        with:
+          deno-version: v1.39.0
+
+      - uses: oven-sh/setup-bun@v2
+
+      - name: Bootstrap
+        run: ./scripts/bootstrap
+
+      - name: Run ecosystem tests
+        run: |
+          yarn tsn ecosystem-tests/cli.ts --live --verbose --parallel --jobs=4 --retry=3
+        env:
+          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
diff --git .gitignore .gitignore
index 81c4c41ca..3fdab1cb7 100644
--- .gitignore
+++ .gitignore
@@ -11,4 +11,4 @@ tmp
 .pack
 ecosystem-tests/deno/package.json
 ecosystem-tests/*/openai.tgz
-
+.dev.vars
diff --git .release-please-manifest.json .release-please-manifest.json
index 6eb0f130e..541794534 100644
--- .release-please-manifest.json
+++ .release-please-manifest.json
@@ -1,3 +1,3 @@
 {
-  ".": "4.83.0"
+  ".": "4.85.2"
 }
diff --git .stats.yml .stats.yml
index df7877dfd..658877d3b 100644
--- .stats.yml
+++ .stats.yml
@@ -1,2 +1,2 @@
-configured_endpoints: 69
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-fc5dbc19505b0035f9e7f88868619f4fb519b048bde011f6154f3132d4be71fb.yml
+configured_endpoints: 74
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-4aa6ee65ba9efc789e05e6a5ef0883b2cadf06def8efd863dbf75e9e233067e1.yml
diff --git CHANGELOG.md CHANGELOG.md
index f61def5e4..70a447b0a 100644
--- CHANGELOG.md
+++ CHANGELOG.md
@@ -1,5 +1,73 @@
 # Changelog
 
+## 4.85.2 (2025-02-18)
+
+Full Changelog: [v4.85.1...v4.85.2](https://github.com/openai/openai-node/compare/v4.85.1...v4.85.2)
+
+### Bug Fixes
+
+* optimize sse chunk reading off-by-one error ([#1339](https://github.com/openai/openai-node/issues/1339)) ([c82795b](https://github.com/openai/openai-node/commit/c82795b189c73d1c0e3bc3a40d0d4a2558b0483a))
+
+## 4.85.1 (2025-02-14)
+
+Full Changelog: [v4.85.0...v4.85.1](https://github.com/openai/openai-node/compare/v4.85.0...v4.85.1)
+
+### Bug Fixes
+
+* **client:** fix export map for index exports ([#1328](https://github.com/openai/openai-node/issues/1328)) ([647ba7a](https://github.com/openai/openai-node/commit/647ba7a52311928f604c72b2cc95698c0837887f))
+* **package:** add chat/completions.ts back in ([#1333](https://github.com/openai/openai-node/issues/1333)) ([e4b5546](https://github.com/openai/openai-node/commit/e4b554632ab1646da831f29413fefb3378c49cc1))
+
+
+### Chores
+
+* **internal:** add missing return type annotation ([#1334](https://github.com/openai/openai-node/issues/1334)) ([53e0856](https://github.com/openai/openai-node/commit/53e0856ec4d36deee4d71b5aaf436df0a59b9402))
+
+## 4.85.0 (2025-02-13)
+
+Full Changelog: [v4.84.1...v4.85.0](https://github.com/openai/openai-node/compare/v4.84.1...v4.85.0)
+
+### Features
+
+* **api:** add support for storing chat completions ([#1327](https://github.com/openai/openai-node/issues/1327)) ([8d77f8e](https://github.com/openai/openai-node/commit/8d77f8e3c4801b7fa1e7c6f50b48c1de1f43f3e6))
+
+
+### Bug Fixes
+
+* **realtime:** call .toString() on WebSocket url ([#1324](https://github.com/openai/openai-node/issues/1324)) ([09bc50d](https://github.com/openai/openai-node/commit/09bc50d439679b6acfd2441e69ee5aa18c00e5d9))
+
+## 4.84.1 (2025-02-13)
+
+Full Changelog: [v4.84.0...v4.84.1](https://github.com/openai/openai-node/compare/v4.84.0...v4.84.1)
+
+### Bug Fixes
+
+* **realtime:** correct websocket type var constraint ([#1321](https://github.com/openai/openai-node/issues/1321)) ([afb17ea](https://github.com/openai/openai-node/commit/afb17ea6497b860ebbe5d8e68e4a97681dd307ff))
+
+## 4.84.0 (2025-02-12)
+
+Full Changelog: [v4.83.0...v4.84.0](https://github.com/openai/openai-node/compare/v4.83.0...v4.84.0)
+
+### Features
+
+* **pagination:** avoid fetching when has_more: false ([#1305](https://github.com/openai/openai-node/issues/1305)) ([b6944c6](https://github.com/openai/openai-node/commit/b6944c634b53c9084f2ccf777c2491e89b2cc7af))
+
+
+### Bug Fixes
+
+* **api:** add missing reasoning effort + model enums ([#1302](https://github.com/openai/openai-node/issues/1302)) ([14c55c3](https://github.com/openai/openai-node/commit/14c55c312e31f1ed46d02f39a99049f785504a53))
+* **assistants:** handle `thread.run.incomplete` event ([7032cc4](https://github.com/openai/openai-node/commit/7032cc40b8aa0a58459cf114bceb8028a8517400))
+* correctly decode multi-byte characters over multiple chunks ([#1316](https://github.com/openai/openai-node/issues/1316)) ([dd776c4](https://github.com/openai/openai-node/commit/dd776c4867401f527f699bd4b9e567890256e849))
+
+
+### Chores
+
+* **internal:** remove segfault-handler dependency ([3521ca3](https://github.com/openai/openai-node/commit/3521ca34e7f5bd51542084e27c084a5d7cc5448b))
+
+
+### Documentation
+
+* **readme:** cleanup into multiple files ([da94424](https://github.com/openai/openai-node/commit/da944242e542e9e5e51cb11853c621fc6825ac02))
+
 ## 4.83.0 (2025-02-05)
 
 Full Changelog: [v4.82.0...v4.83.0](https://github.com/openai/openai-node/compare/v4.82.0...v4.83.0)
diff --git README.md README.md
index a1f4bf760..166e35e22 100644
--- README.md
+++ README.md
@@ -40,7 +40,7 @@ import OpenAI from 'jsr:@openai/openai';
 The full API of this library can be found in [api.md file](api.md) along with many [code examples](https://github.com/openai/openai-node/tree/master/examples). The code below shows how to get started using the chat completions API.
 
 <!-- prettier-ignore -->
-\`\`\`js
+```ts
 import OpenAI from 'openai';
 
 const client = new OpenAI({
@@ -80,189 +80,11 @@ async function main() {
 main();

-If you need to cancel a stream, you can break from the loop
-or call stream.controller.abort().

-## Realtime API beta

-The Realtime API enables you to build low-latency, multi-modal conversational experiences. It currently supports text and audio as both input and output, as well as function calling through a WebSocket connection.

-The Realtime API works through a combination of client-sent events and server-sent events. Clients can send events to do things like update session configuration or send text and audio inputs. Server events confirm when audio responses have completed, or when a text response from the model has been received. A full event reference can be found here and a guide can be found here.

-This SDK supports accessing the Realtime API through the WebSocket API or with ws.

-Basic text based example with ws:

-```ts
-// requires yarn add ws @types/ws
-import { OpenAIRealtimeWS } from 'openai/beta/realtime/ws';

-const rt = new OpenAIRealtimeWS({ model: 'gpt-4o-realtime-preview-2024-12-17' });

-// access the underlying ws.WebSocket instance
-rt.socket.on('open', () => {

  • console.log('Connection opened!');
  • rt.send({
  • type: 'session.update',
  • session: {
  •  modalities: ['text'],
    
  •  model: 'gpt-4o-realtime-preview',
    
  • },
  • });
  • rt.send({
  • type: 'conversation.item.create',
  • item: {
  •  type: 'message',
    
  •  role: 'user',
    
  •  content: [{ type: 'input_text', text: 'Say a couple paragraphs!' }],
    
  • },
  • });
  • rt.send({ type: 'response.create' });
    -});

-rt.on('error', (err) => {

  • // in a real world scenario this should be logged somewhere as you
  • // likely want to continue procesing events regardless of any errors
  • throw err;
    -});

-rt.on('session.created', (event) => {

  • console.log('session created!', event.session);
  • console.log();
    -});

-rt.on('response.text.delta', (event) => process.stdout.write(event.delta));
-rt.on('response.text.done', () => console.log());

-rt.on('response.done', () => rt.close());

-rt.socket.on('close', () => console.log('\nConnection closed!'));
-```

-To use the web API WebSocket implementation, replace OpenAIRealtimeWS with OpenAIRealtimeWebSocket and adjust any rt.socket access:

-```ts
-import { OpenAIRealtimeWebSocket } from 'openai/beta/realtime/websocket';

-const rt = new OpenAIRealtimeWebSocket({ model: 'gpt-4o-realtime-preview-2024-12-17' });
-// ...
-rt.socket.addEventListener('open', () => {

  • // ...
    -});
    -```

-A full example can be found here.

-### Realtime error handling

-When an error is encountered, either on the client side or returned from the server through the error event, the error event listener will be fired. However, if you haven't registered an error event listener then an unhandled Promise rejection error will be thrown.

-It is highly recommended that you register an error event listener and handle errors approriately as typically the underlying connection is still usable.

-```ts
-const rt = new OpenAIRealtimeWS({ model: 'gpt-4o-realtime-preview-2024-12-17' });
-rt.on('error', (err) => {

  • // in a real world scenario this should be logged somewhere as you
  • // likely want to continue procesing events regardless of any errors
  • throw err;
    -});
    -```

-### Request & Response types

-This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:

-
-```ts
-import OpenAI from 'openai';

-const client = new OpenAI({

  • apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
    -});

-async function main() {

  • const params: OpenAI.Chat.ChatCompletionCreateParams = {
  • messages: [{ role: 'user', content: 'Say this is a test' }],
  • model: 'gpt-4o',
  • };
  • const chatCompletion: OpenAI.Chat.ChatCompletion = await client.chat.completions.create(params);
    -}

-main();
-```

-Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.

-> [!IMPORTANT]
-> Previous versions of this SDK used a Configuration class. See the v3 to v4 migration guide.

-### Polling Helpers

-When interacting with the API some actions such as starting a Run and adding files to vector stores are asynchronous and take time to complete. The SDK includes
-helper functions which will poll the status until it reaches a terminal state and then return the resulting object.
-If an API method results in an action which could benefit from polling there will be a corresponding version of the
-method ending in 'AndPoll'.

-For instance to create a Run and poll until it reaches a terminal state you can run:

-```ts
-const run = await openai.beta.threads.runs.createAndPoll(thread.id, {

  • assistant_id: assistantId,
    -});
    -```

-More information on the lifecycle of a Run can be found in the Run Lifecycle Documentation

-### Bulk Upload Helpers

-When creating and interacting with vector stores, you can use the polling helpers to monitor the status of operations.
-For convenience, we also provide a bulk upload helper to allow you to simultaneously upload several files at once.

-```ts
-const fileList = [

  • createReadStream('/home/data/example.pdf'),
  • ...
    -];

-const batch = await openai.vectorStores.fileBatches.uploadAndPoll(vectorStore.id, {files: fileList});
-```

-### Streaming Helpers

-The SDK also includes helpers to process streams and handle the incoming events.

-```ts
-const run = openai.beta.threads.runs

  • .stream(thread.id, {
  • assistant_id: assistant.id,
  • })
  • .on('textCreated', (text) => process.stdout.write('\nassistant > '))
  • .on('textDelta', (textDelta, snapshot) => process.stdout.write(textDelta.value))
  • .on('toolCallCreated', (toolCall) => process.stdout.write(\nassistant > ${toolCall.type}\n\n))
  • .on('toolCallDelta', (toolCallDelta, snapshot) => {
  • if (toolCallDelta.type === 'code_interpreter') {
  •  if (toolCallDelta.code_interpreter.input) {
    
  •    process.stdout.write(toolCallDelta.code_interpreter.input);
    
  •  }
    
  •  if (toolCallDelta.code_interpreter.outputs) {
    
  •    process.stdout.write('\noutput >\n');
    
  •    toolCallDelta.code_interpreter.outputs.forEach((output) => {
    
  •      if (output.type === 'logs') {
    
  •        process.stdout.write(`\n${output.logs}\n`);
    
  •      }
    
  •    });
    
  •  }
    
  • }
  • });
    -```

-More information on streaming helpers can be found in the dedicated documentation: helpers.md
+If you need to cancel a stream, you can break from the loop or call stream.controller.abort().

-### Streaming responses
+### Chat Completion streaming helpers

-This library provides several conveniences for streaming chat completions, for example:
+This library also provides several conveniences for streaming chat completions, for example:

import OpenAI from 'openai';
@@ -292,98 +114,32 @@ async function main() {
main();

-Streaming with openai.beta.chat.completions.stream({…}) exposes
-various helpers for your convenience including event handlers and promises.

-Alternatively, you can use openai.chat.completions.create({ stream: true, … })
-which only returns an async iterable of the chunks in the stream and thus uses less memory
-(it does not build up a final chat completion object for you).

-If you need to cancel a stream, you can break from a for await loop or call stream.abort().

-### Automated function calls
+See helpers.md for more details.

-We provide the openai.beta.chat.completions.runTools({…})
-convenience helper for using function tool calls with the /chat/completions endpoint
-which automatically call the JavaScript functions you provide
-and sends their results back to the /chat/completions endpoint,
-looping as long as the model requests tool calls.

-If you pass a parse function, it will automatically parse the arguments for you
-and returns any parsing errors to the model to attempt auto-recovery.
-Otherwise, the args will be passed to the function you provide as a string.
+### Request & Response types

-If you pass tool_choice: {function: {name: …}} instead of auto,
-it returns immediately after calling that function (and only loops to auto-recover parsing errors).
+This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:

+

import OpenAI from 'openai';

-const client = new OpenAI();
+const client = new OpenAI({
+  apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
+});

async function main() {
-  const runner = client.beta.chat.completions
-    .runTools({
-      model: 'gpt-4o',
-      messages: [{ role: 'user', content: 'How is the weather this week?' }],
-      tools: [
-        {
-          type: 'function',
-          function: {
-            function: getCurrentLocation,
-            parameters: { type: 'object', properties: {} },
-          },
-        },
-        {
-          type: 'function',
-          function: {
-            function: getWeather,
-            parse: JSON.parse, // or use a validation library like zod for typesafe parsing.
-            parameters: {
-              type: 'object',
-              properties: {
-                location: { type: 'string' },
-              },
-            },
-          },
-        },
-      ],
-    })
-    .on('message', (message) => console.log(message));
-
-  const finalContent = await runner.finalContent();
-  console.log();
-  console.log('Final content:', finalContent);
-}
-
-async function getCurrentLocation() {
-  return 'Boston'; // Simulate lookup
-}
-
-async function getWeather(args: { location: string }) {
-  const { location } = args;
-  // … do lookup …
-  return { temperature, precipitation };
+  const params: OpenAI.Chat.ChatCompletionCreateParams = {
+    messages: [{ role: 'user', content: 'Say this is a test' }],
+    model: 'gpt-4o',
+  };
+  const chatCompletion: OpenAI.Chat.ChatCompletion = await client.chat.completions.create(params);
}

main();
-
-// {role: "user",      content: "How's the weather this week?"}
-// {role: "assistant", tool_calls: [{type: "function", function: {name: "getCurrentLocation", arguments: "{}"}, id: "123"}
-// {role: "tool",      name: "getCurrentLocation", content: "Boston", tool_call_id: "123"}
-// {role: "assistant", tool_calls: [{type: "function", function: {name: "getWeather", arguments: '{"location": "Boston"}'}, id: "1234"}]}
-// {role: "tool",      name: "getWeather", content: '{"temperature": "50degF", "preciptation": "high"}', tool_call_id: "1234"}
-// {role: "assistant", content: "It's looking cold and rainy - you might want to wear a jacket!"}
-//
-// Final content: "It's looking cold and rainy - you might want to wear a jacket!"

-Like with .stream(), we provide a variety of helpers and events.

-Note that runFunctions was previously available as well, but has been deprecated in favor of runTools.

-Read more about various examples such as with integrating with zod,
-next.js, and proxying a stream to the browser.
+Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.

File uploads

@@ -434,6 +190,7 @@ async function main() {
.create({ model: 'gpt-4o', training_file: 'file-abc123' })
.catch(async (err) => {
if (err instanceof OpenAI.APIError) {

  •    console.log(err.request_id);
       console.log(err.status); // 400
       console.log(err.name); // BadRequestError
       console.log(err.headers); // {server: 'nginx', ...}
    

@@ -459,76 +216,6 @@ Error codes are as followed:
| >=500 | InternalServerError |
| N/A | APIConnectionError |

-## Request IDs

-> For more information on debugging requests, see these docs

-All object responses in the SDK provide a _request_id property which is added from the x-request-id response header so that you can quickly log failing requests and report them back to OpenAI.

-ts -const completion = await client.chat.completions.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-4o' }); -console.log(completion._request_id) // req_123 -

-You can also access the Request ID using the .withResponse() method:

-```ts
-const { data: stream, request_id } = await openai.chat.completions

  • .create({
  • model: 'gpt-4',
  • messages: [{ role: 'user', content: 'Say this is a test' }],
  • stream: true,
  • })
  • .withResponse();
    -```

-## Microsoft Azure OpenAI

-To use this library with Azure OpenAI, use the AzureOpenAI
-class instead of the OpenAI class.

-> [!IMPORTANT]
-> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params
-> won't always be correct.

-```ts
-import { AzureOpenAI } from 'openai';
-import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';

-const credential = new DefaultAzureCredential();
-const scope = 'https://cognitiveservices.azure.com/.default';
-const azureADTokenProvider = getBearerTokenProvider(credential, scope);

-const openai = new AzureOpenAI({ azureADTokenProvider, apiVersion: "<The API version, e.g. 2024-10-01-preview>" });

-const result = await openai.chat.completions.create({

  • model: 'gpt-4o',
  • messages: [{ role: 'user', content: 'Say hello!' }],
    -});

-console.log(result.choices[0]!.message?.content);
-```

-### Realtime API
-This SDK provides real-time streaming capabilities for Azure OpenAI through the OpenAIRealtimeWS and OpenAIRealtimeWebSocket clients described previously.

-To utilize the real-time features, begin by creating a fully configured AzureOpenAI client and passing it into either OpenAIRealtimeWS.azure or OpenAIRealtimeWebSocket.azure. For example:

-```ts
-const cred = new DefaultAzureCredential();
-const scope = 'https://cognitiveservices.azure.com/.default';
-const deploymentName = 'gpt-4o-realtime-preview-1001';
-const azureADTokenProvider = getBearerTokenProvider(cred, scope);
-const client = new AzureOpenAI({

  • azureADTokenProvider,
  • apiVersion: '2024-10-01-preview',
  • deployment: deploymentName,
    -});
    -const rt = await OpenAIRealtimeWS.azure(client);
    -```

-Once the instance has been created, you can then begin sending requests and receiving streaming responses in real time.

Retries

Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
@@ -571,6 +258,29 @@ On timeout, an APIConnectionTimeoutError is thrown.

Note that requests which time out will be retried twice by default.

+## Request IDs
+
+> For more information on debugging requests, see these docs
+
+All object responses in the SDK provide a _request_id property which is added from the x-request-id response header so that you can quickly log failing requests and report them back to OpenAI.
+
+ts +const completion = await client.chat.completions.create({ messages: [{ role: 'user', content: 'Say this is a test' }], model: 'gpt-4o' }); +console.log(completion._request_id) // req_123 +
+
+You can also access the Request ID using the .withResponse() method:
+
+```ts
+const { data: stream, request_id } = await openai.chat.completions

  • .create({
  • model: 'gpt-4',
  • messages: [{ role: 'user', content: 'Say this is a test' }],
  • stream: true,
  • })
  • .withResponse();
    +```

Auto-pagination

List methods in the OpenAI API are paginated.
@@ -602,6 +312,55 @@ while (page.hasNextPage()) {
}


+## Realtime API Beta
+
+The Realtime API enables you to build low-latency, multi-modal conversational experiences. It currently supports text and audio as both input and output, as well as [function calling](https://platform.openai.com/docs/guides/function-calling) through a `WebSocket` connection.
+
+```ts
+import { OpenAIRealtimeWebSocket } from 'openai/beta/realtime/websocket';
+
+const rt = new OpenAIRealtimeWebSocket({ model: 'gpt-4o-realtime-preview-2024-12-17' });
+
+rt.on('response.text.delta', (event) => process.stdout.write(event.delta));
+```
+
+For more information see [realtime.md](realtime.md).
+
+## Microsoft Azure OpenAI
+
+To use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the `AzureOpenAI`
+class instead of the `OpenAI` class.
+
+> [!IMPORTANT]
+> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params
+> won't always be correct.
+
+```ts
+import { AzureOpenAI } from 'openai';
+import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';
+
+const credential = new DefaultAzureCredential();
+const scope = 'https://cognitiveservices.azure.com/.default';
+const azureADTokenProvider = getBearerTokenProvider(credential, scope);
+
+const openai = new AzureOpenAI({ azureADTokenProvider, apiVersion: "<The API version, e.g. 2024-10-01-preview>" });
+
+const result = await openai.chat.completions.create({
+  model: 'gpt-4o',
+  messages: [{ role: 'user', content: 'Say hello!' }],
+});
+
+console.log(result.choices[0]!.message?.content);
+```
+
+For more information on support for the Azure API, see [azure.md](azure.md).
+
+## Automated function calls
+
+We provide the `openai.beta.chat.completions.runTools({…})` convenience helper for using function tool calls with the `/chat/completions` endpoint which automatically call the JavaScript functions you provide and sends their results back to the `/chat/completions` endpoint, looping as long as the model requests tool calls.
+
+For more information see [helpers.md](helpers.md#automated-function-calls).
+
## Advanced Usage

### Accessing raw Response data (e.g., headers)
diff --git api.md api.md
index 01854a8e0..63f239628 100644
--- api.md
+++ api.md
@@ -32,39 +32,51 @@ Types:

Types:

-- <code><a href="./src/resources/chat/completions.ts">ChatCompletion</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionAssistantMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionAudio</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionAudioParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionChunk</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPart</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPartImage</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPartInputAudio</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPartRefusal</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionContentPartText</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionDeveloperMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionFunctionCallOption</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionFunctionMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionMessage</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionMessageToolCall</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionModality</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionNamedToolChoice</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionPredictionContent</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionReasoningEffort</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionRole</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionStreamOptions</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionSystemMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionTokenLogprob</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionTool</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionToolChoiceOption</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionToolMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">ChatCompletionUserMessageParam</a></code>
-- <code><a href="./src/resources/chat/completions.ts">CreateChatCompletionRequestMessage</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletion</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionAssistantMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionAudio</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionAudioParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionChunk</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPart</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPartImage</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPartInputAudio</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPartRefusal</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionContentPartText</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionDeleted</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionDeveloperMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionFunctionCallOption</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionFunctionMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionMessage</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionMessageToolCall</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionModality</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionNamedToolChoice</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionPredictionContent</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionReasoningEffort</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionRole</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionStoreMessage</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionStreamOptions</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionSystemMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionTokenLogprob</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionTool</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionToolChoiceOption</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionToolMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">ChatCompletionUserMessageParam</a></code>
+- <code><a href="./src/resources/chat/completions/completions.ts">CreateChatCompletionRequestMessage</a></code>

Methods:

-- <code title="post /chat/completions">client.chat.completions.<a href="./src/resources/chat/completions.ts">create</a>({ ...params }) -> ChatCompletion</code>
+- <code title="post /chat/completions">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">create</a>({ ...params }) -> ChatCompletion</code>
+- <code title="get /chat/completions/{completion_id}">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">retrieve</a>(completionId) -> ChatCompletion</code>
+- <code title="post /chat/completions/{completion_id}">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">update</a>(completionId, { ...params }) -> ChatCompletion</code>
+- <code title="get /chat/completions">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">list</a>({ ...params }) -> ChatCompletionsPage</code>
+- <code title="delete /chat/completions/{completion_id}">client.chat.completions.<a href="./src/resources/chat/completions/completions.ts">del</a>(completionId) -> ChatCompletionDeleted</code>
+
+### Messages
+
+Methods:
+
+- <code title="get /chat/completions/{completion_id}/messages">client.chat.completions.messages.<a href="./src/resources/chat/completions/messages.ts">list</a>(completionId, { ...params }) -> ChatCompletionStoreMessagesPage</code>

# Embeddings

diff --git a/azure.md b/azure.md
new file mode 100644
index 000000000..df06c2985
--- /dev/null
+++ azure.md
@@ -0,0 +1,49 @@
+# Microsoft Azure OpenAI
+
+To use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the `AzureOpenAI`
+class instead of the `OpenAI` class.
+
+> [!IMPORTANT]
+> The Azure API shape slightly differs from the core API shape which means that the static types for responses / params
+> won't always be correct.
+
+```ts
+import { AzureOpenAI } from 'openai';
+import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';
+
+const credential = new DefaultAzureCredential();
+const scope = 'https://cognitiveservices.azure.com/.default';
+const azureADTokenProvider = getBearerTokenProvider(credential, scope);
+
+const openai = new AzureOpenAI({ azureADTokenProvider, apiVersion: "<The API version, e.g. 2024-10-01-preview>" });
+
+const result = await openai.chat.completions.create({
+  model: 'gpt-4o',
+  messages: [{ role: 'user', content: 'Say hello!' }],
+});
+
+console.log(result.choices[0]!.message?.content);
+```
+
+For more information on support for the Azure API, see [azure.md](azure.md).
+
+## Realtime API
+
+This SDK provides real-time streaming capabilities for Azure OpenAI through the `OpenAIRealtimeWS` and `OpenAIRealtimeWebSocket` clients described previously.
+
+To utilize the real-time features, begin by creating a fully configured `AzureOpenAI` client and passing it into either `OpenAIRealtimeWS.azure` or `OpenAIRealtimeWebSocket.azure`. For example:
+
+```ts
+const cred = new DefaultAzureCredential();
+const scope = 'https://cognitiveservices.azure.com/.default';
+const deploymentName = 'gpt-4o-realtime-preview-1001';
+const azureADTokenProvider = getBearerTokenProvider(cred, scope);
+const client = new AzureOpenAI({
+  azureADTokenProvider,
+  apiVersion: '2024-10-01-preview',
+  deployment: deploymentName,
+});
+const rt = await OpenAIRealtimeWS.azure(client);
+```
+
+Once the instance has been created, you can then begin sending requests and receiving streaming responses in real time.
diff --git ecosystem-tests/cli.ts ecosystem-tests/cli.ts
index 00120e5f9..77faddec5 100644
--- ecosystem-tests/cli.ts
+++ ecosystem-tests/cli.ts
@@ -4,10 +4,6 @@ import yargs from 'yargs';
import assert from 'assert';
import path from 'path';

-// @ts-ignore
-var SegfaultHandler = require('segfault-handler');
-SegfaultHandler.registerHandler('crash.log');
-
const TAR_NAME = 'openai.tgz';
const PACK_FOLDER = '.pack';
const PACK_FILE = `${PACK_FOLDER}/${TAR_NAME}`;
@@ -74,6 +70,7 @@ const projectRunners = {
  'cloudflare-worker': async () => {
    await installPackage();

+    await fs.writeFile('.dev.vars', `OPENAI_API_KEY='${process.env['OPENAI_API_KEY']}'`);
    await run('npm', ['run', 'tsc']);

    if (state.live) {
diff --git helpers.md helpers.md
index 16bc1f277..41b352e5e 100644
--- helpers.md
+++ helpers.md
@@ -142,9 +142,7 @@ More information can be found in the documentation: [Assistant Streaming](https:

```ts
const run = openai.beta.threads.runs
-  .stream(thread.id, {
-    assistant_id: assistant.id,
-  })
+  .stream(thread.id, { assistant_id: assistant.id })
  .on('textCreated', (text) => process.stdout.write('\nassistant > '))
  .on('textDelta', (textDelta, snapshot) => process.stdout.write(textDelta.value))
  .on('toolCallCreated', (toolCall) => process.stdout.write(`\nassistant > ${toolCall.type}\n\n`))
@@ -304,47 +302,87 @@ If you need to cancel a stream, you can `break` from a `for await` loop or call

See an example of streaming helpers in action in [`examples/stream.ts`](examples/stream.ts).

-### Automated Function Calls
+### Automated function calls

-```ts
-openai.chat.completions.runTools({ stream: false, … }, options?): ChatCompletionRunner
-openai.chat.completions.runTools({ stream: true, … }, options?): ChatCompletionStreamingRunner
-```
+We provide the `openai.beta.chat.completions.runTools({…})`
+convenience helper for using function tool calls with the `/chat/completions` endpoint
+which automatically call the JavaScript functions you provide
+and sends their results back to the `/chat/completions` endpoint,
+looping as long as the model requests tool calls.

-`openai.chat.completions.runTools()` returns a Runner
-for automating function calls with chat completions.
-The runner automatically calls the JavaScript functions you provide and sends their results back
-to the API, looping as long as the model requests function calls.
+If you pass a `parse` function, it will automatically parse the `arguments` for you
+and returns any parsing errors to the model to attempt auto-recovery.
+Otherwise, the args will be passed to the function you provide as a string.

-If you pass a `parse` function, it will automatically parse the `arguments` for you and returns any parsing
-errors to the model to attempt auto-recovery. Otherwise, the args will be passed to the function you provide
-as a string.
+If you pass `tool_choice: {function: {name: …}}` instead of `auto`,
+it returns immediately after calling that function (and only loops to auto-recover parsing errors).

```ts
-client.chat.completions.runTools({
-  model: 'gpt-3.5-turbo',
-  messages: [{ role: 'user', content: 'How is the weather this week?' }],
-  tools: [
-    {
-      type: 'function',
-      function: {
-        function: getWeather as (args: { location: string; time: Date }) => any,
-        parse: parseFunction as (args: strings) => { location: string; time: Date },
-        parameters: {
-          type: 'object',
-          properties: {
-            location: { type: 'string' },
-            time: { type: 'string', format: 'date-time' },
+import OpenAI from 'openai';
+
+const client = new OpenAI();
+
+async function main() {
+  const runner = client.beta.chat.completions
+    .runTools({
+      model: 'gpt-4o',
+      messages: [{ role: 'user', content: 'How is the weather this week?' }],
+      tools: [
+        {
+          type: 'function',
+          function: {
+            function: getCurrentLocation,
+            parameters: { type: 'object', properties: {} },
          },
        },
-      },
-    },
-  ],
-});
+        {
+          type: 'function',
+          function: {
+            function: getWeather,
+            parse: JSON.parse, // or use a validation library like zod for typesafe parsing.
+            parameters: {
+              type: 'object',
+              properties: {
+                location: { type: 'string' },
+              },
+            },
+          },
+        },
+      ],
+    })
+    .on('message', (message) => console.log(message));
+
+  const finalContent = await runner.finalContent();
+  console.log();
+  console.log('Final content:', finalContent);
+}
+
+async function getCurrentLocation() {
+  return 'Boston'; // Simulate lookup
+}
+
+async function getWeather(args: { location: string }) {
+  const { location } = args;
+  // … do lookup …
+  return { temperature, precipitation };
+}
+
+main();
+
+// {role: "user",      content: "How's the weather this week?"}
+// {role: "assistant", tool_calls: [{type: "function", function: {name: "getCurrentLocation", arguments: "{}"}, id: "123"}
+// {role: "tool",      name: "getCurrentLocation", content: "Boston", tool_call_id: "123"}
+// {role: "assistant", tool_calls: [{type: "function", function: {name: "getWeather", arguments: '{"location": "Boston"}'}, id: "1234"}]}
+// {role: "tool",      name: "getWeather", content: '{"temperature": "50degF", "preciptation": "high"}', tool_call_id: "1234"}
+// {role: "assistant", content: "It's looking cold and rainy - you might want to wear a jacket!"}
+//
+// Final content: "It's looking cold and rainy - you might want to wear a jacket!"

-If you pass function_call: {name: …} instead of auto, it returns immediately after calling that
-function (and only loops to auto-recover parsing errors).
+Like with .stream(), we provide a variety of helpers and events.
+
+Read more about various examples such as with integrating with zod,
+next.js, and proxying a stream to the browser.

By default, we run the loop up to 10 chat completions from the API. You can change this behavior by
adjusting maxChatCompletions in the request options object. Note that max_tokens is the limit per
@@ -662,3 +700,17 @@ client.beta.vectorStores.files.createAndPoll((...)
client.beta.vectorStores.fileBatches.createAndPoll((...)
client.beta.vectorStores.fileBatches.uploadAndPoll((...)

+
+# Bulk Upload Helpers
+
+When creating and interacting with vector stores, you can use the polling helpers to monitor the status of operations.
+For convenience, we also provide a bulk upload helper to allow you to simultaneously upload several files at once.
+
+```ts
+const fileList = [
+  createReadStream('/home/data/example.pdf'),
+  ...
+];
+
+const batch = await openai.vectorStores.fileBatches.uploadAndPoll(vectorStore.id, {files: fileList});
+```
diff --git jsr.json jsr.json
index 6fa05e624..8f83c0ff2 100644
--- jsr.json
+++ jsr.json
@@ -1,6 +1,6 @@
{
  "name": "@openai/openai",
-  "version": "4.83.0",
+  "version": "4.85.2",
  "exports": {
    ".": "./index.ts",
    "./helpers/zod": "./helpers/zod.ts",
diff --git package.json package.json
index bd507e9f8..661bc2938 100644
--- package.json
+++ package.json
@@ -1,6 +1,6 @@
{
  "name": "openai",
-  "version": "4.83.0",
+  "version": "4.85.2",
  "description": "The official TypeScript library for the OpenAI API",
  "author": "OpenAI <[email protected]>",
  "types": "dist/index.d.ts",
@@ -47,7 +47,6 @@
    "jest": "^29.4.0",
    "prettier": "^3.0.0",
    "prettier-2": "npm:prettier@^2",
-    "segfault-handler": "^1.3.0",
    "ts-jest": "^29.1.0",
    "ts-node": "^10.5.0",
    "tsc-multi": "^1.1.0",
@@ -113,17 +112,38 @@
      "default": "./dist/index.mjs"
    },
    "./*.mjs": {
-      "types": "./dist/*.d.ts",
-      "default": "./dist/*.mjs"
+      "types": [
+        "./dist/*.d.ts",
+        "./dist/*/index.d.ts"
+      ],
+      "default": [
+        "./dist/*.mjs",
+        "./dist/*/index.mjs"
+      ]
    },
    "./*.js": {
-      "types": "./dist/*.d.ts",
-      "default": "./dist/*.js"
+      "types": [
+        "./dist/*.d.ts",
+        "./dist/*/index.d.ts"
+      ],
+      "default": [
+        "./dist/*.js",
+        "./dist/*/index.js"
+      ]
    },
    "./*": {
-      "types": "./dist/*.d.ts",
-      "require": "./dist/*.js",
-      "default": "./dist/*.mjs"
+      "types": [
+        "./dist/*.d.ts",
+        "./dist/*/index.d.ts"
+      ],
+      "require": [
+        "./dist/*.js",
+        "./dist/*/index.js"
+      ],
+      "default": [
+        "./dist/*.mjs",
+        "./dist/*/index.mjs"
+      ]
    }
  },
  "bin": "./bin/cli",
diff --git a/realtime.md b/realtime.md
new file mode 100644
index 000000000..2fcd17e9e
--- /dev/null
+++ realtime.md
@@ -0,0 +1,87 @@
+## Realtime API beta
+
+The Realtime API enables you to build low-latency, multi-modal conversational experiences. It currently supports text and audio as both input and output, as well as [function calling](https://platform.openai.com/docs/guides/function-calling) through a `WebSocket` connection.
+
+The Realtime API works through a combination of client-sent events and server-sent events. Clients can send events to do things like update session configuration or send text and audio inputs. Server events confirm when audio responses have completed, or when a text response from the model has been received. A full event reference can be found [here](https://platform.openai.com/docs/api-reference/realtime-client-events) and a guide can be found [here](https://platform.openai.com/docs/guides/realtime).
+
+This SDK supports accessing the Realtime API through the [WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) or with [ws](https://github.com/websockets/ws).
+
+Basic text based example with `ws`:
+
+```ts
+// requires `yarn add ws @types/ws`
+import { OpenAIRealtimeWS } from 'openai/beta/realtime/ws';
+
+const rt = new OpenAIRealtimeWS({ model: 'gpt-4o-realtime-preview-2024-12-17' });
+
+// access the underlying `ws.WebSocket` instance
+rt.socket.on('open', () => {
+  console.log('Connection opened!');
+  rt.send({
+    type: 'session.update',
+    session: {
+      modalities: ['text'],
+      model: 'gpt-4o-realtime-preview',
+    },
+  });
+
+  rt.send({
+    type: 'conversation.item.create',
+    item: {
+      type: 'message',
+      role: 'user',
+      content: [{ type: 'input_text', text: 'Say a couple paragraphs!' }],
+    },
+  });
+
+  rt.send({ type: 'response.create' });
+});
+
+rt.on('error', (err) => {
+  // in a real world scenario this should be logged somewhere as you
+  // likely want to continue procesing events regardless of any errors
+  throw err;
+});
+
+rt.on('session.created', (event) => {
+  console.log('session created!', event.session);
+  console.log();
+});
+
+rt.on('response.text.delta', (event) => process.stdout.write(event.delta));
+rt.on('response.text.done', () => console.log());
+
+rt.on('response.done', () => rt.close());
+
+rt.socket.on('close', () => console.log('\nConnection closed!'));
+```
+
+To use the web API `WebSocket` implementation, replace `OpenAIRealtimeWS` with `OpenAIRealtimeWebSocket` and adjust any `rt.socket` access:
+
+```ts
+import { OpenAIRealtimeWebSocket } from 'openai/beta/realtime/websocket';
+
+const rt = new OpenAIRealtimeWebSocket({ model: 'gpt-4o-realtime-preview-2024-12-17' });
+// ...
+rt.socket.addEventListener('open', () => {
+ // ...
+});
+```
+
+A full example can be found [here](https://github.com/openai/openai-node/blob/master/examples/realtime/websocket.ts).
+
+### Realtime error handling
+
+When an error is encountered, either on the client side or returned from the server through the [`error` event](https://platform.openai.com/docs/guides/realtime-model-capabilities#error-handling), the `error` event listener will be fired. However, if you haven't registered an `error` event listener then an `unhandled Promise rejection` error will be thrown.
+
+It is **highly recommended** that you register an `error` event listener and handle errors approriately as typically the underlying connection is still usable.
+
+```ts
+const rt = new OpenAIRealtimeWS({ model: 'gpt-4o-realtime-preview-2024-12-17' });
+rt.on('error', (err) => {
+  // in a real world scenario this should be logged somewhere as you
+  // likely want to continue procesing events regardless of any errors
+  throw err;
+});
+```
+
diff --git src/beta/realtime/websocket.ts src/beta/realtime/websocket.ts
index 349cf5760..e8900e809 100644
--- src/beta/realtime/websocket.ts
+++ src/beta/realtime/websocket.ts
@@ -11,7 +11,7 @@ interface MessageEvent {
type _WebSocket =
  typeof globalThis extends (
    {
-      WebSocket: infer ws;
+      WebSocket: infer ws extends abstract new (...args: any) => any;
    }
  ) ?
    // @ts-ignore
@@ -53,7 +53,7 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
    props.onURL?.(this.url);

    // @ts-ignore
-    this.socket = new WebSocket(this.url, [
+    this.socket = new WebSocket(this.url.toString(), [
      'realtime',
      ...(isAzure(client) ? [] : [`openai-insecure-api-key.${client.apiKey}`]),
      'openai-beta.realtime-v1',
@@ -95,7 +95,7 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
  }

  static async azure(
-    client: AzureOpenAI,
+    client: Pick<AzureOpenAI, '_getAzureADToken' | 'apiVersion' | 'apiKey' | 'baseURL' | 'deploymentName'>,
    options: { deploymentName?: string; dangerouslyAllowBrowser?: boolean } = {},
  ): Promise<OpenAIRealtimeWebSocket> {
    const token = await client._getAzureADToken();
diff --git src/beta/realtime/ws.ts src/beta/realtime/ws.ts
index 51339089c..3f51dfc4b 100644
--- src/beta/realtime/ws.ts
+++ src/beta/realtime/ws.ts
@@ -52,7 +52,7 @@ export class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {
  }

  static async azure(
-    client: AzureOpenAI,
+    client: Pick<AzureOpenAI, '_getAzureADToken' | 'apiVersion' | 'apiKey' | 'baseURL' | 'deploymentName'>,
    options: { deploymentName?: string; options?: WS.ClientOptions | undefined } = {},
  ): Promise<OpenAIRealtimeWS> {
    const deploymentName = options.deploymentName ?? client.deploymentName;
@@ -82,7 +82,7 @@ export class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {
  }
}

-async function getAzureHeaders(client: AzureOpenAI) {
+async function getAzureHeaders(client: Pick<AzureOpenAI, '_getAzureADToken' | 'apiKey'>) {
  if (client.apiKey !== '<Missing Key>') {
    return { 'api-key': client.apiKey };
  } else {
diff --git src/index.ts src/index.ts
index f4e940af8..debefce8c 100644
--- src/index.ts
+++ src/index.ts
@@ -66,6 +66,13 @@ import {
import { Audio, AudioModel, AudioResponseFormat } from './resources/audio/audio';
import { Beta } from './resources/beta/beta';
import { Chat, ChatModel } from './resources/chat/chat';
+import { FineTuning } from './resources/fine-tuning/fine-tuning';
+import {
+  Upload,
+  UploadCompleteParams,
+  UploadCreateParams,
+  Uploads as UploadsAPIUploads,
+} from './resources/uploads/uploads';
import {
  ChatCompletion,
  ChatCompletionAssistantMessageParam,
@@ -80,9 +87,11 @@ import {
  ChatCompletionCreateParams,
  ChatCompletionCreateParamsNonStreaming,
  ChatCompletionCreateParamsStreaming,
+  ChatCompletionDeleted,
  ChatCompletionDeveloperMessageParam,
  ChatCompletionFunctionCallOption,
  ChatCompletionFunctionMessageParam,
+  ChatCompletionListParams,
  ChatCompletionMessage,
  ChatCompletionMessageParam,
  ChatCompletionMessageToolCall,
@@ -91,21 +100,17 @@ import {
  ChatCompletionPredictionContent,
  ChatCompletionReasoningEffort,
  ChatCompletionRole,
+  ChatCompletionStoreMessage,
  ChatCompletionStreamOptions,
  ChatCompletionSystemMessageParam,
  ChatCompletionTokenLogprob,
  ChatCompletionTool,
  ChatCompletionToolChoiceOption,
  ChatCompletionToolMessageParam,
+  ChatCompletionUpdateParams,
  ChatCompletionUserMessageParam,
-} from './resources/chat/completions';
-import { FineTuning } from './resources/fine-tuning/fine-tuning';
-import {
-  Upload,
-  UploadCompleteParams,
-  UploadCreateParams,
-  Uploads as UploadsAPIUploads,
-} from './resources/uploads/uploads';
+  ChatCompletionsPage,
+} from './resources/chat/completions/completions';

export interface ClientOptions {
  /**
@@ -310,6 +315,7 @@ export class OpenAI extends Core.APIClient {

OpenAI.Completions = Completions;
OpenAI.Chat = Chat;
+OpenAI.ChatCompletionsPage = ChatCompletionsPage;
OpenAI.Embeddings = Embeddings;
OpenAI.Files = Files;
OpenAI.FileObjectsPage = FileObjectsPage;
@@ -355,6 +361,7 @@ export declare namespace OpenAI {
    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,
    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,
    type ChatCompletionContentPartText as ChatCompletionContentPartText,
+    type ChatCompletionDeleted as ChatCompletionDeleted,
    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,
    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
@@ -366,6 +373,7 @@ export declare namespace OpenAI {
    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,
    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,
    type ChatCompletionRole as ChatCompletionRole,
+    type ChatCompletionStoreMessage as ChatCompletionStoreMessage,
    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,
    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
@@ -373,9 +381,12 @@ export declare namespace OpenAI {
    type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,
    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
+    ChatCompletionsPage as ChatCompletionsPage,
    type ChatCompletionCreateParams as ChatCompletionCreateParams,
    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,
    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,
+    type ChatCompletionUpdateParams as ChatCompletionUpdateParams,
+    type ChatCompletionListParams as ChatCompletionListParams,
  };

  export {
diff --git src/internal/decoders/line.ts src/internal/decoders/line.ts
index 34e41d1dc..947f240b3 100644
--- src/internal/decoders/line.ts
+++ src/internal/decoders/line.ts
@@ -13,52 +13,58 @@ export class LineDecoder {
  static NEWLINE_CHARS = new Set(['\n', '\r']);
  static NEWLINE_REGEXP = /\r\n|[\n\r]/g;

-  buffer: string[];
-  trailingCR: boolean;
+  buffer: Uint8Array;
+  #carriageReturnIndex: number | null;
  textDecoder: any; // TextDecoder found in browsers; not typed to avoid pulling in either "dom" or "node" types.

  constructor() {
-    this.buffer = [];
-    this.trailingCR = false;
+    this.buffer = new Uint8Array();
+    this.#carriageReturnIndex = null;
  }

  decode(chunk: Bytes): string[] {
-    let text = this.decodeText(chunk);
-
-    if (this.trailingCR) {
-      text = '\r' + text;
-      this.trailingCR = false;
-    }
-    if (text.endsWith('\r')) {
-      this.trailingCR = true;
-      text = text.slice(0, -1);
-    }
-
-    if (!text) {
+    if (chunk == null) {
      return [];
    }

-    const trailingNewline = LineDecoder.NEWLINE_CHARS.has(text[text.length - 1] || '');
-    let lines = text.split(LineDecoder.NEWLINE_REGEXP);
+    const binaryChunk =
+      chunk instanceof ArrayBuffer ? new Uint8Array(chunk)
+      : typeof chunk === 'string' ? new TextEncoder().encode(chunk)
+      : chunk;
+
+    let newData = new Uint8Array(this.buffer.length + binaryChunk.length);
+    newData.set(this.buffer);
+    newData.set(binaryChunk, this.buffer.length);
+    this.buffer = newData;
+
+    const lines: string[] = [];
+    let patternIndex;
+    while ((patternIndex = findNewlineIndex(this.buffer, this.#carriageReturnIndex)) != null) {
+      if (patternIndex.carriage && this.#carriageReturnIndex == null) {
+        // skip until we either get a corresponding `\n`, a new `\r` or nothing
+        this.#carriageReturnIndex = patternIndex.index;
+        continue;
+      }

-    // if there is a trailing new line then the last entry will be an empty
-    // string which we don't care about
-    if (trailingNewline) {
-      lines.pop();
-    }
+      // we got double \r or \rtext\n
+      if (
+        this.#carriageReturnIndex != null &&
+        (patternIndex.index !== this.#carriageReturnIndex + 1 || patternIndex.carriage)
+      ) {
+        lines.push(this.decodeText(this.buffer.slice(0, this.#carriageReturnIndex - 1)));
+        this.buffer = this.buffer.slice(this.#carriageReturnIndex);
+        this.#carriageReturnIndex = null;
+        continue;
+      }

-    if (lines.length === 1 && !trailingNewline) {
-      this.buffer.push(lines[0]!);
-      return [];
-    }
+      const endIndex =
+        this.#carriageReturnIndex !== null ? patternIndex.preceding - 1 : patternIndex.preceding;

-    if (this.buffer.length > 0) {
-      lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
-      this.buffer = [];
-    }
+      const line = this.decodeText(this.buffer.slice(0, endIndex));
+      lines.push(line);

-    if (!trailingNewline) {
-      this.buffer = [lines.pop() || ''];
+      this.buffer = this.buffer.slice(patternIndex.index);
+      this.#carriageReturnIndex = null;
    }

    return lines;
@@ -102,13 +108,69 @@ export class LineDecoder {
  }

  flush(): string[] {
-    if (!this.buffer.length && !this.trailingCR) {
+    if (!this.buffer.length) {
      return [];
    }
+    return this.decode('\n');
+  }
+}

-    const lines = [this.buffer.join('')];
-    this.buffer = [];
-    this.trailingCR = false;
-    return lines;
+/**
+ * This function searches the buffer for the end patterns, (\r or \n)
+ * and returns an object with the index preceding the matched newline and the
+ * index after the newline char. `null` is returned if no new line is found.
+ *
+ * ```ts
+ * findNewLineIndex('abc\ndef') -> { preceding: 2, index: 3 }
+ * ```
+ */
+function findNewlineIndex(
+  buffer: Uint8Array,
+  startIndex: number | null,
+): { preceding: number; index: number; carriage: boolean } | null {
+  const newline = 0x0a; // \n
+  const carriage = 0x0d; // \r
+
+  for (let i = startIndex ?? 0; i < buffer.length; i++) {
+    if (buffer[i] === newline) {
+      return { preceding: i, index: i + 1, carriage: false };
+    }
+
+    if (buffer[i] === carriage) {
+      return { preceding: i, index: i + 1, carriage: true };
+    }
  }
+
+  return null;
+}
+
+export function findDoubleNewlineIndex(buffer: Uint8Array): number {
+  // This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
+  // and returns the index right after the first occurrence of any pattern,
+  // or -1 if none of the patterns are found.
+  const newline = 0x0a; // \n
+  const carriage = 0x0d; // \r
+
+  for (let i = 0; i < buffer.length - 1; i++) {
+    if (buffer[i] === newline && buffer[i + 1] === newline) {
+      // \n\n
+      return i + 2;
+    }
+    if (buffer[i] === carriage && buffer[i + 1] === carriage) {
+      // \r\r
+      return i + 2;
+    }
+    if (
+      buffer[i] === carriage &&
+      buffer[i + 1] === newline &&
+      i + 3 < buffer.length &&
+      buffer[i + 2] === carriage &&
+      buffer[i + 3] === newline
+    ) {
+      // \r\n\r\n
+      return i + 4;
+    }
+  }
+
+  return -1;
}
diff --git src/lib/AssistantStream.ts src/lib/AssistantStream.ts
index caf68e7dd..9b6cc20c5 100644
--- src/lib/AssistantStream.ts
+++ src/lib/AssistantStream.ts
@@ -370,6 +370,7 @@ export class AssistantStream
      case 'thread.run.in_progress':
      case 'thread.run.requires_action':
      case 'thread.run.completed':
+      case 'thread.run.incomplete':
      case 'thread.run.failed':
      case 'thread.run.cancelling':
      case 'thread.run.cancelled':
@@ -400,6 +401,8 @@ export class AssistantStream
        throw new Error(
          'Encountered an error event in event processing - errors should be processed earlier',
        );
+      default:
+        assertNever(event);
    }
  }

@@ -772,3 +775,5 @@ export class AssistantStream
    return await this._createToolAssistantStream(runs, threadId, runId, params, options);
  }
}
+
+function assertNever(_x: never) {}
diff --git src/lib/ChatCompletionStream.ts src/lib/ChatCompletionStream.ts
index 6c846f70b..35648c27b 100644
--- src/lib/ChatCompletionStream.ts
+++ src/lib/ChatCompletionStream.ts
@@ -13,7 +13,7 @@ import {
  type ChatCompletionCreateParamsStreaming,
  type ChatCompletionCreateParamsBase,
  type ChatCompletionRole,
-} from '../resources/chat/completions';
+} from '../resources/chat/completions/completions';
import {
  AbstractChatCompletionRunner,
  type AbstractChatCompletionRunnerEvents,
diff --git src/pagination.ts src/pagination.ts
index 63644e333..7a513fc44 100644
--- src/pagination.ts
+++ src/pagination.ts
@@ -43,6 +43,8 @@ export class Page<Item> extends AbstractPage<Item> implements PageResponse<Item>

export interface CursorPageResponse<Item> {
  data: Array<Item>;
+
+  has_more: boolean;
}

export interface CursorPageParams {
@@ -57,6 +59,8 @@ export class CursorPage<Item extends { id: string }>
{
  data: Array<Item>;

+  has_more: boolean;
+
  constructor(
    client: APIClient,
    response: Response,
@@ -66,12 +70,21 @@ export class CursorPage<Item extends { id: string }>
    super(client, response, body, options);

    this.data = body.data || [];
+    this.has_more = body.has_more || false;
  }

  getPaginatedItems(): Item[] {
    return this.data ?? [];
  }

+  override hasNextPage(): boolean {
+    if (this.has_more === false) {
+      return false;
+    }
+
+    return super.hasNextPage();
+  }
+
  // @deprecated Please use `nextPageInfo()` instead
  nextPageParams(): Partial<CursorPageParams> | null {
    const info = this.nextPageInfo();
diff --git src/resources/beta/assistants.ts src/resources/beta/assistants.ts
index 69a5db520..0cc63d691 100644
--- src/resources/beta/assistants.ts
+++ src/resources/beta/assistants.ts
@@ -1133,6 +1133,16 @@ export interface AssistantCreateParams {
   */
  name?: string | null;

+  /**
+   * **o1 and o3-mini models only**
+   *
+   * Constrains effort on reasoning for
+   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+   * result in faster responses and fewer tokens used on reasoning in a response.
+   */
+  reasoning_effort?: 'low' | 'medium' | 'high' | null;
+
  /**
   * Specifies the format that the model must output. Compatible with
   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
@@ -1288,13 +1298,52 @@ export interface AssistantUpdateParams {
   * [Model overview](https://platform.openai.com/docs/models) for descriptions of
   * them.
   */
-  model?: string;
+  model?:
+    | (string & {})
+    | 'o3-mini'
+    | 'o3-mini-2025-01-31'
+    | 'o1'
+    | 'o1-2024-12-17'
+    | 'gpt-4o'
+    | 'gpt-4o-2024-11-20'
+    | 'gpt-4o-2024-08-06'
+    | 'gpt-4o-2024-05-13'
+    | 'gpt-4o-mini'
+    | 'gpt-4o-mini-2024-07-18'
+    | 'gpt-4-turbo'
+    | 'gpt-4-turbo-2024-04-09'
+    | 'gpt-4-0125-preview'
+    | 'gpt-4-turbo-preview'
+    | 'gpt-4-1106-preview'
+    | 'gpt-4-vision-preview'
+    | 'gpt-4'
+    | 'gpt-4-0314'
+    | 'gpt-4-0613'
+    | 'gpt-4-32k'
+    | 'gpt-4-32k-0314'
+    | 'gpt-4-32k-0613'
+    | 'gpt-3.5-turbo'
+    | 'gpt-3.5-turbo-16k'
+    | 'gpt-3.5-turbo-0613'
+    | 'gpt-3.5-turbo-1106'
+    | 'gpt-3.5-turbo-0125'
+    | 'gpt-3.5-turbo-16k-0613';

  /**
   * The name of the assistant. The maximum length is 256 characters.
   */
  name?: string | null;

+  /**
+   * **o1 and o3-mini models only**
+   *
+   * Constrains effort on reasoning for
+   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+   * result in faster responses and fewer tokens used on reasoning in a response.
+   */
+  reasoning_effort?: 'low' | 'medium' | 'high' | null;
+
  /**
   * Specifies the format that the model must output. Compatible with
   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
diff --git src/resources/beta/threads/runs/runs.ts src/resources/beta/threads/runs/runs.ts
index 84ba7b63c..8ab94cc99 100644
--- src/resources/beta/threads/runs/runs.ts
+++ src/resources/beta/threads/runs/runs.ts
@@ -731,6 +731,16 @@ export interface RunCreateParamsBase {
   */
  parallel_tool_calls?: boolean;

+  /**
+   * Body param: **o1 and o3-mini models only**
+   *
+   * Constrains effort on reasoning for
+   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+   * result in faster responses and fewer tokens used on reasoning in a response.
+   */
+  reasoning_effort?: 'low' | 'medium' | 'high' | null;
+
  /**
   * Body param: Specifies the format that the model must output. Compatible with
   * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
diff --git src/resources/chat/chat.ts src/resources/chat/chat.ts
index d4a18929c..5bceec45a 100644
--- src/resources/chat/chat.ts
+++ src/resources/chat/chat.ts
@@ -1,7 +1,7 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../resource';
-import * as CompletionsAPI from './completions';
+import * as CompletionsAPI from './completions/completions';
import {
  ChatCompletion,
  ChatCompletionAssistantMessageParam,
@@ -16,9 +16,11 @@ import {
  ChatCompletionCreateParams,
  ChatCompletionCreateParamsNonStreaming,
  ChatCompletionCreateParamsStreaming,
+  ChatCompletionDeleted,
  ChatCompletionDeveloperMessageParam,
  ChatCompletionFunctionCallOption,
  ChatCompletionFunctionMessageParam,
+  ChatCompletionListParams,
  ChatCompletionMessage,
  ChatCompletionMessageParam,
  ChatCompletionMessageToolCall,
@@ -27,19 +29,24 @@ import {
  ChatCompletionPredictionContent,
  Cha,tCompletionReasoningEffort,
  ChatCompletionRole,
+  ChatCompletionStoreMessage,
  ChatCompletionStreamOptions,
  ChatCompletionSystemMessageParam,
  ChatCompletionTokenLogprob,
  ChatCompletionTool,
  ChatCompletionToolChoiceOption,
  ChatCompletionToolMessageParam,
+  ChatCompletionUpdateParams,
  ChatCompletionUserMessageParam,
+  ChatCompletionsPage,
  CompletionCreateParams,
  CompletionCreateParamsNonStreaming,
  CompletionCreateParamsStreaming,
+  CompletionListParams,
+  CompletionUpdateParams,
  Completions,
  CreateChatCompletionRequestMessage,
-} from './completions';
+} from './completions/completions';

export class Chat extends APIResource {
  completions: CompletionsAPI.Completions = new CompletionsAPI.Completions(this._client);
@@ -87,6 +94,7 @@ export type ChatModel =
  | 'gpt-3.5-turbo-16k-0613';

Chat.Completions = Completions;
+Chat.ChatCompletionsPage = ChatCompletionsPage;

export declare namespace Chat {
  export { type ChatModel as ChatModel };
@@ -103,6 +111,7 @@ export declare namespace Chat {
    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,
    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,
    type ChatCompletionContentPartText as ChatCompletionContentPartText,
+    type ChatCompletionDeleted as ChatCompletionDeleted,
    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,
    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
@@ -114,6 +123,7 @@ export declare namespace Chat {
    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,
    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,
    type ChatCompletionRole as ChatCompletionRole,
+    type ChatCompletionStoreMessage as ChatCompletionStoreMessage,
    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,
    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
@@ -122,11 +132,16 @@ export declare namespace Chat {
    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
    type CreateChatCompletionRequestMessage as CreateChatCompletionRequestMessage,
+    ChatCompletionsPage as ChatCompletionsPage,
    type ChatCompletionCreateParams as ChatCompletionCreateParams,
    type CompletionCreateParams as CompletionCreateParams,
    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,
    type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,
    type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
+    type ChatCompletionUpdateParams as ChatCompletionUpdateParams,
+    type CompletionUpdateParams as CompletionUpdateParams,
+    type ChatCompletionListParams as ChatCompletionListParams,
+    type CompletionListParams as CompletionListParams,
  };
}
diff --git src/resources/chat/completions.ts src/resources/chat/completions.ts
index 55b008cf0..55b151e8b 100644
--- src/resources/chat/completions.ts
+++ src/resources/chat/completions.ts
@@ -1,1313 +1 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-import { APIResource } from '../../resource';
-import { APIPromise } from '../../core';
-import * as Core from '../../core';
-import * as ChatCompletionsAPI from './completions';
-import * as CompletionsAPI from '../completions';
-import * as Shared from '../shared';
-import * as ChatAPI from './chat';
-import { Stream } from '../../streaming';
-
-export class Completions extends APIResource {
-  /**
-   * Creates a model response for the given chat conversation. Learn more in the
-   * [text generation](https://platform.openai.com/docs/guides/text-generation),
-   * [vision](https://platform.openai.com/docs/guides/vision), and
-   * [audio](https://platform.openai.com/docs/guides/audio) guides.
-   *
-   * Parameter support can differ depending on the model used to generate the
-   * response, particularly for newer reasoning models. Parameters that are only
-   * supported for reasoning models are noted below. For the current state of
-   * unsupported parameters in reasoning models,
-   * [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).
-   */
-  create(
-    body: ChatCompletionCreateParamsNonStreaming,
-    options?: Core.RequestOptions,
-  ): APIPromise<ChatCompletion>;
-  create(
-    body: ChatCompletionCreateParamsStreaming,
-    options?: Core.RequestOptions,
-  ): APIPromise<Stream<ChatCompletionChunk>>;
-  create(
-    body: ChatCompletionCreateParamsBase,
-    options?: Core.RequestOptions,
-  ): APIPromise<Stream<ChatCompletionChunk> | ChatCompletion>;
-  create(
-    body: ChatCompletionCreateParams,
-    options?: Core.RequestOptions,
-  ): APIPromise<ChatCompletion> | APIPromise<Stream<ChatCompletionChunk>> {
-    return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false }) as
-      | APIPromise<ChatCompletion>
-      | APIPromise<Stream<ChatCompletionChunk>>;
-  }
-}
-
-/**
- * Represents a chat completion response returned by model, based on the provided
- * input.
- */
-export interface ChatCompletion {
-  /**
-   * A unique identifier for the chat completion.
-   */
-  id: string;
-
-  /**
-   * A list of chat completion choices. Can be more than one if `n` is greater
-   * than 1.
-   */
-  choices: Array<ChatCompletion.Choice>;
-
-  /**
-   * The Unix timestamp (in seconds) of when the chat completion was created.
-   */
-  created: number;
-
-  /**
-   * The model used for the chat completion.
-   */
-  model: string;
-
-  /**
-   * The object type, which is always `chat.completion`.
-   */
-  object: 'chat.completion';
-
-  /**
-   * The service tier used for processing the request.
-   */
-  service_tier?: 'scale' | 'default' | null;
-
-  /**
-   * This fingerprint represents the backend configuration that the model runs with.
-   *
-   * Can be used in conjunction with the `seed` request parameter to understand when
-   * backend changes have been made that might impact determinism.
-   */
-  system_fingerprint?: string;
-
-  /**
-   * Usage statistics for the completion request.
-   */
-  usage?: CompletionsAPI.CompletionUsage;
-}
-
-export namespace ChatCompletion {
-  export interface Choice {
-    /**
-     * The reason the model stopped generating tokens. This will be `stop` if the model
-     * hit a natural stop point or a provided stop sequence, `length` if the maximum
-     * number of tokens specified in the request was reached, `content_filter` if
-     * content was omitted due to a flag from our content filters, `tool_calls` if the
-     * model called a tool, or `function_call` (deprecated) if the model called a
-     * function.
-     */
-    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
-
-    /**
-     * The index of the choice in the list of choices.
-     */
-    index: number;
-
-    /**
-     * Log probability information for the choice.
-     */
-    logprobs: Choice.Logprobs | null;
-
-    /**
-     * A chat completion message generated by the model.
-     */
-    message: ChatCompletionsAPI.ChatCompletionMessage;
-  }
-
-  export namespace Choice {
-    /**
-     * Log probability information for the choice.
-     */
-    export interface Logprobs {
-      /**
-       * A list of message content tokens with log probability information.
-       */
-      content: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
-
-      /**
-       * A list of message refusal tokens with log probability information.
-       */
-      refusal: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
-    }
-  }
-}
-
-/**
- * Messages sent by the model in response to user messages.
- */
-export interface ChatCompletionAssistantMessageParam {
-  /**
-   * The role of the messages author, in this case `assistant`.
-   */
-  role: 'assistant';
-
-  /**
-   * Data about a previous audio response from the model.
-   * [Learn more](https://platform.openai.com/docs/guides/audio).
-   */
-  audio?: ChatCompletionAssistantMessageParam.Audio | null;
-
-  /**
-   * The contents of the assistant message. Required unless `tool_calls` or
-   * `function_call` is specified.
-   */
-  content?: string | Array<ChatCompletionContentPartText | ChatCompletionContentPartRefusal> | null;
-
-  /**
-   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-   * function that should be called, as generated by the model.
-   */
-  function_call?: ChatCompletionAssistantMessageParam.FunctionCall | null;
-
-  /**
-   * An optional name for the participant. Provides the model information to
-   * differentiate between participants of the same role.
-   */
-  name?: string;
-
-  /**
-   * The refusal message by the assistant.
-   */
-  refusal?: string | null;
-
-  /**
-   * The tool calls generated by the model, such as function calls.
-   */
-  tool_calls?: Array<ChatCompletionMessageToolCall>;
-}
-
-export namespace ChatCompletionAssistantMessageParam {
-  /**
-   * Data about a previous audio response from the model.
-   * [Learn more](https://platform.openai.com/docs/guides/audio).
-   */
-  export interface Audio {
-    /**
-     * Unique identifier for a previous audio response from the model.
-     */
-    id: string;
-  }
-
-  /**
-   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-   * function that should be called, as generated by the model.
-   */
-  export interface FunctionCall {
-    /**
-     * The arguments to call the function with, as generated by the model in JSON
-     * format. Note that the model does not always generate valid JSON, and may
-     * hallucinate parameters not defined by your function schema. Validate the
-     * arguments in your code before calling your function.
-     */
-    arguments: string;
-
-    /**
-     * The name of the function to call.
-     */
-    name: string;
-  }
-}
-
-/**
- * If the audio output modality is requested, this object contains data about the
- * audio response from the model.
- * [Learn more](https://platform.openai.com/docs/guides/audio).
- */
-export interface ChatCompletionAudio {
-  /**
-   * Unique identifier for this audio response.
-   */
-  id: string;
-
-  /**
-   * Base64 encoded audio bytes generated by the model, in the format specified in
-   * the request.
-   */
-  data: string;
-
-  /**
-   * The Unix timestamp (in seconds) for when this audio response will no longer be
-   * accessible on the server for use in multi-turn conversations.
-   */
-  expires_at: number;
-
-  /**
-   * Transcript of the audio generated by the model.
-   */
-  transcript: string;
-}
-
-/**
- * Parameters for audio output. Required when audio output is requested with
- * `modalities: ["audio"]`.
- * [Learn more](https://platform.openai.com/docs/guides/audio).
- */
-export interface ChatCompletionAudioParam {
-  /**
-   * Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
-   * or `pcm16`.
-   */
-  format: 'wav' | 'mp3' | 'flac' | 'opus' | 'pcm16';
-
-  /**
-   * The voice the model uses to respond. Supported voices are `ash`, `ballad`,
-   * `coral`, `sage`, and `verse` (also supported but not recommended are `alloy`,
-   * `echo`, and `shimmer`; these voices are less expressive).
-   */
-  voice: 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';
-}
-
-/**
- * Represents a streamed chunk of a chat completion response returned by model,
- * based on the provided input.
- */
-export interface ChatCompletionChunk {
-  /**
-   * A unique identifier for the chat completion. Each chunk has the same ID.
-   */
-  id: string;
-
-  /**
-   * A list of chat completion choices. Can contain more than one elements if `n` is
-   * greater than 1. Can also be empty for the last chunk if you set
-   * `stream_options: {"include_usage": true}`.
-   */
-  choices: Array<ChatCompletionChunk.Choice>;
-
-  /**
-   * The Unix timestamp (in seconds) of when the chat completion was created. Each
-   * chunk has the same timestamp.
-   */
-  created: number;
-
-  /**
-   * The model to generate the completion.
-   */
-  model: string;
-
-  /**
-   * The object type, which is always `chat.completion.chunk`.
-   */
-  object: 'chat.completion.chunk';
-
-  /**
-   * The service tier used for processing the request.
-   */
-  service_tier?: 'scale' | 'default' | null;
-
-  /**
-   * This fingerprint represents the backend configuration that the model runs with.
-   * Can be used in conjunction with the `seed` request parameter to understand when
-   * backend changes have been made that might impact determinism.
-   */
-  system_fingerprint?: string;
-
-  /**
-   * An optional field that will only be present when you set
-   * `stream_options: {"include_usage": true}` in your request. When present, it
-   * contains a null value except for the last chunk which contains the token usage
-   * statistics for the entire request.
-   */
-  usage?: CompletionsAPI.CompletionUsage | null;
-}
-
-export namespace ChatCompletionChunk {
-  export interface Choice {
-    /**
-     * A chat completion delta generated by streamed model responses.
-     */
-    delta: Choice.Delta;
-
-    /**
-     * The reason the model stopped generating tokens. This will be `stop` if the model
-     * hit a natural stop point or a provided stop sequence, `length` if the maximum
-     * number of tokens specified in the request was reached, `content_filter` if
-     * content was omitted due to a flag from our content filters, `tool_calls` if the
-     * model called a tool, or `function_call` (deprecated) if the model called a
-     * function.
-     */
-    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call' | null;
-
-    /**
-     * The index of the choice in the list of choices.
-     */
-    index: number;
-
-    /**
-     * Log probability information for the choice.
-     */
-    logprobs?: Choice.Logprobs | null;
-  }
-
-  export namespace Choice {
-    /**
-     * A chat completion delta generated by streamed model responses.
-     */
-    export interface Delta {
-      /**
-       * The contents of the chunk message.
-       */
-      content?: string | null;
-
-      /**
-       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-       * function that should be called, as generated by the model.
-       */
-      function_call?: Delta.FunctionCall;
-
-      /**
-       * The refusal message generated by the model.
-       */
-      refusal?: string | null;
-
-      /**
-       * The role of the author of this message.
-       */
-      role?: 'developer' | 'system' | 'user' | 'assistant' | 'tool';
-
-      tool_calls?: Array<Delta.ToolCall>;
-    }
-
-    export namespace Delta {
-      /**
-       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-       * function that should be called, as generated by the model.
-       */
-      export interface FunctionCall {
-        /**
-         * The arguments to call the function with, as generated by the model in JSON
-         * format. Note that the model does not always generate valid JSON, and may
-         * hallucinate parameters not defined by your function schema. Validate the
-         * arguments in your code before calling your function.
-         */
-        arguments?: string;
-
-        /**
-         * The name of the function to call.
-         */
-        name?: string;
-      }
-
-      export interface ToolCall {
-        index: number;
-
-        /**
-         * The ID of the tool call.
-         */
-        id?: string;
-
-        function?: ToolCall.Function;
-
-        /**
-         * The type of the tool. Currently, only `function` is supported.
-         */
-        type?: 'function';
-      }
-
-      export namespace ToolCall {
-        export interface Function {
-          /**
-           * The arguments to call the function with, as generated by the model in JSON
-           * format. Note that the model does not always generate valid JSON, and may
-           * hallucinate parameters not defined by your function schema. Validate the
-           * arguments in your code before calling your function.
-           */
-          arguments?: string;
-
-          /**
-           * The name of the function to call.
-           */
-          name?: string;
-        }
-      }
-    }
-
-    /**
-     * Log probability information for the choice.
-     */
-    export interface Logprobs {
-      /**
-       * A list of message content tokens with log probability information.
-       */
-      content: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
-
-      /**
-       * A list of message refusal tokens with log probability information.
-       */
-      refusal: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
-    }
-  }
-}
-
-/**
- * Learn about
- * [text inputs](https://platform.openai.com/docs/guides/text-generation).
- */
-export type ChatCompletionContentPart =
-  | ChatCompletionContentPartText
-  | ChatCompletionContentPartImage
-  | ChatCompletionContentPartInputAudio;
-
-/**
- * Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
- */
-export interface ChatCompletionContentPartImage {
-  image_url: ChatCompletionContentPartImage.ImageURL;
-
-  /**
-   * The type of the content part.
-   */
-  type: 'image_url';
-}
-
-export namespace ChatCompletionContentPartImage {
-  export interface ImageURL {
-    /**
-     * Either a URL of the image or the base64 encoded image data.
-     */
-    url: string;
-
-    /**
-     * Specifies the detail level of the image. Learn more in the
-     * [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
-     */
-    detail?: 'auto' | 'low' | 'high';
-  }
-}
-
-/**
- * Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
- */
-export interface ChatCompletionContentPartInputAudio {
-  input_audio: ChatCompletionContentPartInputAudio.InputAudio;
-
-  /**
-   * The type of the content part. Always `input_audio`.
-   */
-  type: 'input_audio';
-}
-
-export namespace ChatCompletionContentPartInputAudio {
-  export interface InputAudio {
-    /**
-     * Base64 encoded audio data.
-     */
-    data: string;
-
-    /**
-     * The format of the encoded audio data. Currently supports "wav" and "mp3".
-     */
-    format: 'wav' | 'mp3';
-  }
-}
-
-export interface ChatCompletionContentPartRefusal {
-  /**
-   * The refusal message generated by the model.
-   */
-  refusal: string;
-
-  /**
-   * The type of the content part.
-   */
-  type: 'refusal';
-}
-
-/**
- * Learn about
- * [text inputs](https://platform.openai.com/docs/guides/text-generation).
- */
-export interface ChatCompletionContentPartText {
-  /**
-   * The text content.
-   */
-  text: string;
-
-  /**
-   * The type of the content part.
-   */
-  type: 'text';
-}
-
-/**
- * Developer-provided instructions that the model should follow, regardless of
- * messages sent by the user. With o1 models and newer, `developer` messages
- * replace the previous `system` messages.
- */
-export interface ChatCompletionDeveloperMessageParam {
-  /**
-   * The contents of the developer message.
-   */
-  content: string | Array<ChatCompletionContentPartText>;
-
-  /**
-   * The role of the messages author, in this case `developer`.
-   */
-  role: 'developer';
-
-  /**
-   * An optional name for the participant. Provides the model information to
-   * differentiate between participants of the same role.
-   */
-  name?: string;
-}
-
-/**
- * Specifying a particular function via `{"name": "my_function"}` forces the model
- * to call that function.
- */
-export interface ChatCompletionFunctionCallOption {
-  /**
-   * The name of the function to call.
-   */
-  name: string;
-}
-
-/**
- * @deprecated
- */
-export interface ChatCompletionFunctionMessageParam {
-  /**
-   * The contents of the function message.
-   */
-  content: string | null;
-
-  /**
-   * The name of the function to call.
-   */
-  name: string;
-
-  /**
-   * The role of the messages author, in this case `function`.
-   */
-  role: 'function';
-}
-
-/**
- * A chat completion message generated by the model.
- */
-export interface ChatCompletionMessage {
-  /**
-   * The contents of the message.
-   */
-  content: string | null;
-
-  /**
-   * The refusal message generated by the model.
-   */
-  refusal: string | null;
-
-  /**
-   * The role of the author of this message.
-   */
-  role: 'assistant';
-
-  /**
-   * If the audio output modality is requested, this object contains data about the
-   * audio response from the model.
-   * [Learn more](https://platform.openai.com/docs/guides/audio).
-   */
-  audio?: ChatCompletionAudio | null;
-
-  /**
-   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-   * function that should be called, as generated by the model.
-   */
-  function_call?: ChatCompletionMessage.FunctionCall | null;
-
-  /**
-   * The tool calls generated by the model, such as function calls.
-   */
-  tool_calls?: Array<ChatCompletionMessageToolCall>;
-}
-
-export namespace ChatCompletionMessage {
-  /**
-   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
-   * function that should be called, as generated by the model.
-   */
-  export interface FunctionCall {
-    /**
-     * The arguments to call the function with, as generated by the model in JSON
-     * format. Note that the model does not always generate valid JSON, and may
-     * hallucinate parameters not defined by your function schema. Validate the
-     * arguments in your code before calling your function.
-     */
-    arguments: string;
-
-    /**
-     * The name of the function to call.
-     */
-    name: string;
-  }
-}
-
-/**
- * Developer-provided instructions that the model should follow, regardless of
- * messages sent by the user. With o1 models and newer, `developer` messages
- * replace the previous `system` messages.
- */
-export type ChatCompletionMessageParam =
-  | ChatCompletionDeveloperMessageParam
-  | ChatCompletionSystemMessageParam
-  | ChatCompletionUserMessageParam
-  | ChatCompletionAssistantMessageParam
-  | ChatCompletionToolMessageParam
-  | ChatCompletionFunctionMessageParam;
-
-export interface ChatCompletionMessageToolCall {
-  /**
-   * The ID of the tool call.
-   */
-  id: string;
-
-  /**
-   * The function that the model called.
-   */
-  function: ChatCompletionMessageToolCall.Function;
-
-  /**
-   * The type of the tool. Currently, only `function` is supported.
-   */
-  type: 'function';
-}
-
-export namespace ChatCompletionMessageToolCall {
-  /**
-   * The function that the model called.
-   */
-  export interface Function {
-    /**
-     * The arguments to call the function with, as generated by the model in JSON
-     * format. Note that the model does not always generate valid JSON, and may
-     * hallucinate parameters not defined by your function schema. Validate the
-     * arguments in your code before calling your function.
-     */
-    arguments: string;
-
-    /**
-     * The name of the function to call.
-     */
-    name: string;
-  }
-}
-
-export type ChatCompletionModality = 'text' | 'audio';
-
-/**
- * Specifies a tool the model should use. Use to force the model to call a specific
- * function.
- */
-export interface ChatCompletionNamedToolChoice {
-  function: ChatCompletionNamedToolChoice.Function;
-
-  /**
-   * The type of the tool. Currently, only `function` is supported.
-   */
-  type: 'function';
-}
-
-export namespace ChatCompletionNamedToolChoice {
-  export interface Function {
-    /**
-     * The name of the function to call.
-     */
-    name: string;
-  }
-}
-
-/**
- * Static predicted output content, such as the content of a text file that is
- * being regenerated.
- */
-export interface ChatCompletionPredictionContent {
-  /**
-   * The content that should be matched when generating a model response. If
-   * generated tokens would match this content, the entire model response can be
-   * returned much more quickly.
-   */
-  content: string | Array<ChatCompletionContentPartText>;
-
-  /**
-   * The type of the predicted content you want to provide. This type is currently
-   * always `content`.
-   */
-  type: 'content';
-}
-
-/**
- * **o1 models only**
- *
- * Constrains effort on reasoning for
- * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
- * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
- * result in faster responses and fewer tokens used on reasoning in a response.
- */
-export type ChatCompletionReasoningEffort = 'low' | 'medium' | 'high';
-
-/**
- * The role of the author of a message
- */
-export type ChatCompletionRole = 'developer' | 'system' | 'user' | 'assistant' | 'tool' | 'function';
-
-/**
- * Options for streaming response. Only set this when you set `stream: true`.
- */
-export interface ChatCompletionStreamOptions {
-  /**
-   * If set, an additional chunk will be streamed before the `data: [DONE]` message.
-   * The `usage` field on this chunk shows the token usage statistics for the entire
-   * request, and the `choices` field will always be an empty array. All other chunks
-   * will also include a `usage` field, but with a null value.
-   */
-  include_usage?: boolean;
-}
-
-/**
- * Developer-provided instructions that the model should follow, regardless of
- * messages sent by the user. With o1 models and newer, use `developer` messages
- * for this purpose instead.
- */
-export interface ChatCompletionSystemMessageParam {
-  /**
-   * The contents of the system message.
-   */
-  content: string | Array<ChatCompletionContentPartText>;
-
-  /**
-   * The role of the messages author, in this case `system`.
-   */
-  role: 'system';
-
-  /**
-   * An optional name for the participant. Provides the model information to
-   * differentiate between participants of the same role.
-   */
-  name?: string;
-}
-
-export interface ChatCompletionTokenLogprob {
-  /**
-   * The token.
-   */
-  token: string;
-
-  /**
-   * A list of integers representing the UTF-8 bytes representation of the token.
-   * Useful in instances where characters are represented by multiple tokens and
-   * their byte representations must be combined to generate the correct text
-   * representation. Can be `null` if there is no bytes representation for the token.
-   */
-  bytes: Array<number> | null;
-
-  /**
-   * The log probability of this token, if it is within the top 20 most likely
-   * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
-   * unlikely.
-   */
-  logprob: number;
-
-  /**
-   * List of the most likely tokens and their log probability, at this token
-   * position. In rare cases, there may be fewer than the number of requested
-   * `top_logprobs` returned.
-   */
-  top_logprobs: Array<ChatCompletionTokenLogprob.TopLogprob>;
-}
-
-export namespace ChatCompletionTokenLogprob {
-  export interface TopLogprob {
-    /**
-     * The token.
-     */
-    token: string;
-
-    /**
-     * A list of integers representing the UTF-8 bytes representation of the token.
-     * Useful in instances where characters are represented by multiple tokens and
-     * their byte representations must be combined to generate the correct text
-     * representation. Can be `null` if there is no bytes representation for the token.
-     */
-    bytes: Array<number> | null;
-
-    /**
-     * The log probability of this token, if it is within the top 20 most likely
-     * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
-     * unlikely.
-     */
-    logprob: number;
-  }
-}
-
-export interface ChatCompletionTool {
-  function: Shared.FunctionDefinition;
-
-  /**
-   * The type of the tool. Currently, only `function` is supported.
-   */
-  type: 'function';
-}
-
-/**
- * Controls which (if any) tool is called by the model. `none` means the model will
- * not call any tool and instead generates a message. `auto` means the model can
- * pick between generating a message or calling one or more tools. `required` means
- * the model must call one or more tools. Specifying a particular tool via
- * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
- * call that tool.
- *
- * `none` is the default when no tools are present. `auto` is the default if tools
- * are present.
- */
-export type ChatCompletionToolChoiceOption = 'none' | 'auto' | 'required' | ChatCompletionNamedToolChoice;
-
-export interface ChatCompletionToolMessageParam {
-  /**
-   * The contents of the tool message.
-   */
-  content: string | Array<ChatCompletionContentPartText>;
-
-  /**
-   * The role of the messages author, in this case `tool`.
-   */
-  role: 'tool';
-
-  /**
-   * Tool call that this message is responding to.
-   */
-  tool_call_id: string;
-}
-
-/**
- * Messages sent by an end user, containing prompts or additional context
- * information.
- */
-export interface ChatCompletionUserMessageParam {
-  /**
-   * The contents of the user message.
-   */
-  content: string | Array<ChatCompletionContentPart>;
-
-  /**
-   * The role of the messages author, in this case `user`.
-   */
-  role: 'user';
-
-  /**
-   * An optional name for the participant. Provides the model information to
-   * differentiate between participants of the same role.
-   */
-  name?: string;
-}
-
-/**
- * @deprecated ChatCompletionMessageParam should be used instead
- */
-export type CreateChatCompletionRequestMessage = ChatCompletionMessageParam;
-
-export type ChatCompletionCreateParams =
-  | ChatCompletionCreateParamsNonStreaming
-  | ChatCompletionCreateParamsStreaming;
-
-export interface ChatCompletionCreateParamsBase {
-  /**
-   * A list of messages comprising the conversation so far. Depending on the
-   * [model](https://platform.openai.com/docs/models) you use, different message
-   * types (modalities) are supported, like
-   * [text](https://platform.openai.com/docs/guides/text-generation),
-   * [images](https://platform.openai.com/docs/guides/vision), and
-   * [audio](https://platform.openai.com/docs/guides/audio).
-   */
-  messages: Array<ChatCompletionMessageParam>;
-
-  /**
-   * ID of the model to use. See the
-   * [model endpoint compatibility](https://platform.openai.com/docs/models#model-endpoint-compatibility)
-   * table for details on which models work with the Chat API.
-   */
-  model: (string & {}) | ChatAPI.ChatModel;
-
-  /**
-   * Parameters for audio output. Required when audio output is requested with
-   * `modalities: ["audio"]`.
-   * [Learn more](https://platform.openai.com/docs/guides/audio).
-   */
-  audio?: ChatCompletionAudioParam | null;
-
-  /**
-   * Number between -2.0 and 2.0. Positive values penalize new tokens based on their
-   * existing frequency in the text so far, decreasing the model's likelihood to
-   * repeat the same line verbatim.
-   */
-  frequency_penalty?: number | null;
-
-  /**
-   * Deprecated in favor of `tool_choice`.
-   *
-   * Controls which (if any) function is called by the model.
-   *
-   * `none` means the model will not call a function and instead generates a message.
-   *
-   * `auto` means the model can pick between generating a message or calling a
-   * function.
-   *
-   * Specifying a particular function via `{"name": "my_function"}` forces the model
-   * to call that function.
-   *
-   * `none` is the default when no functions are present. `auto` is the default if
-   * functions are present.
-   */
-  function_call?: 'none' | 'auto' | ChatCompletionFunctionCallOption;
-
-  /**
-   * Deprecated in favor of `tools`.
-   *
-   * A list of functions the model may generate JSON inputs for.
-   */
-  functions?: Array<ChatCompletionCreateParams.Function>;
-
-  /**
-   * Modify the likelihood of specified tokens appearing in the completion.
-   *
-   * Accepts a JSON object that maps tokens (specified by their token ID in the
-   * tokenizer) to an associated bias value from -100 to 100. Mathematically, the
-   * bias is added to the logits generated by the model prior to sampling. The exact
-   * effect will vary per model, but values between -1 and 1 should decrease or
-   * increase likelihood of selection; values like -100 or 100 should result in a ban
-   * or exclusive selection of the relevant token.
-   */
-  logit_bias?: Record<string, number> | null;
-
-  /**
-   * Whether to return log probabilities of the output tokens or not. If true,
-   * returns the log probabilities of each output token returned in the `content` of
-   * `message`.
-   */
-  logprobs?: boolean | null;
-
-  /**
-   * An upper bound for the number of tokens that can be generated for a completion,
-   * including visible output tokens and
-   * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
-   */
-  max_completion_tokens?: number | null;
-
-  /**
-   * The maximum number of [tokens](/tokenizer) that can be generated in the chat
-   * completion. This value can be used to control
-   * [costs](https://openai.com/api/pricing/) for text generated via API.
-   *
-   * This value is now deprecated in favor of `max_completion_tokens`, and is not
-   * compatible with
-   * [o1 series models](https://platform.openai.com/docs/guides/reasoning).
-   */
-  max_tokens?: number | null;
-
-  /**
-   * Set of 16 key-value pairs that can be attached to an object. This can be useful
-   * for storing additional information about the object in a structured format, and
-   * querying for objects via API or the dashboard.
-   *
-   * Keys are strings with a maximum length of 64 characters. Values are strings with
-   * a maximum length of 512 characters.
-   */
-  metadata?: Shared.Metadata | null;
-
-  /**
-   * Output types that you would like the model to generate for this request. Most
-   * models are capable of generating text, which is the default:
-   *
-   * `["text"]`
-   *
-   * The `gpt-4o-audio-preview` model can also be used to
-   * [generate audio](https://platform.openai.com/docs/guides/audio). To request that
-   * this model generate both text and audio responses, you can use:
-   *
-   * `["text", "audio"]`
-   */
-  modalities?: Array<ChatCompletionModality> | null;
-
-  /**
-   * How many chat completion choices to generate for each input message. Note that
-   * you will be charged based on the number of generated tokens across all of the
-   * choices. Keep `n` as `1` to minimize costs.
-   */
-  n?: number | null;
-
-  /**
-   * Whether to enable
-   * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
-   * during tool use.
-   */
-  parallel_tool_calls?: boolean;
-
-  /**
-   * Static predicted output content, such as the content of a text file that is
-   * being regenerated.
-   */
-  prediction?: ChatCompletionPredictionContent | null;
-
-  /**
-   * Number between -2.0 and 2.0. Positive values penalize new tokens based on
-   * whether they appear in the text so far, increasing the model's likelihood to
-   * talk about new topics.
-   */
-  presence_penalty?: number | null;
-
-  /**
-   * **o1 models only**
-   *
-   * Constrains effort on reasoning for
-   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
-   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
-   * result in faster responses and fewer tokens used on reasoning in a response.
-   */
-  reasoning_effort?: ChatCompletionReasoningEffort;
-
-  /**
-   * An object specifying the format that the model must output.
-   *
-   * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
-   * Outputs which ensures the model will match your supplied JSON schema. Learn more
-   * in the
-   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
-   *
-   * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
-   * message the model generates is valid JSON.
-   *
-   * **Important:** when using JSON mode, you **must** also instruct the model to
-   * produce JSON yourself via a system or user message. Without this, the model may
-   * generate an unending stream of whitespace until the generation reaches the token
-   * limit, resulting in a long-running and seemingly "stuck" request. Also note that
-   * the message content may be partially cut off if `finish_reason="length"`, which
-   * indicates the generation exceeded `max_tokens` or the conversation exceeded the
-   * max context length.
-   */
-  response_format?:
-    | Shared.ResponseFormatText
-    | Shared.ResponseFormatJSONObject
-    | Shared.ResponseFormatJSONSchema;
-
-  /**
-   * This feature is in Beta. If specified, our system will make a best effort to
-   * sample deterministically, such that repeated requests with the same `seed` and
-   * parameters should return the same result. Determinism is not guaranteed, and you
-   * should refer to the `system_fingerprint` response parameter to monitor changes
-   * in the backend.
-   */
-  seed?: number | null;
-
-  /**
-   * Specifies the latency tier to use for processing the request. This parameter is
-   * relevant for customers subscribed to the scale tier service:
-   *
-   * - If set to 'auto', and the Project is Scale tier enabled, the system will
-   *   utilize scale tier credits until they are exhausted.
-   * - If set to 'auto', and the Project is not Scale tier enabled, the request will
-   *   be processed using the default service tier with a lower uptime SLA and no
-   *   latency guarantee.
-   * - If set to 'default', the request will be processed using the default service
-   *   tier with a lower uptime SLA and no latency guarantee.
-   * - When not set, the default behavior is 'auto'.
-   */
-  service_tier?: 'auto' | 'default' | null;
-
-  /**
-   * Up to 4 sequences where the API will stop generating further tokens.
-   */
-  stop?: string | null | Array<string>;
-
-  /**
-   * Whether or not to store the output of this chat completion request for use in
-   * our [model distillation](https://platform.openai.com/docs/guides/distillation)
-   * or [evals](https://platform.openai.com/docs/guides/evals) products.
-   */
-  store?: boolean | null;
-
-  /**
-   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
-   * sent as data-only
-   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
-   * as they become available, with the stream terminated by a `data: [DONE]`
-   * message.
-   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
-   */
-  stream?: boolean | null;
-
-  /**
-   * Options for streaming response. Only set this when you set `stream: true`.
-   */
-  stream_options?: ChatCompletionStreamOptions | null;
-
-  /**
-   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
-   * make the output more random, while lower values like 0.2 will make it more
-   * focused and deterministic. We generally recommend altering this or `top_p` but
-   * not both.
-   */
-  temperature?: number | null;
-
-  /**
-   * Controls which (if any) tool is called by the model. `none` means the model will
-   * not call any tool and instead generates a message. `auto` means the model can
-   * pick between generating a message or calling one or more tools. `required` means
-   * the model must call one or more tools. Specifying a particular tool via
-   * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
-   * call that tool.
-   *
-   * `none` is the default when no tools are present. `auto` is the default if tools
-   * are present.
-   */
-  tool_choice?: ChatCompletionToolChoiceOption;
-
-  /**
-   * A list of tools the model may call. Currently, only functions are supported as a
-   * tool. Use this to provide a list of functions the model may generate JSON inputs
-   * for. A max of 128 functions are supported.
-   */
-  tools?: Array<ChatCompletionTool>;
-
-  /**
-   * An integer between 0 and 20 specifying the number of most likely tokens to
-   * return at each token position, each with an associated log probability.
-   * `logprobs` must be set to `true` if this parameter is used.
-   */
-  top_logprobs?: number | null;
-
-  /**
-   * An alternative to sampling with temperature, called nucleus sampling, where the
-   * model considers the results of the tokens with top_p probability mass. So 0.1
-   * means only the tokens comprising the top 10% probability mass are considered.
-   *
-   * We generally recommend altering this or `temperature` but not both.
-   */
-  top_p?: number | null;
-
-  /**
-   * A unique identifier representing your end-user, which can help OpenAI to monitor
-   * and detect abuse.
-   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
-   */
-  user?: string;
-}
-
-export namespace ChatCompletionCreateParams {
-  /**
-   * @deprecated
-   */
-  export interface Function {
-    /**
-     * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
-     * underscores and dashes, with a maximum length of 64.
-     */
-    name: string;
-
-    /**
-     * A description of what the function does, used by the model to choose when and
-     * how to call the function.
-     */
-    description?: string;
-
-    /**
-     * The parameters the functions accepts, described as a JSON Schema object. See the
-     * [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
-     * and the
-     * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
-     * documentation about the format.
-     *
-     * Omitting `parameters` defines a function with an empty parameter list.
-     */
-    parameters?: Shared.FunctionParameters;
-  }
-
-  export type ChatCompletionCreateParamsNonStreaming =
-    ChatCompletionsAPI.ChatCompletionCreateParamsNonStreaming;
-  export type ChatCompletionCreateParamsStreaming = ChatCompletionsAPI.ChatCompletionCreateParamsStreaming;
-}
-
-/**
- * @deprecated Use ChatCompletionCreateParams instead
- */
-export type CompletionCreateParams = ChatCompletionCreateParams;
-
-export interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase {
-  /**
-   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
-   * sent as data-only
-   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
-   * as they become available, with the stream terminated by a `data: [DONE]`
-   * message.
-   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
-   */
-  stream?: false | null;
-}
-
-/**
- * @deprecated Use ChatCompletionCreateParamsNonStreaming instead
- */
-export type CompletionCreateParamsNonStreaming = ChatCompletionCreateParamsNonStreaming;
-
-export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreateParamsBase {
-  /**
-   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
-   * sent as data-only
-   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
-   * as they become available, with the stream terminated by a `data: [DONE]`
-   * message.
-   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
-   */
-  stream: true;
-}
-
-/**
- * @deprecated Use ChatCompletionCreateParamsStreaming instead
- */
-export type CompletionCreateParamsStreaming = ChatCompletionCreateParamsStreaming;
-
-export declare namespace Completions {
-  export {
-    type ChatCompletion as ChatCompletion,
-    type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,
-    type ChatCompletionAudio as ChatCompletionAudio,
-    type ChatCompletionAudioParam as ChatCompletionAudioParam,
-    type ChatCompletionChunk as ChatCompletionChunk,
-    type ChatCompletionContentPart as ChatCompletionContentPart,
-    type ChatCompletionContentPartImage as ChatCompletionContentPartImage,
-    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,
-    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,
-    type ChatCompletionContentPartText as ChatCompletionContentPartText,
-    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,
-    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
-    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
-    type ChatCompletionMessage as ChatCompletionMessage,
-    type ChatCompletionMessageParam as ChatCompletionMessageParam,
-    type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,
-    type ChatCompletionModality as ChatCompletionModality,
-    type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,
-    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,
-    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,
-    type ChatCompletionRole as ChatCompletionRole,
-    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,
-    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
-    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
-    type ChatCompletionTool as ChatCompletionTool,
-    type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,
-    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
-    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
-    type CreateChatCompletionRequestMessage as CreateChatCompletionRequestMessage,
-    type ChatCompletionCreateParams as ChatCompletionCreateParams,
-    type CompletionCreateParams as CompletionCreateParams,
-    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,
-    type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
-    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,
-    type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
-  };
-}
+export * from './completions/completions';
diff --git a/src/resources/chat/completions/completions.ts b/src/resources/chat/completions/completions.ts
new file mode 100644
index 000000000..3af4a3a1d
--- /dev/null
+++ src/resources/chat/completions/completions.ts
@@ -0,0 +1,1453 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import { APIResource } from '../../../resource';
+import { isRequestOptions } from '../../../core';
+import { APIPromise } from '../../../core';
+import * as Core from '../../../core';
+import * as CompletionsCompletionsAPI from './completions';
+import * as CompletionsAPI from '../../completions';
+import * as Shared from '../../shared';
+import * as ChatAPI from '../chat';
+import * as MessagesAPI from './messages';
+import { MessageListParams, Messages } from './messages';
+import { CursorPage, type CursorPageParams } from '../../../pagination';
+import { Stream } from '../../../streaming';
+
+export class Completions extends APIResource {
+  messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client);
+
+  /**
+   * Creates a model response for the given chat conversation. Learn more in the
+   * [text generation](https://platform.openai.com/docs/guides/text-generation),
+   * [vision](https://platform.openai.com/docs/guides/vision), and
+   * [audio](https://platform.openai.com/docs/guides/audio) guides.
+   *
+   * Parameter support can differ depending on the model used to generate the
+   * response, particularly for newer reasoning models. Parameters that are only
+   * supported for reasoning models are noted below. For the current state of
+   * unsupported parameters in reasoning models,
+   * [refer to the reasoning guide](https://platform.openai.com/docs/guides/reasoning).
+   */
+  create(
+    body: ChatCompletionCreateParamsNonStreaming,
+    options?: Core.RequestOptions,
+  ): APIPromise<ChatCompletion>;
+  create(
+    body: ChatCompletionCreateParamsStreaming,
+    options?: Core.RequestOptions,
+  ): APIPromise<Stream<ChatCompletionChunk>>;
+  create(
+    body: ChatCompletionCreateParamsBase,
+    options?: Core.RequestOptions,
+  ): APIPromise<Stream<ChatCompletionChunk> | ChatCompletion>;
+  create(
+    body: ChatCompletionCreateParams,
+    options?: Core.RequestOptions,
+  ): APIPromise<ChatCompletion> | APIPromise<Stream<ChatCompletionChunk>> {
+    return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false }) as
+      | APIPromise<ChatCompletion>
+      | APIPromise<Stream<ChatCompletionChunk>>;
+  }
+
+  /**
+   * Get a stored chat completion. Only chat completions that have been created with
+   * the `store` parameter set to `true` will be returned.
+   */
+  retrieve(completionId: string, options?: Core.RequestOptions): Core.APIPromise<ChatCompletion> {
+    return this._client.get(`/chat/completions/${completionId}`, options);
+  }
+
+  /**
+   * Modify a stored chat completion. Only chat completions that have been created
+   * with the `store` parameter set to `true` can be modified. Currently, the only
+   * supported modification is to update the `metadata` field.
+   */
+  update(
+    completionId: string,
+    body: ChatCompletionUpdateParams,
+    options?: Core.RequestOptions,
+  ): Core.APIPromise<ChatCompletion> {
+    return this._client.post(`/chat/completions/${completionId}`, { body, ...options });
+  }
+
+  /**
+   * List stored chat completions. Only chat completions that have been stored with
+   * the `store` parameter set to `true` will be returned.
+   */
+  list(
+    query?: ChatCompletionListParams,
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionsPage, ChatCompletion>;
+  list(options?: Core.RequestOptions): Core.PagePromise<ChatCompletionsPage, ChatCompletion>;
+  list(
+    query: ChatCompletionListParams | Core.RequestOptions = {},
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionsPage, ChatCompletion> {
+    if (isRequestOptions(query)) {
+      return this.list({}, query);
+    }
+    return this._client.getAPIList('/chat/completions', ChatCompletionsPage, { query, ...options });
+  }
+
+  /**
+   * Delete a stored chat completion. Only chat completions that have been created
+   * with the `store` parameter set to `true` can be deleted.
+   */
+  del(completionId: string, options?: Core.RequestOptions): Core.APIPromise<ChatCompletionDeleted> {
+    return this._client.delete(`/chat/completions/${completionId}`, options);
+  }
+}
+
+export class ChatCompletionsPage extends CursorPage<ChatCompletion> {}
+
+export class ChatCompletionStoreMessagesPage extends CursorPage<ChatCompletionStoreMessage> {}
+
+/**
+ * Represents a chat completion response returned by model, based on the provided
+ * input.
+ */
+export interface ChatCompletion {
+  /**
+   * A unique identifier for the chat completion.
+   */
+  id: string;
+
+  /**
+   * A list of chat completion choices. Can be more than one if `n` is greater
+   * than 1.
+   */
+  choices: Array<ChatCompletion.Choice>;
+
+  /**
+   * The Unix timestamp (in seconds) of when the chat completion was created.
+   */
+  created: number;
+
+  /**
+   * The model used for the chat completion.
+   */
+  model: string;
+
+  /**
+   * The object type, which is always `chat.completion`.
+   */
+  object: 'chat.completion';
+
+  /**
+   * The service tier used for processing the request.
+   */
+  service_tier?: 'scale' | 'default' | null;
+
+  /**
+   * This fingerprint represents the backend configuration that the model runs with.
+   *
+   * Can be used in conjunction with the `seed` request parameter to understand when
+   * backend changes have been made that might impact determinism.
+   */
+  system_fingerprint?: string;
+
+  /**
+   * Usage statistics for the completion request.
+   */
+  usage?: CompletionsAPI.CompletionUsage;
+}
+
+export namespace ChatCompletion {
+  export interface Choice {
+    /**
+     * The reason the model stopped generating tokens. This will be `stop` if the model
+     * hit a natural stop point or a provided stop sequence, `length` if the maximum
+     * number of tokens specified in the request was reached, `content_filter` if
+     * content was omitted due to a flag from our content filters, `tool_calls` if the
+     * model called a tool, or `function_call` (deprecated) if the model called a
+     * function.
+     */
+    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
+
+    /**
+     * The index of the choice in the list of choices.
+     */
+    index: number;
+
+    /**
+     * Log probability information for the choice.
+     */
+    logprobs: Choice.Logprobs | null;
+
+    /**
+     * A chat completion message generated by the model.
+     */
+    message: CompletionsCompletionsAPI.ChatCompletionMessage;
+  }
+
+  export namespace Choice {
+    /**
+     * Log probability information for the choice.
+     */
+    export interface Logprobs {
+      /**
+       * A list of message content tokens with log probability information.
+       */
+      content: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
+
+      /**
+       * A list of message refusal tokens with log probability information.
+       */
+      refusal: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
+    }
+  }
+}
+
+/**
+ * Messages sent by the model in response to user messages.
+ */
+export interface ChatCompletionAssistantMessageParam {
+  /**
+   * The role of the messages author, in this case `assistant`.
+   */
+  role: 'assistant';
+
+  /**
+   * Data about a previous audio response from the model.
+   * [Learn more](https://platform.openai.com/docs/guides/audio).
+   */
+  audio?: ChatCompletionAssistantMessageParam.Audio | null;
+
+  /**
+   * The contents of the assistant message. Required unless `tool_calls` or
+   * `function_call` is specified.
+   */
+  content?: string | Array<ChatCompletionContentPartText | ChatCompletionContentPartRefusal> | null;
+
+  /**
+   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+   * function that should be called, as generated by the model.
+   */
+  function_call?: ChatCompletionAssistantMessageParam.FunctionCall | null;
+
+  /**
+   * An optional name for the participant. Provides the model information to
+   * differentiate between participants of the same role.
+   */
+  name?: string;
+
+  /**
+   * The refusal message by the assistant.
+   */
+  refusal?: string | null;
+
+  /**
+   * The tool calls generated by the model, such as function calls.
+   */
+  tool_calls?: Array<ChatCompletionMessageToolCall>;
+}
+
+export namespace ChatCompletionAssistantMessageParam {
+  /**
+   * Data about a previous audio response from the model.
+   * [Learn more](https://platform.openai.com/docs/guides/audio).
+   */
+  export interface Audio {
+    /**
+     * Unique identifier for a previous audio response from the model.
+     */
+    id: string;
+  }
+
+  /**
+   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+   * function that should be called, as generated by the model.
+   */
+  export interface FunctionCall {
+    /**
+     * The arguments to call the function with, as generated by the model in JSON
+     * format. Note that the model does not always generate valid JSON, and may
+     * hallucinate parameters not defined by your function schema. Validate the
+     * arguments in your code before calling your function.
+     */
+    arguments: string;
+
+    /**
+     * The name of the function to call.
+     */
+    name: string;
+  }
+}
+
+/**
+ * If the audio output modality is requested, this object contains data about the
+ * audio response from the model.
+ * [Learn more](https://platform.openai.com/docs/guides/audio).
+ */
+export interface ChatCompletionAudio {
+  /**
+   * Unique identifier for this audio response.
+   */
+  id: string;
+
+  /**
+   * Base64 encoded audio bytes generated by the model, in the format specified in
+   * the request.
+   */
+  data: string;
+
+  /**
+   * The Unix timestamp (in seconds) for when this audio response will no longer be
+   * accessible on the server for use in multi-turn conversations.
+   */
+  expires_at: number;
+
+  /**
+   * Transcript of the audio generated by the model.
+   */
+  transcript: string;
+}
+
+/**
+ * Parameters for audio output. Required when audio output is requested with
+ * `modalities: ["audio"]`.
+ * [Learn more](https://platform.openai.com/docs/guides/audio).
+ */
+export interface ChatCompletionAudioParam {
+  /**
+   * Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`, `opus`,
+   * or `pcm16`.
+   */
+  format: 'wav' | 'mp3' | 'flac' | 'opus' | 'pcm16';
+
+  /**
+   * The voice the model uses to respond. Supported voices are `ash`, `ballad`,
+   * `coral`, `sage`, and `verse` (also supported but not recommended are `alloy`,
+   * `echo`, and `shimmer`; these voices are less expressive).
+   */
+  voice: 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';
+}
+
+/**
+ * Represents a streamed chunk of a chat completion response returned by model,
+ * based on the provided input.
+ */
+export interface ChatCompletionChunk {
+  /**
+   * A unique identifier for the chat completion. Each chunk has the same ID.
+   */
+  id: string;
+
+  /**
+   * A list of chat completion choices. Can contain more than one elements if `n` is
+   * greater than 1. Can also be empty for the last chunk if you set
+   * `stream_options: {"include_usage": true}`.
+   */
+  choices: Array<ChatCompletionChunk.Choice>;
+
+  /**
+   * The Unix timestamp (in seconds) of when the chat completion was created. Each
+   * chunk has the same timestamp.
+   */
+  created: number;
+
+  /**
+   * The model to generate the completion.
+   */
+  model: string;
+
+  /**
+   * The object type, which is always `chat.completion.chunk`.
+   */
+  object: 'chat.completion.chunk';
+
+  /**
+   * The service tier used for processing the request.
+   */
+  service_tier?: 'scale' | 'default' | null;
+
+  /**
+   * This fingerprint represents the backend configuration that the model runs with.
+   * Can be used in conjunction with the `seed` request parameter to understand when
+   * backend changes have been made that might impact determinism.
+   */
+  system_fingerprint?: string;
+
+  /**
+   * An optional field that will only be present when you set
+   * `stream_options: {"include_usage": true}` in your request. When present, it
+   * contains a null value except for the last chunk which contains the token usage
+   * statistics for the entire request.
+   */
+  usage?: CompletionsAPI.CompletionUsage | null;
+}
+
+export namespace ChatCompletionChunk {
+  export interface Choice {
+    /**
+     * A chat completion delta generated by streamed model responses.
+     */
+    delta: Choice.Delta;
+
+    /**
+     * The reason the model stopped generating tokens. This will be `stop` if the model
+     * hit a natural stop point or a provided stop sequence, `length` if the maximum
+     * number of tokens specified in the request was reached, `content_filter` if
+     * content was omitted due to a flag from our content filters, `tool_calls` if the
+     * model called a tool, or `function_call` (deprecated) if the model called a
+     * function.
+     */
+    finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call' | null;
+
+    /**
+     * The index of the choice in the list of choices.
+     */
+    index: number;
+
+    /**
+     * Log probability information for the choice.
+     */
+    logprobs?: Choice.Logprobs | null;
+  }
+
+  export namespace Choice {
+    /**
+     * A chat completion delta generated by streamed model responses.
+     */
+    export interface Delta {
+      /**
+       * The contents of the chunk message.
+       */
+      content?: string | null;
+
+      /**
+       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+       * function that should be called, as generated by the model.
+       */
+      function_call?: Delta.FunctionCall;
+
+      /**
+       * The refusal message generated by the model.
+       */
+      refusal?: string | null;
+
+      /**
+       * The role of the author of this message.
+       */
+      role?: 'developer' | 'system' | 'user' | 'assistant' | 'tool';
+
+      tool_calls?: Array<Delta.ToolCall>;
+    }
+
+    export namespace Delta {
+      /**
+       * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+       * function that should be called, as generated by the model.
+       */
+      export interface FunctionCall {
+        /**
+         * The arguments to call the function with, as generated by the model in JSON
+         * format. Note that the model does not always generate valid JSON, and may
+         * hallucinate parameters not defined by your function schema. Validate the
+         * arguments in your code before calling your function.
+         */
+        arguments?: string;
+
+        /**
+         * The name of the function to call.
+         */
+        name?: string;
+      }
+
+      export interface ToolCall {
+        index: number;
+
+        /**
+         * The ID of the tool call.
+         */
+        id?: string;
+
+        function?: ToolCall.Function;
+
+        /**
+         * The type of the tool. Currently, only `function` is supported.
+         */
+        type?: 'function';
+      }
+
+      export namespace ToolCall {
+        export interface Function {
+          /**
+           * The arguments to call the function with, as generated by the model in JSON
+           * format. Note that the model does not always generate valid JSON, and may
+           * hallucinate parameters not defined by your function schema. Validate the
+           * arguments in your code before calling your function.
+           */
+          arguments?: string;
+
+          /**
+           * The name of the function to call.
+           */
+          name?: string;
+        }
+      }
+    }
+
+    /**
+     * Log probability information for the choice.
+     */
+    export interface Logprobs {
+      /**
+       * A list of message content tokens with log probability information.
+       */
+      content: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
+
+      /**
+       * A list of message refusal tokens with log probability information.
+       */
+      refusal: Array<CompletionsCompletionsAPI.ChatCompletionTokenLogprob> | null;
+    }
+  }
+}
+
+/**
+ * Learn about
+ * [text inputs](https://platform.openai.com/docs/guides/text-generation).
+ */
+export type ChatCompletionContentPart =
+  | ChatCompletionContentPartText
+  | ChatCompletionContentPartImage
+  | ChatCompletionContentPartInputAudio;
+
+/**
+ * Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
+ */
+export interface ChatCompletionContentPartImage {
+  image_url: ChatCompletionContentPartImage.ImageURL;
+
+  /**
+   * The type of the content part.
+   */
+  type: 'image_url';
+}
+
+export namespace ChatCompletionContentPartImage {
+  export interface ImageURL {
+    /**
+     * Either a URL of the image or the base64 encoded image data.
+     */
+    url: string;
+
+    /**
+     * Specifies the detail level of the image. Learn more in the
+     * [Vision guide](https://platform.openai.com/docs/guides/vision#low-or-high-fidelity-image-understanding).
+     */
+    detail?: 'auto' | 'low' | 'high';
+  }
+}
+
+/**
+ * Learn about [audio inputs](https://platform.openai.com/docs/guides/audio).
+ */
+export interface ChatCompletionContentPartInputAudio {
+  input_audio: ChatCompletionContentPartInputAudio.InputAudio;
+
+  /**
+   * The type of the content part. Always `input_audio`.
+   */
+  type: 'input_audio';
+}
+
+export namespace ChatCompletionContentPartInputAudio {
+  export interface InputAudio {
+    /**
+     * Base64 encoded audio data.
+     */
+    data: string;
+
+    /**
+     * The format of the encoded audio data. Currently supports "wav" and "mp3".
+     */
+    format: 'wav' | 'mp3';
+  }
+}
+
+export interface ChatCompletionContentPartRefusal {
+  /**
+   * The refusal message generated by the model.
+   */
+  refusal: string;
+
+  /**
+   * The type of the content part,.
+   */
+  type: 'refusal';
+}
+
+/**
+ * Learn about
+ * [text inputs](https://platform.openai.com/docs/guides/text-generation).
+ */
+export interface ChatCompletionContentPartText {
+  /**
+   * The text content.
+   */
+  text: string;
+
+  /**
+   * The type of the content part.
+   */
+  type: 'text';
+}
+
+export interface ChatCompletionDeleted {
+  /**
+   * The ID of the chat completion that was deleted.
+   */
+  id: string;
+
+  /**
+   * Whether the chat completion was deleted.
+   */
+  deleted: boolean;
+
+  /**
+   * The type of object being deleted.
+   */
+  object: 'chat.completion.deleted';
+}
+
+/**
+ * Developer-provided instructions that the model should follow, regardless of
+ * messages sent by the user. With o1 models and newer, `developer` messages
+ * replace the previous `system` messages.
+ */
+export interface ChatCompletionDeveloperMessageParam {
+  /**
+   * The contents of the developer message.
+   */
+  content: string | Array<ChatCompletionContentPartText>;
+
+  /**
+   * The role of the messages author, in this case `developer`.
+   */
+  role: 'developer';
+
+  /**
+   * An optional name for the participant. Provides the model information to
+   * differentiate between participants of the same role.
+   */
+  name?: string;
+}
+
+/**
+ * Specifying a particular function via `{"name": "my_function"}` forces the model
+ * to call that function.
+ */
+export interface ChatCompletionFunctionCallOption {
+  /**
+   * The name of the function to call.
+   */
+  name: string;
+}
+
+/**
+ * @deprecated
+ */
+export interface ChatCompletionFunctionMessageParam {
+  /**
+   * The contents of the function message.
+   */
+  content: string | null;
+
+  /**
+   * The name of the function to call.
+   */
+  name: string;
+
+  /**
+   * The role of the messages author, in this case `function`.
+   */
+  role: 'function';
+}
+
+/**
+ * A chat completion message generated by the model.
+ */
+export interface ChatCompletionMessage {
+  /**
+   * The contents of the message.
+   */
+  content: string | null;
+
+  /**
+   * The refusal message generated by the model.
+   */
+  refusal: string | null;
+
+  /**
+   * The role of the author of this message.
+   */
+  role: 'assistant';
+
+  /**
+   * If the audio output modality is requested, this object contains data about the
+   * audio response from the model.
+   * [Learn more](https://platform.openai.com/docs/guides/audio).
+   */
+  audio?: ChatCompletionAudio | null;
+
+  /**
+   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+   * function that should be called, as generated by the model.
+   */
+  function_call?: ChatCompletionMessage.FunctionCall | null;
+
+  /**
+   * The tool calls generated by the model, such as function calls.
+   */
+  tool_calls?: Array<ChatCompletionMessageToolCall>;
+}
+
+export namespace ChatCompletionMessage {
+  /**
+   * @deprecated Deprecated and replaced by `tool_calls`. The name and arguments of a
+   * function that should be called, as generated by the model.
+   */
+  export interface FunctionCall {
+    /**
+     * The arguments to call the function with, as generated by the model in JSON
+     * format. Note that the model does not always generate valid JSON, and may
+     * hallucinate parameters not defined by your function schema. Validate the
+     * arguments in your code before calling your function.
+     */
+    arguments: string;
+
+    /**
+     * The name of the function to call.
+     */
+    name: string;
+  }
+}
+
+/**
+ * Developer-provided instructions that the model should follow, regardless of
+ * messages sent by the user. With o1 models and newer, `developer` messages
+ * replace the previous `system` messages.
+ */
+export type ChatCompletionMessageParam =
+  | ChatCompletionDeveloperMessageParam
+  | ChatCompletionSystemMessageParam
+  | ChatCompletionUserMessageParam
+  | ChatCompletionAssistantMessageParam
+  | ChatCompletionToolMessageParam
+  | ChatCompletionFunctionMessageParam;
+
+export interface ChatCompletionMessageToolCall {
+  /**
+   * The ID of the tool call.
+   */
+  id: string;
+
+  /**
+   * The function that the model called.
+   */
+  function: ChatCompletionMessageToolCall.Function;
+
+  /**
+   * The type of the tool. Currently, only `function` is supported.
+   */
+  type: 'function';
+}
+
+export namespace ChatCompletionMessageToolCall {
+  /**
+   * The function that the model called.
+   */
+  export interface Function {
+    /**
+     * The arguments to call the function with, as generated by the model in JSON
+     * format. Note that the model does not always generate valid JSON, and may
+     * hallucinate parameters not defined by your function schema. Validate the
+     * arguments in your code before calling your function.
+     */
+    arguments: string;
+
+    /**
+     * The name of the function to call.
+     */
+    name: string;
+  }
+}
+
+export type ChatCompletionModality = 'text' | 'audio';
+
+/**
+ * Specifies a tool the model should use. Use to force the model to call a specific
+ * function.
+ */
+export interface ChatCompletionNamedToolChoice {
+  function: ChatCompletionNamedToolChoice.Function;
+
+  /**
+   * The type of the tool. Currently, only `function` is supported.
+   */
+  type: 'function';
+}
+
+export namespace ChatCompletionNamedToolChoice {
+  export interface Function {
+    /**
+     * The name of the function to call.
+     */
+    name: string;
+  }
+}
+
+/**
+ * Static predicted output content, such as the content of a text file that is
+ * being regenerated.
+ */
+export interface ChatCompletionPredictionContent {
+  /**
+   * The content that should be matched when generating a model response. If
+   * generated tokens would match this content, the entire model response can be
+   * returned much more quickly.
+   */
+  content: string | Array<ChatCompletionContentPartText>;
+
+  /**
+   * The type of the predicted content you want to provide. This type is currently
+   * always `content`.
+   */
+  type: 'content';
+}
+
+/**
+ * **o1 and o3-mini models only**
+ *
+ * Constrains effort on reasoning for
+ * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+ * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+ * result in faster responses and fewer tokens used on reasoning in a response.
+ */
+export type ChatCompletionReasoningEffort = 'low' | 'medium' | 'high' | null;
+
+/**
+ * The role of the author of a message
+ */
+export type ChatCompletionRole = 'developer' | 'system' | 'user' | 'assistant' | 'tool' | 'function';
+
+/**
+ * A chat completion message generated by the model.
+ */
+export interface ChatCompletionStoreMessage extends ChatCompletionMessage {
+  /**
+   * The identifier of the chat message.
+   */
+  id: string;
+}
+
+/**
+ * Options for streaming response. Only set this when you set `stream: true`.
+ */
+export interface ChatCompletionStreamOptions {
+  /**
+   * If set, an additional chunk will be streamed before the `data: [DONE]` message.
+   * The `usage` field on this chunk shows the token usage statistics for the entire
+   * request, and the `choices` field will always be an empty array. All other chunks
+   * will also include a `usage` field, but with a null value.
+   */
+  include_usage?: boolean;
+}
+
+/**
+ * Developer-provided instructions that the model should follow, regardless of
+ * messages sent by the user. With o1 models and newer, use `developer` messages
+ * for this purpose instead.
+ */
+export interface ChatCompletionSystemMessageParam {
+  /**
+   * The contents of the system message.
+   */
+  content: string | Array<ChatCompletionContentPartText>;
+
+  /**
+   * The role of the messages author, in this case `system`.
+   */
+  role: 'system';
+
+  /**
+   * An optional name for the participant. Provides the model information to
+   * differentiate between participants of the same role.
+   */
+  name?: string;
+}
+
+export interface ChatCompletionTokenLogprob {
+  /**
+   * The token.
+   */
+  token: string;
+
+  /**
+   * A list of integers representing the UTF-8 bytes representation of the token.
+   * Useful in instances where characters are represented by multiple tokens and
+   * their byte representations must be combined to generate the correct text
+   * representation. Can be `null` if there is no bytes representation for the token.
+   */
+  bytes: Array<number> | null;
+
+  /**
+   * The log probability of this token, if it is within the top 20 most likely
+   * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
+   * unlikely.
+   */
+  logprob: number;
+
+  /**
+   * List of the most likely tokens and their log probability, at this token
+   * position. In rare cases, there may be fewer than the number of requested
+   * `top_logprobs` returned.
+   */
+  top_logprobs: Array<ChatCompletionTokenLogprob.TopLogprob>;
+}
+
+export namespace ChatCompletionTokenLogprob {
+  export interface TopLogprob {
+    /**
+     * The token.
+     */
+    token: string;
+
+    /**
+     * A list of integers representing the UTF-8 bytes representation of the token.
+     * Useful in instances where characters are represented by multiple tokens and
+     * their byte representations must be combined to generate the correct text
+     * representation. Can be `null` if there is no bytes representation for the token.
+     */
+    bytes: Array<number> | null;
+
+    /**
+     * The log probability of this token, if it is within the top 20 most likely
+     * tokens. Otherwise, the value `-9999.0` is used to signify that the token is very
+     * unlikely.
+     */
+    logprob: number;
+  }
+}
+
+export interface ChatCompletionTool {
+  function: Shared.FunctionDefinition;
+
+  /**
+   * The type of the tool. Currently, only `function` is supported.
+   */
+  type: 'function';
+}
+
+/**
+ * Controls which (if any) tool is called by the model. `none` means the model will
+ * not call any tool and instead generates a message. `auto` means the model can
+ * pick between generating a message or calling one or more tools. `required` means
+ * the model must call one or more tools. Specifying a particular tool via
+ * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
+ * call that tool.
+ *
+ * `none` is the default when no tools are present. `auto` is the default if tools
+ * are present.
+ */
+export type ChatCompletionToolChoiceOption = 'none' | 'auto' | 'required' | ChatCompletionNamedToolChoice;
+
+export interface ChatCompletionToolMessageParam {
+  /**
+   * The contents of the tool message.
+   */
+  content: string | Array<ChatCompletionContentPartText>;
+
+  /**
+   * The role of the messages author, in this case `tool`.
+   */
+  role: 'tool';
+
+  /**
+   * Tool call that this message is responding to.
+   */
+  tool_call_id: string;
+}
+
+/**
+ * Messages sent by an end user, containing prompts or additional context
+ * information.
+ */
+export interface ChatCompletionUserMessageParam {
+  /**
+   * The contents of the user message.
+   */
+  content: string | Array<ChatCompletionContentPart>;
+
+  /**
+   * The role of the messages author, in this case `user`.
+   */
+  role: 'user';
+
+  /**
+   * An optional name for the participant. Provides the model information to
+   * differentiate between participants of the same role.
+   */
+  name?: string;
+}
+
+/**
+ * @deprecated ChatCompletionMessageParam should be used instead
+ */
+export type CreateChatCompletionRequestMessage = ChatCompletionMessageParam;
+
+export type ChatCompletionCreateParams =
+  | ChatCompletionCreateParamsNonStreaming
+  | ChatCompletionCreateParamsStreaming;
+
+export interface ChatCompletionCreateParamsBase {
+  /**
+   * A list of messages comprising the conversation so far. Depending on the
+   * [model](https://platform.openai.com/docs/models) you use, different message
+   * types (modalities) are supported, like
+   * [text](https://platform.openai.com/docs/guides/text-generation),
+   * [images](https://platform.openai.com/docs/guides/vision), and
+   * [audio](https://platform.openai.com/docs/guides/audio).
+   */
+  messages: Array<ChatCompletionMessageParam>;
+
+  /**
+   * ID of the model to use. See the
+   * [model endpoint compatibility](https://platform.openai.com/docs/models#model-endpoint-compatibility)
+   * table for details on which models work with the Chat API.
+   */
+  model: (string & {}) | ChatAPI.ChatModel;
+
+  /**
+   * Parameters for audio output. Required when audio output is requested with
+   * `modalities: ["audio"]`.
+   * [Learn more](https://platform.openai.com/docs/guides/audio).
+   */
+  audio?: ChatCompletionAudioParam | null;
+
+  /**
+   * Number between -2.0 and 2.0. Positive values penalize new tokens based on their
+   * existing frequency in the text so far, decreasing the model's likelihood to
+   * repeat the same line verbatim.
+   */
+  frequency_penalty?: number | null;
+
+  /**
+   * Deprecated in favor of `tool_choice`.
+   *
+   * Controls which (if any) function is called by the model.
+   *
+   * `none` means the model will not call a function and instead generates a message.
+   *
+   * `auto` means the model can pick between generating a message or calling a
+   * function.
+   *
+   * Specifying a particular function via `{"name": "my_function"}` forces the model
+   * to call that function.
+   *
+   * `none` is the default when no functions are present. `auto` is the default if
+   * functions are present.
+   */
+  function_call?: 'none' | 'auto' | ChatCompletionFunctionCallOption;
+
+  /**
+   * Deprecated in favor of `tools`.
+   *
+   * A list of functions the model may generate JSON inputs for.
+   */
+  functions?: Array<ChatCompletionCreateParams.Function>;
+
+  /**
+   * Modify the likelihood of specified tokens appearing in the completion.
+   *
+   * Accepts a JSON object that maps tokens (specified by their token ID in the
+   * tokenizer) to an associated bias value from -100 to 100. Mathematically, the
+   * bias is added to the logits generated by the model prior to sampling. The exact
+   * effect will vary per model, but values between -1 and 1 should decrease or
+   * increase likelihood of selection; values like -100 or 100 should result in a ban
+   * or exclusive selection of the relevant token.
+   */
+  logit_bias?: Record<string, number> | null;
+
+  /**
+   * Whether to return log probabilities of the output tokens or not. If true,
+   * returns the log probabilities of each output token returned in the `content` of
+   * `message`.
+   */
+  logprobs?: boolean | null;
+
+  /**
+   * An upper bound for the number of tokens that can be generated for a completion,
+   * including visible output tokens and
+   * [reasoning tokens](https://platform.openai.com/docs/guides/reasoning).
+   */
+  max_completion_tokens?: number | null;
+
+  /**
+   * The maximum number of [tokens](/tokenizer) that can be generated in the chat
+   * completion. This value can be used to control
+   * [costs](https://openai.com/api/pricing/) for text generated via API.
+   *
+   * This value is now deprecated in favor of `max_completion_tokens`, and is not
+   * compatible with
+   * [o1 series models](https://platform.openai.com/docs/guides/reasoning).
+   */
+  max_tokens?: number | null;
+
+  /**
+   * Set of 16 key-value pairs that can be attached to an object. This can be useful
+   * for storing additional information about the object in a structured format, and
+   * querying for objects via API or the dashboard.
+   *
+   * Keys are strings with a maximum length of 64 characters. Values are strings with
+   * a maximum length of 512 characters.
+   */
+  metadata?: Shared.Metadata | null;
+
+  /**
+   * Output types that you would like the model to generate for this request. Most
+   * models are capable of generating text, which is the default:
+   *
+   * `["text"]`
+   *
+   * The `gpt-4o-audio-preview` model can also be used to
+   * [generate audio](https://platform.openai.com/docs/guides/audio). To request that
+   * this model generate both text and audio responses, you can use:
+   *
+   * `["text", "audio"]`
+   */
+  modalities?: Array<ChatCompletionModality> | null;
+
+  /**
+   * How many chat completion choices to generate for each input message. Note that
+   * you will be charged based on the number of generated tokens across all of the
+   * choices. Keep `n` as `1` to minimize costs.
+   */
+  n?: number | null;
+
+  /**
+   * Whether to enable
+   * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
+   * during tool use.
+   */
+  parallel_tool_calls?: boolean;
+
+  /**
+   * Static predicted output content, such as the content of a text file that is
+   * being regenerated.
+   */
+  prediction?: ChatCompletionPredictionContent | null;
+
+  /**
+   * Number between -2.0 and 2.0. Positive values penalize new tokens based on
+   * whether they appear in the text so far, increasing the model's likelihood to
+   * talk about new topics.
+   */
+  presence_penalty?: number | null;
+
+  /**
+   * **o1 and o3-mini models only**
+   *
+   * Constrains effort on reasoning for
+   * [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
+   * supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
+   * result in faster responses and fewer tokens used on reasoning in a response.
+   */
+  reasoning_effort?: ChatCompletionReasoningEffort | null;
+
+  /**
+   * An object specifying the format that the model must output.
+   *
+   * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
+   * Outputs which ensures the model will match your supplied JSON schema. Learn more
+   * in the
+   * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
+   *
+   * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
+   * message the model generates is valid JSON.
+   *
+   * **Important:** when using JSON mode, you **must** also instruct the model to
+   * produce JSON yourself via a system or user message. Without this, the model may
+   * generate an unending stream of whitespace until the generation reaches the token
+   * limit, resulting in a long-running and seemingly "stuck" request. Also note that
+   * the message content may be partially cut off if `finish_reason="length"`, which
+   * indicates the generation exceeded `max_tokens` or the conversation exceeded the
+   * max context length.
+   */
+  response_format?:
+    | Shared.ResponseFormatText
+    | Shared.ResponseFormatJSONObject
+    | Shared.ResponseFormatJSONSchema;
+
+  /**
+   * This feature is in Beta. If specified, our system will make a best effort to
+   * sample deterministically, such that repeated requests with the same `seed` and
+   * parameters should return the same result. Determinism is not guaranteed, and you
+   * should refer to the `system_fingerprint` response parameter to monitor changes
+   * in the backend.
+   */
+  seed?: number | null;
+
+  /**
+   * Specifies the latency tier to use for processing the request. This parameter is
+   * relevant for customers subscribed to the scale tier service:
+   *
+   * - If set to 'auto', and the Project is Scale tier enabled, the system will
+   *   utilize scale tier credits until they are exhausted.
+   * - If set to 'auto', and the Project is not Scale tier enabled, the request will
+   *   be processed using the default service tier with a lower uptime SLA and no
+   *   latency guarantee.
+   * - If set to 'default', the request will be processed using the default service
+   *   tier with a lower uptime SLA and no latency guarantee.
+   * - When not set, the default behavior is 'auto'.
+   */
+  service_tier?: 'auto' | 'default' | null;
+
+  /**
+   * Up to 4 sequences where the API will stop generating further tokens.
+   */
+  stop?: string | null | Array<string>;
+
+  /**
+   * Whether or not to store the output of this chat completion request for use in
+   * our [model distillation](https://platform.openai.com/docs/guides/distillation)
+   * or [evals](https://platform.openai.com/docs/guides/evals) products.
+   */
+  store?: boolean | null;
+
+  /**
+   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
+   * sent as data-only
+   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
+   * as they become available, with the stream terminated by a `data: [DONE]`
+   * message.
+   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
+   */
+  stream?: boolean | null;
+
+  /**
+   * Options for streaming response. Only set this when you set `stream: true`.
+   */
+  stream_options?: ChatCompletionStreamOptions | null;
+
+  /**
+   * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
+   * make the output more random, while lower values like 0.2 will make it more
+   * focused and deterministic. We generally recommend altering this or `top_p` but
+   * not both.
+   */
+  temperature?: number | null;
+
+  /**
+   * Controls which (if any) tool is called by the model. `none` means the model will
+   * not call any tool and instead generates a message. `auto` means the model can
+   * pick between generating a message or calling one or more tools. `required` means
+   * the model must call one or more tools. Specifying a particular tool via
+   * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
+   * call that tool.
+   *
+   * `none` is the default when no tools are present. `auto` is the default if tools
+   * are present.
+   */
+  tool_choice?: ChatCompletionToolChoiceOption;
+
+  /**
+   * A list of tools the model may call. Currently, only functions are supported as a
+   * tool. Use this to provide a list of functions the model may generate JSON inputs
+   * for. A max of 128 functions are supported.
+   */
+  tools?: Array<ChatCompletionTool>;
+
+  /**
+   * An integer between 0 and 20 specifying the number of most likely tokens to
+   * return at each token position, each with an associated log probability.
+   * `logprobs` must be set to `true` if this parameter is used.
+   */
+  top_logprobs?: number | null;
+
+  /**
+   * An alternative to sampling with temperature, called nucleus sampling, where the
+   * model considers the results of the tokens with top_p probability mass. So 0.1
+   * means only the tokens comprising the top 10% probability mass are considered.
+   *
+   * We generally recommend altering this or `temperature` but not both.
+   */
+  top_p?: number | null;
+
+  /**
+   * A unique identifier representing your end-user, which can help OpenAI to monitor
+   * and detect abuse.
+   * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
+   */
+  user?: string;
+}
+
+export namespace ChatCompletionCreateParams {
+  /**
+   * @deprecated
+   */
+  export interface Function {
+    /**
+     * The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
+     * underscores and dashes, with a maximum length of 64.
+     */
+    name: string;
+
+    /**
+     * A description of what the function does, used by the model to choose when and
+     * how to call the function.
+     */
+    description?: string;
+
+    /**
+     * The parameters the functions accepts, described as a JSON Schema object. See the
+     * [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
+     * and the
+     * [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
+     * documentation about the format.
+     *
+     * Omitting `parameters` defines a function with an empty parameter list.
+     */
+    parameters?: Shared.FunctionParameters;
+  }
+
+  export type ChatCompletionCreateParamsNonStreaming =
+    CompletionsCompletionsAPI.ChatCompletionCreateParamsNonStreaming;
+  export type ChatCompletionCreateParamsStreaming =
+    CompletionsCompletionsAPI.ChatCompletionCreateParamsStreaming;
+}
+
+/**
+ * @deprecated Use ChatCompletionCreateParams instead
+ */
+export type CompletionCreateParams = ChatCompletionCreateParams;
+
+export interface ChatCompletionCreateParamsNonStreaming extends ChatCompletionCreateParamsBase {
+  /**
+   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
+   * sent as data-only
+   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
+   * as they become available, with the stream terminated by a `data: [DONE]`
+   * message.
+   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
+   */
+  stream?: false | null;
+}
+
+/**
+ * @deprecated Use ChatCompletionCreateParamsNonStreaming instead
+ */
+export type CompletionCreateParamsNonStreaming = ChatCompletionCreateParamsNonStreaming;
+
+export interface ChatCompletionCreateParamsStreaming extends ChatCompletionCreateParamsBase {
+  /**
+   * If set, partial message deltas will be sent, like in ChatGPT. Tokens will be
+   * sent as data-only
+   * [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
+   * as they become available, with the stream terminated by a `data: [DONE]`
+   * message.
+   * [Example Python code](https://cookbook.openai.com/examples/how_to_stream_completions).
+   */
+  stream: true;
+}
+
+/**
+ * @deprecated Use ChatCompletionCreateParamsStreaming instead
+ */
+export type CompletionCreateParamsStreaming = ChatCompletionCreateParamsStreaming;
+
+export interface ChatCompletionUpdateParams {
+  /**
+   * Set of 16 key-value pairs that can be attached to an object. This can be useful
+   * for storing additional information about the object in a structured format, and
+   * querying for objects via API or the dashboard.
+   *
+   * Keys are strings with a maximum length of 64 characters. Values are strings with
+   * a maximum length of 512 characters.
+   */
+  metadata: Shared.Metadata | null;
+}
+
+/**
+ * @deprecated Use ChatCompletionUpdateParams instead
+ */
+export type CompletionUpdateParams = ChatCompletionUpdateParams;
+
+export interface ChatCompletionListParams extends CursorPageParams {
+  /**
+   * A list of metadata keys to filter the chat completions by. Example:
+   *
+   * `metadata[key1]=value1&metadata[key2]=value2`
+   */
+  metadata?: Shared.Metadata | null;
+
+  /**
+   * The model used to generate the chat completions.
+   */
+  model?: string;
+
+  /**
+   * Sort order for chat completions by timestamp. Use `asc` for ascending order or
+   * `desc` for descending order. Defaults to `asc`.
+   */
+  order?: 'asc' | 'desc';
+}
+
+/**
+ * @deprecated Use ChatCompletionListParams instead
+ */
+export type CompletionListParams = ChatCompletionListParams;
+
+Completions.ChatCompletionsPage = ChatCompletionsPage;
+Completions.Messages = Messages;
+
+export declare namespace Completions {
+  export {
+    type ChatCompletion as ChatCompletion,
+    type ChatCompletionAssistantMessageParam as ChatCompletionAssistantMessageParam,
+    type ChatCompletionAudio as ChatCompletionAudio,
+    type ChatCompletionAudioParam as ChatCompletionAudioParam,
+    type ChatCompletionChunk as ChatCompletionChunk,
+    type ChatCompletionContentPart as ChatCompletionContentPart,
+    type ChatCompletionContentPartImage as ChatCompletionContentPartImage,
+    type ChatCompletionContentPartInputAudio as ChatCompletionContentPartInputAudio,
+    type ChatCompletionContentPartRefusal as ChatCompletionContentPartRefusal,
+    type ChatCompletionContentPartText as ChatCompletionContentPartText,
+    type ChatCompletionDeleted as ChatCompletionDeleted,
+    type ChatCompletionDeveloperMessageParam as ChatCompletionDeveloperMessageParam,
+    type ChatCompletionFunctionCallOption as ChatCompletionFunctionCallOption,
+    type ChatCompletionFunctionMessageParam as ChatCompletionFunctionMessageParam,
+    type ChatCompletionMessage as ChatCompletionMessage,
+    type ChatCompletionMessageParam as ChatCompletionMessageParam,
+    type ChatCompletionMessageToolCall as ChatCompletionMessageToolCall,
+    type ChatCompletionModality as ChatCompletionModality,
+    type ChatCompletionNamedToolChoice as ChatCompletionNamedToolChoice,
+    type ChatCompletionPredictionContent as ChatCompletionPredictionContent,
+    type ChatCompletionReasoningEffort as ChatCompletionReasoningEffort,
+    type ChatCompletionRole as ChatCompletionRole,
+    type ChatCompletionStoreMessage as ChatCompletionStoreMessage,
+    type ChatCompletionStreamOptions as ChatCompletionStreamOptions,
+    type ChatCompletionSystemMessageParam as ChatCompletionSystemMessageParam,
+    type ChatCompletionTokenLogprob as ChatCompletionTokenLogprob,
+    type ChatCompletionTool as ChatCompletionTool,
+    type ChatCompletionToolChoiceOption as ChatCompletionToolChoiceOption,
+    type ChatCompletionToolMessageParam as ChatCompletionToolMessageParam,
+    type ChatCompletionUserMessageParam as ChatCompletionUserMessageParam,
+    type CreateChatCompletionRequestMessage as CreateChatCompletionRequestMessage,
+    ChatCompletionsPage as ChatCompletionsPage,
+    type ChatCompletionCreateParams as ChatCompletionCreateParams,
+    type CompletionCreateParams as CompletionCreateParams,
+    type ChatCompletionCreateParamsNonStreaming as ChatCompletionCreateParamsNonStreaming,
+    type CompletionCreateParamsNonStreaming as CompletionCreateParamsNonStreaming,
+    type ChatCompletionCreateParamsStreaming as ChatCompletionCreateParamsStreaming,
+    type CompletionCreateParamsStreaming as CompletionCreateParamsStreaming,
+    type ChatCompletionUpdateParams as ChatCompletionUpdateParams,
+    type CompletionUpdateParams as CompletionUpdateParams,
+    type ChatCompletionListParams as ChatCompletionListParams,
+    type CompletionListParams as CompletionListParams,
+  };
+
+  export { Messages as Messages, type MessageListParams as MessageListParams };
+}
diff --git a/src/resources/chat/completions/index.ts b/src/resources/chat/completions/index.ts
new file mode 100644
index 000000000..3691f41d8
--- /dev/null
+++ src/resources/chat/completions/index.ts
@@ -0,0 +1,49 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+export {
+  ChatCompletionStoreMessagesPage,
+  ChatCompletionsPage,
+  Completions,
+  type ChatCompletion,
+  type ChatCompletionAssistantMessageParam,
+  type ChatCompletionAudio,
+  type ChatCompletionAudioParam,
+  type ChatCompletionChunk,
+  type ChatCompletionContentPart,
+  type ChatCompletionContentPartImage,
+  type ChatCompletionContentPartInputAudio,
+  type ChatCompletionContentPartRefusal,
+  type ChatCompletionContentPartText,
+  type ChatCompletionDeleted,
+  type ChatCompletionDeveloperMessageParam,
+  type ChatCompletionFunctionCallOption,
+  type ChatCompletionFunctionMessageParam,
+  type ChatCompletionMessage,
+  type ChatCompletionMessageParam,
+  type ChatCompletionMessageToolCall,
+  type ChatCompletionModality,
+  type ChatCompletionNamedToolChoice,
+  type ChatCompletionPredictionContent,
+  type ChatCompletionReasoningEffort,
+  type ChatCompletionRole,
+  type ChatCompletionStoreMessage,
+  type ChatCompletionStreamOptions,
+  type ChatCompletionSystemMessageParam,
+  type ChatCompletionTokenLogprob,
+  type ChatCompletionTool,
+  type ChatCompletionToolChoiceOption,
+  type ChatCompletionToolMessageParam,
+  type ChatCompletionUserMessageParam,
+  type CreateChatCompletionRequestMessage,
+  type ChatCompletionCreateParams,
+  type CompletionCreateParams,
+  type ChatCompletionCreateParamsNonStreaming,
+  type CompletionCreateParamsNonStreaming,
+  type ChatCompletionCreateParamsStreaming,
+  type CompletionCreateParamsStreaming,
+  type ChatCompletionUpdateParams,
+  type CompletionUpdateParams,
+  type ChatCompletionListParams,
+  type CompletionListParams,
+} from './completions';
+export { Messages, type MessageListParams } from './messages';
diff --git a/src/resources/chat/completions/messages.ts b/src/resources/chat/completions/messages.ts
new file mode 100644
index 000000000..fc1cc5d94
--- /dev/null
+++ src/resources/chat/completions/messages.ts
@@ -0,0 +1,52 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import { APIResource } from '../../../resource';
+import { isRequestOptions } from '../../../core';
+import * as Core from '../../../core';
+import * as CompletionsAPI from './completions';
+import { ChatCompletionStoreMessagesPage } from './completions';
+import { type CursorPageParams } from '../../../pagination';
+
+export class Messages extends APIResource {
+  /**
+   * Get the messages in a stored chat completion. Only chat completions that have
+   * been created with the `store` parameter set to `true` will be returned.
+   */
+  list(
+    completionId: string,
+    query?: MessageListParams,
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionStoreMessagesPage, CompletionsAPI.ChatCompletionStoreMessage>;
+  list(
+    completionId: string,
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionStoreMessagesPage, CompletionsAPI.ChatCompletionStoreMessage>;
+  list(
+    completionId: string,
+    query: MessageListParams | Core.RequestOptions = {},
+    options?: Core.RequestOptions,
+  ): Core.PagePromise<ChatCompletionStoreMessagesPage, CompletionsAPI.ChatCompletionStoreMessage> {
+    if (isRequestOptions(query)) {
+      return this.list(completionId, {}, query);
+    }
+    return this._client.getAPIList(
+      `/chat/completions/${completionId}/messages`,
+      ChatCompletionStoreMessagesPage,
+      { query, ...options },
+    );
+  }
+}
+
+export interface MessageListParams extends CursorPageParams {
+  /**
+   * Sort order for messages by timestamp. Use `asc` for ascending order or `desc`
+   * for descending order. Defaults to `asc`.
+   */
+  order?: 'asc' | 'desc';
+}
+
+export declare namespace Messages {
+  export { type MessageListParams as MessageListParams };
+}
+
+export { ChatCompletionStoreMessagesPage };
diff --git src/resources/chat/index.ts src/resources/chat/index.ts
index c3be19402..a9b5b46fb 100644
--- src/resources/chat/index.ts
+++ src/resources/chat/index.ts
@@ -2,6 +2,8 @@

export { Chat, type ChatModel } from './chat';
export {
+  ChatCompletionStoreMessagesPage,
+  ChatCompletionsPage,
  Completions,
  type ChatCompletion,
  type ChatCompletionAssistantMessageParam,
@@ -13,6 +15,7 @@ export {
  type ChatCompletionContentPartInputAudio,
  type ChatCompletionContentPartRefusal,
  type ChatCompletionContentPartText,
+  type ChatCompletionDeleted,
  type ChatCompletionDeveloperMessageParam,
  type ChatCompletionFunctionCallOption,
  type ChatCompletionFunctionMessageParam,
@@ -24,6 +27,7 @@ export {
  type ChatCompletionPredictionContent,
  type ChatCompletionReasoningEffort,
  type ChatCompletionRole,
+  type ChatCompletionStoreMessage,
  type ChatCompletionStreamOptions,
  type ChatCompletionSystemMessageParam,
  type ChatCompletionTokenLogprob,
@@ -38,4 +42,8 @@ export {
  type CompletionCreateParamsNonStreaming,
  type ChatCompletionCreateParamsStreaming,
  type CompletionCreateParamsStreaming,
-} from './completions';
+  type ChatCompletionUpdateParams,
+  type CompletionUpdateParams,
+  type ChatCompletionListParams,
+  type CompletionListParams,
+} from './completions/index';
diff --git src/resources/completions.ts src/resources/completions.ts
index be75a46f0..664e39d9d 100644
--- src/resources/completions.ts
+++ src/resources/completions.ts
@@ -4,7 +4,7 @@ import { APIResource } from '../resource';
import { APIPromise } from '../core';
import * as Core from '../core';
import * as CompletionsAPI from './completions';
-import * as ChatCompletionsAPI from './chat/completions';
+import * as CompletionsCompletionsAPI from './chat/completions/completions';
import { Stream } from '../streaming';

export class Completions extends APIResource {
@@ -311,7 +311,7 @@ export interface CompletionCreateParamsBase {
  /**
   * Options for streaming response. Only set this when you set `stream: true`.
   */
-  stream_options?: ChatCompletionsAPI.ChatCompletionStreamOptions | null;
+  stream_options?: CompletionsCompletionsAPI.ChatCompletionStreamOptions | null;

  /**
   * The suffix that comes after a completion of inserted text.
diff --git src/resources/moderations.ts src/resources/moderations.ts
index f7b16166d..86e90376d 100644
--- src/resources/moderations.ts
+++ src/resources/moderations.ts
@@ -75,14 +75,14 @@ export namespace Moderation {
     * execution of wrongdoing, or that gives advice or instruction on how to commit
     * illicit acts. For example, "how to shoplift" would fit this category.
     */
-    illicit: boolean;
+    illicit: boolean | null;

    /**
     * Content that includes instructions or advice that facilitate the planning or
     * execution of wrongdoing that also includes violence, or that gives advice or
     * instruction on the procurement of any weapon.
     */
-    'illicit/violent': boolean;
+    'illicit/violent': boolean | null;

    /**
     * Content that promotes, encourages, or depicts acts of self-harm, such as
diff --git src/streaming.ts src/streaming.ts
index 6a57a50a0..52266154c 100644
--- src/streaming.ts
+++ src/streaming.ts
@@ -1,6 +1,6 @@
import { ReadableStream, type Response } from './_shims/index';
import { OpenAIError } from './error';
-import { LineDecoder } from './internal/decoders/line';
+import { findDoubleNewlineIndex, LineDecoder } from './internal/decoders/line';
import { ReadableStreamToAsyncIterable } from './internal/stream-utils';

import { APIError } from './error';
@@ -259,37 +259,6 @@ async function* iterSSEChunks(iterator: AsyncIterableIterator<Bytes>): AsyncGene
  }
}

-function findDoubleNewlineIndex(buffer: Uint8Array): number {
-  // This function searches the buffer for the end patterns (\r\r, \n\n, \r\n\r\n)
-  // and returns the index right after the first occurrence of any pattern,
-  // or -1 if none of the patterns are found.
-  const newline = 0x0a; // \n
-  const carriage = 0x0d; // \r
-
-  for (let i = 0; i < buffer.length - 2; i++) {
-    if (buffer[i] === newline && buffer[i + 1] === newline) {
-      // \n\n
-      return i + 2;
-    }
-    if (buffer[i] === carriage && buffer[i + 1] === carriage) {
-      // \r\r
-      return i + 2;
-    }
-    if (
-      buffer[i] === carriage &&
-      buffer[i + 1] === newline &&
-      i + 3 < buffer.length &&
-      buffer[i + 2] === carriage &&
-      buffer[i + 3] === newline
-    ) {
-      // \r\n\r\n
-      return i + 4;
-    }
-  }
-
-  return -1;
-}
-
class SSEDecoder {
  private data: string[];
  private event: string | null;
@@ -345,17 +314,6 @@ class SSEDecoder {
  }
}

-/** This is an internal helper function that's just used for testing */
-export function _decodeChunks(chunks: string[]): string[] {
-  const decoder = new LineDecoder();
-  const lines: string[] = [];
-  for (const chunk of chunks) {
-    lines.push(...decoder.decode(chunk));
-  }
-
-  return lines;
-}
-
function partition(str: string, delimiter: string): [string, string, string] {
  const index = str.indexOf(delimiter);
  if (index !== -1) {
diff --git src/version.ts src/version.ts
index 13c764d7d..4fdc11dc7 100644
--- src/version.ts
+++ src/version.ts
@@ -1 +1 @@
-export const VERSION = '4.83.0'; // x-release-please-version
+export const VERSION = '4.85.2'; // x-release-please-version
diff --git tests/api-resources/beta/assistants.test.ts tests/api-resources/beta/assistants.test.ts
index 88a10ba8f..16bc9f942 100644
--- tests/api-resources/beta/assistants.test.ts
+++ tests/api-resources/beta/assistants.test.ts
@@ -27,6 +27,7 @@ describe('resource assistants', () => {
      instructions: 'instructions',
      metadata: { foo: 'string' },
      name: 'name',
+      reasoning_effort: 'low',
      response_format: 'auto',
      temperature: 1,
      tool_resources: {
diff --git tests/api-resources/beta/threads/runs/runs.test.ts tests/api-resources/beta/threads/runs/runs.test.ts
index 9b728403f..13ae89a00 100644
--- tests/api-resources/beta/threads/runs/runs.test.ts
+++ tests/api-resources/beta/threads/runs/runs.test.ts
@@ -39,6 +39,7 @@ describe('resource runs', () => {
      metadata: { foo: 'string' },
      model: 'gpt-4o',
      parallel_tool_calls: true,
+      reasoning_effort: 'low',
      response_format: 'auto',
      stream: false,
      temperature: 1,
diff --git tests/api-resources/chat/completions.test.ts tests/api-resources/chat/completions.test.ts
deleted file mode 100644
index 8f1bc7d4c..000000000
--- tests/api-resources/chat/completions.test.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
-
-import OpenAI from 'openai';
-import { Response } from 'node-fetch';
-
-const client = new OpenAI({
-  apiKey: 'My API Key',
-  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
-});
-
-describe('resource completions', () => {
-  test('create: only required params', async () => {
-    const responsePromise = client.chat.completions.create({
-      messages: [{ content: 'string', role: 'developer' }],
-      model: 'gpt-4o',
-    });
-    const rawResponse = await responsePromise.asResponse();
-    expect(rawResponse).toBeInstanceOf(Response);
-    const response = await responsePromise;
-    expect(response).not.toBeInstanceOf(Response);
-    const dataAndResponse = await responsePromise.withResponse();
-    expect(dataAndResponse.data).toBe(response);
-    expect(dataAndResponse.response).toBe(rawResponse);
-  });
-
-  test('create: required and optional params', async () => {
-    const response = await client.chat.completions.create({
-      messages: [{ content: 'string', role: 'developer', name: 'name' }],
-      model: 'gpt-4o',
-      audio: { format: 'wav', voice: 'alloy' },
-      frequency_penalty: -2,
-      function_call: 'none',
-      functions: [{ name: 'name', description: 'description', parameters: { foo: 'bar' } }],
-      logit_bias: { foo: 0 },
-      logprobs: true,
-      max_completion_tokens: 0,
-      max_tokens: 0,
-      metadata: { foo: 'string' },
-      modalities: ['text'],
-      n: 1,
-      parallel_tool_calls: true,
-      prediction: { content: 'string', type: 'content' },
-      presence_penalty: -2,
-      reasoning_effort: 'low',
-      response_format: { type: 'text' },
-      seed: 0,
-      service_tier: 'auto',
-      stop: 'string',
-      store: true,
-      stream: false,
-      stream_options: { include_usage: true },
-      temperature: 1,
-      tool_choice: 'none',
-      tools: [
-        {
-          function: { name: 'name', description: 'description', parameters: { foo: 'bar' }, strict: true },
-          type: 'function',
-        },
-      ],
-      top_logprobs: 0,
-      top_p: 1,
-      user: 'user-1234',
-    });
-  });
-});
diff --git a/tests/api-resources/chat/completions/completions.test.ts b/tests/api-resources/chat/completions/completions.test.ts
new file mode 100644
index 000000000..acdd631db
--- /dev/null
+++ tests/api-resources/chat/completions/completions.test.ts
@@ -0,0 +1,144 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import OpenAI from 'openai';
+import { Response } from 'node-fetch';
+
+const client = new OpenAI({
+  apiKey: 'My API Key',
+  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
+});
+
+describe('resource completions', () => {
+  test('create: only required params', async () => {
+    const responsePromise = client.chat.completions.create({
+      messages: [{ content: 'string', role: 'developer' }],
+      model: 'gpt-4o',
+    });
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('create: required and optional params', async () => {
+    const response = await client.chat.completions.create({
+      messages: [{ content: 'string', role: 'developer', name: 'name' }],
+      model: 'gpt-4o',
+      audio: { format: 'wav', voice: 'alloy' },
+      frequency_penalty: -2,
+      function_call: 'none',
+      functions: [{ name: 'name', description: 'description', parameters: { foo: 'bar' } }],
+      logit_bias: { foo: 0 },
+      logprobs: true,
+      max_completion_tokens: 0,
+      max_tokens: 0,
+      metadata: { foo: 'string' },
+      modalities: ['text'],
+      n: 1,
+      parallel_tool_calls: true,
+      prediction: { content: 'string', type: 'content' },
+      presence_penalty: -2,
+      reasoning_effort: 'low',
+      response_format: { type: 'text' },
+      seed: 0,
+      service_tier: 'auto',
+      stop: 'string',
+      store: true,
+      stream: false,
+      stream_options: { include_usage: true },
+      temperature: 1,
+      tool_choice: 'none',
+      tools: [
+        {
+          function: { name: 'name', description: 'description', parameters: { foo: 'bar' }, strict: true },
+          type: 'function',
+        },
+      ],
+      top_logprobs: 0,
+      top_p: 1,
+      user: 'user-1234',
+    });
+  });
+
+  test('retrieve', async () => {
+    const responsePromise = client.chat.completions.retrieve('completion_id');
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('retrieve: request options instead of params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.retrieve('completion_id', { path: '/_stainless_unknown_path' }),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+
+  test('update: only required params', async () => {
+    const responsePromise = client.chat.completions.update('completion_id', { metadata: { foo: 'string' } });
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('update: required and optional params', async () => {
+    const response = await client.chat.completions.update('completion_id', { metadata: { foo: 'string' } });
+  });
+
+  test('list', async () => {
+    const responsePromise = client.chat.completions.list();
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('list: request options instead of params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(client.chat.completions.list({ path: '/_stainless_unknown_path' })).rejects.toThrow(
+      OpenAI.NotFoundError,
+    );
+  });
+
+  test('list: request options and params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.list(
+        { after: 'after', limit: 0, metadata: { foo: 'string' }, model: 'model', order: 'asc' },
+        { path: '/_stainless_unknown_path' },
+      ),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+
+  test('del', async () => {
+    const responsePromise = client.chat.completions.del('completion_id');
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('del: request options instead of params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.del('completion_id', { path: '/_stainless_unknown_path' }),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+});
diff --git a/tests/api-resources/chat/completions/messages.test.ts b/tests/api-resources/chat/completions/messages.test.ts
new file mode 100644
index 000000000..664106cb9
--- /dev/null
+++ tests/api-resources/chat/completions/messages.test.ts
@@ -0,0 +1,40 @@
+// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
+
+import OpenAI from 'openai';
+import { Response } from 'node-fetch';
+
+const client = new OpenAI({
+  apiKey: 'My API Key',
+  baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
+});
+
+describe('resource messages', () => {
+  test('list', async () => {
+    const responsePromise = client.chat.completions.messages.list('completion_id');
+    const rawResponse = await responsePromise.asResponse();
+    expect(rawResponse).toBeInstanceOf(Response);
+    const response = await responsePromise;
+    expect(response).not.toBeInstanceOf(Response);
+    const dataAndResponse = await responsePromise.withResponse();
+    expect(dataAndResponse.data).toBe(response);
+    expect(dataAndResponse.response).toBe(rawResponse);
+  });
+
+  test('list: request options instead of params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.messages.list('completion_id', { path: '/_stainless_unknown_path' }),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+
+  test('list: request options and params are passed correctly', async () => {
+    // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
+    await expect(
+      client.chat.completions.messages.list(
+        'completion_id',
+        { after: 'after', limit: 0, order: 'asc' },
+        { path: '/_stainless_unknown_path' },
+      ),
+    ).rejects.toThrow(OpenAI.NotFoundError);
+  });
+});
diff --git a/tests/internal/decoders/line.test.ts b/tests/internal/decoders/line.test.ts
new file mode 100644
index 000000000..e76858e55
--- /dev/null
+++ tests/internal/decoders/line.test.ts
@@ -0,0 +1,128 @@
+import { findDoubleNewlineIndex, LineDecoder } from 'openai/internal/decoders/line';
+
+function decodeChunks(chunks: string[], { flush }: { flush: boolean } = { flush: false }): string[] {
+  const decoder = new LineDecoder();
+  const lines: string[] = [];
+  for (const chunk of chunks) {
+    lines.push(...decoder.decode(chunk));
+  }
+
+  if (flush) {
+    lines.push(...decoder.flush());
+  }
+
+  return lines;
+}
+
+describe('line decoder', () => {
+  test('basic', () => {
+    // baz is not included because the line hasn't ended yet
+    expect(decodeChunks(['foo', ' bar\nbaz'])).toEqual(['foo bar']);
+  });
+
+  test('basic with \\r', () => {
+    expect(decodeChunks(['foo', ' bar\r\nbaz'])).toEqual(['foo bar']);
+    expect(decodeChunks(['foo', ' bar\r\nbaz'], { flush: true })).toEqual(['foo bar', 'baz']);
+  });
+
+  test('trailing new lines', () => {
+    expect(decodeChunks(['foo', ' bar', 'baz\n', 'thing\n'])).toEqual(['foo barbaz', 'thing']);
+  });
+
+  test('trailing new lines with \\r', () => {
+    expect(decodeChunks(['foo', ' bar', 'baz\r\n', 'thing\r\n'])).toEqual(['foo barbaz', 'thing']);
+  });
+
+  test('escaped new lines', () => {
+    expect(decodeChunks(['foo', ' bar\\nbaz\n'])).toEqual(['foo bar\\nbaz']);
+  });
+
+  test('escaped new lines with \\r', () => {
+    expect(decodeChunks(['foo', ' bar\\r\\nbaz\n'])).toEqual(['foo bar\\r\\nbaz']);
+  });
+
+  test('\\r & \\n split across multiple chunks', () => {
+    expect(decodeChunks(['foo\r', '\n', 'bar'], { flush: true })).toEqual(['foo', 'bar']);
+  });
+
+  test('single \\r', () => {
+    expect(decodeChunks(['foo\r', 'bar'], { flush: true })).toEqual(['foo', 'bar']);
+  });
+
+  test('double \\r', () => {
+    expect(decodeChunks(['foo\r', 'bar\r'], { flush: true })).toEqual(['foo', 'bar']);
+    expect(decodeChunks(['foo\r', '\r', 'bar'], { flush: true })).toEqual(['foo', '', 'bar']);
+    // implementation detail that we don't yield the single \r line until a new \r or \n is encountered
+    expect(decodeChunks(['foo\r', '\r', 'bar'], { flush: false })).toEqual(['foo']);
+  });
+
+  test('double \\r then \\r\\n', () => {
+    expect(decodeChunks(['foo\r', '\r', '\r', '\n', 'bar', '\n'])).toEqual(['foo', '', '', 'bar']);
+    expect(decodeChunks(['foo\n', '\n', '\n', 'bar', '\n'])).toEqual(['foo', '', '', 'bar']);
+  });
+
+  test('double newline', () => {
+    expect(decodeChunks(['foo\n\nbar'], { flush: true })).toEqual(['foo', '', 'bar']);
+    expect(decodeChunks(['foo', '\n', '\nbar'], { flush: true })).toEqual(['foo', '', 'bar']);
+    expect(decodeChunks(['foo\n', '\n', 'bar'], { flush: true })).toEqual(['foo', '', 'bar']);
+    expect(decodeChunks(['foo', '\n', '\n', 'bar'], { flush: true })).toEqual(['foo', '', 'bar']);
+  });
+
+  test('multi-byte characters across chunks', () => {
+    const decoder = new LineDecoder();
+
+    // bytes taken from the string 'известни' and arbitrarily split
+    // so that some multi-byte characters span multiple chunks
+    expect(decoder.decode(new Uint8Array([0xd0]))).toHaveLength(0);
+    expect(decoder.decode(new Uint8Array([0xb8, 0xd0, 0xb7, 0xd0]))).toHaveLength(0);
+    expect(
+      decoder.decode(new Uint8Array([0xb2, 0xd0, 0xb5, 0xd1, 0x81, 0xd1, 0x82, 0xd0, 0xbd, 0xd0, 0xb8])),
+    ).toHaveLength(0);
+
+    const decoded = decoder.decode(new Uint8Array([0xa]));
+    expect(decoded).toEqual(['известни']);
+  });
+
+  test('flushing trailing newlines', () => {
+    expect(decodeChunks(['foo\n', '\nbar'], { flush: true })).toEqual(['foo', '', 'bar']);
+  });
+
+  test('flushing empty buffer', () => {
+    expect(decodeChunks([], { flush: true })).toEqual([]);
+  });
+});
+
+describe('findDoubleNewlineIndex', () => {
+  test('finds \\n\\n', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\n\nbar'))).toBe(5);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\n\nbar'))).toBe(2);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\n\n'))).toBe(5);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\n\n'))).toBe(2);
+  });
+
+  test('finds \\r\\r', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\rbar'))).toBe(5);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\r\rbar'))).toBe(2);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\r'))).toBe(5);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\r\r'))).toBe(2);
+  });
+
+  test('finds \\r\\n\\r\\n', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\n\r\nbar'))).toBe(7);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\r\n\r\nbar'))).toBe(4);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\n\r\n'))).toBe(7);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('\r\n\r\n'))).toBe(4);
+  });
+
+  test('returns -1 when no double newline found', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\nbar'))).toBe(-1);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\rbar'))).toBe(-1);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\nbar'))).toBe(-1);
+    expect(findDoubleNewlineIndex(new TextEncoder().encode(''))).toBe(-1);
+  });
+
+  test('handles incomplete patterns', () => {
+    expect(findDoubleNewlineIndex(new TextEncoder().encode('foo\r\n\r'))).toBe(-1);
+    expect(findDoubleNew,lineIndex(new TextEncoder().encode('foo\r\n'))).toBe(-1);
+  });
+});
diff --git tests/streaming.test.ts tests/streaming.test.ts
index 6fe9a5781..b9a38f208 100644
--- tests/streaming.test.ts
+++ tests/streaming.test.ts
@@ -1,35 +1,7 @@
import { Response } from 'node-fetch';
import { PassThrough } from 'stream';
import assert from 'assert';
-import { _iterSSEMessages, _decodeChunks as decodeChunks } from 'openai/streaming';
-
-describe('line decoder', () => {
-  test('basic', () => {
-    // baz is not included because the line hasn't ended yet
-    expect(decodeChunks(['foo', ' bar\nbaz'])).toEqual(['foo bar']);
-  });
-
-  test('basic with \\r', () => {
-    // baz is not included because the line hasn't ended yet
-    expect(decodeChunks(['foo', ' bar\r\nbaz'])).toEqual(['foo bar']);
-  });
-
-  test('trailing new lines', () => {
-    expect(decodeChunks(['foo', ' bar', 'baz\n', 'thing\n'])).toEqual(['foo barbaz', 'thing']);
-  });
-
-  test('trailing new lines with \\r', () => {
-    expect(decodeChunks(['foo', ' bar', 'baz\r\n', 'thing\r\n'])).toEqual(['foo barbaz', 'thing']);
-  });
-
-  test('escaped new lines', () => {
-    expect(decodeChunks(['foo', ' bar\\nbaz\n'])).toEqual(['foo bar\\nbaz']);
-  });
-
-  test('escaped new lines with \\r', () => {
-    expect(decodeChunks(['foo', ' bar\\r\\nbaz\n'])).toEqual(['foo bar\\r\\nbaz']);
-  });
-});
+import { _iterSSEMessages } from 'openai/streaming';

describe('streaming decoding', () => {
  test('basic', async () => {


Description

This PR introduces several updates and enhancements to the repository, focusing on ecosystem testing, documentation changes, the addition of new features, and bug fixes. The main motivation behind these changes is to improve the overall functionality, reliability, and user experience of the OpenAI SDK.

Possible Issues

  1. Backward Compatibility: The significant refactoring in the completions modules might affect backward compatibility. Users who directly import specific paths may face breaking changes due to the new file structure.
  2. Documentation Integration: While documentation updates are included, ensuring they are consistent and cover all new features comprehensively is essential.

Security Hotspots

  1. GitHub Actions Secrets: The usage of ${{ secrets.OPENAI_API_KEY }} in the new GitHub Actions workflow needs to be closely monitored to ensure they are handled securely and not exposed in logs or error messages.
  2. Ecosystem Tests Execution: Running ecosystem-tests/cli.ts with the --live flag means that live requests may be made to the OpenAI API. This requires the API keys to be securely managed to prevent unauthorized access.
Changes

Changes

.github/workflows/ci.yml

  • Added a new job, ecosystem_tests, in the CI workflow to run ecosystem tests with Node 20.
  • Includes steps to set up Node, install dependencies, and run ecosystem tests using specific tools like Deno and Bun.

.gitignore

  • Added .dev.vars to the gitignore to ignore development environment variables files.

.release-please-manifest.json

  • Updated the version from 4.83.0 to 4.85.2.

.stats.yml

  • Updated the configured endpoints from 69 to 74.
  • Changed the OpenAPI spec URL to a new version.

CHANGELOG.md

  • Added new entries for versions 4.85.0, 4.85.1, and 4.85.2.
  • Documented bug fixes and new features in each release.

README.md

  • Enhanced documentation by converting sample code blocks from JavaScript to TypeScript.
  • Reorganized sections for better clarity and consistency.
  • Removed deprecated Real-time API usage examples and replaced them with updated methods.

api.md

  • Updated file paths for the ChatCompletion related types and methods to the new directory structure.

azure.md

  • Added a new documentation file for using Microsoft Azure with OpenAI, detailing setup and configuration steps.

helpers.md

  • Enhanced documentation for streaming and bulk upload helpers.
  • Added new example code for automated function calls with detailed explanations.

jsr.json

  • Updated package version to 4.85.2.

package.json

  • Updated package version to 4.85.2.
  • Removed the segfault-handler dependency.
  • Adjusted the exports field to improve module resolution.

realtime.md

  • Added detailed documentation for the Realtime API beta, including setup instructions and example code.

src/beta/realtime/websocket.ts

  • Made adjustments to the WebSocket initialization to enhance compatibility and stability.

src/beta/realtime/ws.ts

  • Adjusted the Azure integration setup to use a specific subset of the AzureOpenAI properties.

src/pagination.ts

  • Updated CursorPage to handle has_more for pagination.

src/resources/beta/assistants.ts

  • Added support for the reasoning_effort property in AssistantCreateParams and AssistantUpdateParams.

src/resources/beta/threads/runs/runs.ts

  • Added support for the reasoning_effort property in RunCreateParamsBase.

src/resources/chat/chat.ts

  • Updated to import from the new file structure for completions.

src/resources/chat/completions/completions.ts

  • Introduced a new complete module containing components previously placed directly under chat/completions.

src/resources/chat/completions/messages.ts

  • Added new functionality for managing messages within stored chat completions.

src/resources/moderations.ts

  • Adjusted properties in moderations for new moderation categories.

src/streaming.ts

  • Refactored to use the newly optimized LineDecoder and included utility methods for streaming.

src/version.ts

  • Updated the version to 4.85.2.

tests/api-resources/beta/assistants.test.ts

  • Added tests ensuring that reasoning_effort properties are correctly handled.

tests/api-resources/beta/threads/runs/runs.test.ts

  • Added tests ensuring that reasoning_effort properties are correctly handled.

tests/api-resources/chat/completions/completions.test.ts

  • Split tests into a new nested folder structure reflecting the new module organization.

tests/api-resources/chat/completions/messages.test.ts

  • Added tests for the newly implemented messages endpoint.

tests/internal/decoders/line.test.ts

  • Added comprehensive tests for the new LineDecoder functionality and edge cases.
sequenceDiagram
  participant Developer
  participant CI/CD System
  participant GitHub Actions
  participant OpenAI API
  Developer->>CI/CD System: Push code changes (PR)
  CI/CD System->>GitHub Actions: Trigger workflow
  GitHub Actions-->>CI/CD System: Checkout code
  GitHub Actions-->>CI/CD System: Set up Node, Deno, Bun
  GitHub Actions-->>GitHub Actions: Run tests
  GitHub Actions->>OpenAI API: Execute ecosystem tests
  OpenAI API-->>GitHub Actions: Respond with results
  GitHub Actions-->>CI/CD System: Report test results
  CI/CD System-->>Developer: CI results for PR feedback
Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants